- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
1 line
26 KiB
JavaScript
1 line
26 KiB
JavaScript
"use strict";var _constant=require("../../utils/constant"),_utils=require("../../utils/utils"),_coupon=require("../../utils/coupon"),_times=require("../../utils/times"),_featureProcess=require("../../utils/feature-process"),_theme=require("../../utils/theme");function _typeof(t){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},_typeof(t)}function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_unsupportedIterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArray(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t))return _arrayLikeToArray(t)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return t};var t={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",u=r.asyncIterator||"@@asyncIterator",a=r.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var i=e&&e.prototype instanceof d?e:d,u=Object.create(i.prototype),a=new k(r||[]);return o(u,"_invoke",{value:I(t,n,a)}),u}function p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var l={};function d(){}function f(){}function h(){}var v={};s(v,i,function(){return this});var y=Object.getPrototypeOf,m=y&&y(y(w([])));m&&m!==e&&n.call(m,i)&&(v=m);var _=h.prototype=d.prototype=Object.create(v);function b(t){["next","throw","return"].forEach(function(e){s(t,e,function(t){return this._invoke(e,t)})})}function g(t,e){function r(o,i,u,a){var s=p(t[o],t,i);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==_typeof(l)&&n.call(l,"__await")?e.resolve(l.__await).then(function(t){r("next",t,u,a)},function(t){r("throw",t,u,a)}):e.resolve(l).then(function(t){c.value=t,u(c)},function(t){return r("throw",t,u,a)})}a(s.arg)}var i;o(this,"_invoke",{value:function(t,n){function o(){return new e(function(e,o){r(t,n,e,o)})}return i=i?i.then(o,o):o()}})}function I(t,e,n){var o="suspendedStart";return function(r,i){if("executing"===o)throw new Error("Generator is already running");if("completed"===o){if("throw"===r)throw i;return{value:void 0,done:!0}}for(n.method=r,n.arg=i;;){var u=n.delegate;if(u){var a=C(u,n);if(a){if(a===l)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===o)throw o="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o="executing";var s=p(t,e,n);if("normal"===s.type){if(o=n.done?"completed":"suspendedYield",s.arg===l)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o="completed",n.method="throw",n.arg=s.arg)}}}function C(t,e){var n=e.method,o=t.iterator[n];if(void 0===o)return e.delegate=null,"throw"===n&&t.iterator.return&&(e.method="return",e.arg=void 0,C(t,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),l;var r=p(o,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,l;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}function T(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(T,this),this.reset(!0)}function w(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,r=function e(){for(;++o<t.length;)if(n.call(t,o))return e.value=t[o],e.done=!1,e;return e.value=void 0,e.done=!0,e};return r.next=r}}return{next:x}}function x(){return{value:void 0,done:!0}}return f.prototype=h,o(_,"constructor",{value:h,configurable:!0}),o(h,"constructor",{value:f,configurable:!0}),f.displayName=s(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,s(t,a,"GeneratorFunction")),t.prototype=Object.create(_),t},t.awrap=function(t){return{__await:t}},b(g.prototype),s(g.prototype,u,function(){return this}),t.AsyncIterator=g,t.async=function(e,n,o,r,i){void 0===i&&(i=Promise);var u=new g(c(e,n,o,r),i);return t.isGeneratorFunction(n)?u:u.next().then(function(t){return t.done?t.value:u.next()})},b(_),s(_,a,"Generator"),s(_,i,function(){return this}),s(_,"toString",function(){return"[object Generator]"}),t.keys=function(t){var e=Object(t),n=[];for(var o in e)n.push(o);return n.reverse(),function t(){for(;n.length;){var o=n.pop();if(o in e)return t.value=o,t.done=!1,t}return t.done=!0,t}},t.values=w,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(S),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function o(n,o){return u.type="throw",u.arg=t,e.next=n,o&&(e.method="next",e.arg=void 0),!!o}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],u=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var a=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var o=this.tryEntries.length-1;o>=0;--o){var r=this.tryEntries[o];if(r.tryLoc<=this.prev&&n.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var u=i?i.completion:{};return u.type=t,u.arg=e,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(u)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),S(n),l}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var o=n.completion;if("throw"===o.type){var r=o.arg;S(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:w(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},t}function asyncGeneratorStep(t,e,n,o,r,i,u){try{var a=t[i](u),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(o,r)}function _asyncToGenerator(t){return function(){var e=this,n=arguments;return new Promise(function(o,r){var i=t.apply(e,n);function u(t){asyncGeneratorStep(i,o,r,u,a,"next",t)}function a(t){asyncGeneratorStep(i,o,r,u,a,"throw",t)}u(void 0)})}}function _createForOfIteratorHelper(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=_unsupportedIterableToArray(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0,r=function(){};return{s:r,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,u=!0,a=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return u=t.done,t},e:function(t){a=!0,i=t},f:function(){try{u||null==n.return||n.return()}finally{if(a)throw i}}}}function _unsupportedIterableToArray(t,e){if(t){if("string"==typeof t)return _arrayLikeToArray(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?_arrayLikeToArray(t,e):void 0}}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n<e;n++)o[n]=t[n];return o}function ownKeys(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,o)}return n}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(n),!0).forEach(function(e){_defineProperty(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function _defineProperty(t,e,n){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,e||"default");if("object"!==_typeof(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var DefaultCouponUrl="https://p1-live.byteimg.com/tos-cn-i-gjr78lqtd0/0caf7ed62bdc4291913e176da6d01553~tplv-gjr78lqtd0-z75.image",formatTime=function(t){if(!t)return"";var e=new Date(1e3*t),n=e.getFullYear(),o="".concat(e.getMonth()+1).padStart(2,"0"),r="".concat(e.getDate()).padStart(2,"0"),i="".concat(e.getHours()).padStart(2,"0"),u="".concat(e.getMinutes()).padStart(2,"0");return"".concat(n,"-").concat(o,"-").concat(r," ").concat(i,":").concat(u)};Component({properties:{sdkInstance:{type:Object,value:null}},data:{visible:!1,title:"卡券",desc:"",btnText:"立即领取",btnDisabled:!1,countText:"",timeText:"",tipText:"卡券解释权和提供方归主办方所有",imageUrl:"",currentCoupon:null,useDarkTheme:!1,countdownArr:[],showCutOff:!1,cutOffText:""},lifetimes:{attached:function(){this.shownCouponIds||(this.shownCouponIds=[])},detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this._clearTimer()}},observers:{sdkInstance:function(t){if(t){this.sdkInstance=t,this.store=t.store,this.shownCouponIds=this.store.get("coupon.shownIds")||[];var e=this;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({CouponInfo:function(t){var n=t||{},o=n.visible,r=n.currentId;(0,_utils.setDataIfChanged)(e,{visible:!!o}),o&&r&&e.openCoupon(r)},liveInfo:function(t){(0,_utils.setDataIfChanged)(e,{useDarkTheme:(0,_theme.isUseDarkTheme)(null==t?void 0:t.Basic)})},imageTextInfo:function(){var t=e.store.get("CouponInfo")||{},n=t.visible,o=t.currentId;n&&o?e.openCoupon(o):e._continuePop()},"coupon.watchTime":function(){return e._updateStatus()},"coupon.liveStatus":function(){return e._updateStatus()},userInfo:function(){return e._updateStatus()}})}}},methods:{_reportCouponTea:function(t){var e,n,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};null===(e=this.sdkInstance)||void 0===e||null===(n=e.reportTea)||void 0===n||n.call(e,t,_objectSpread(_objectSpread({},o),{},{terminal:"miniprogram",evModule:"coupon"}))},_hasAnyCoupons:function(){var t,e=_createForOfIteratorHelper(this.store.get("imageTextInfo.imageText")||[]);try{for(e.s();!(t=e.n()).done;){var n=t.value;if(n&&!n.IsDelete){var o,r=_createForOfIteratorHelper(n.Context||[]);try{for(r.s();!(o=r.n()).done;){var i=o.value;if((null==i?void 0:i.ImageTextType)===_constant.ImageTextTypes.COUPON)return!0}}catch(t){r.e(t)}finally{r.f()}}}}catch(t){e.e(t)}finally{e.f()}return!1},_getCouponList:function(){var t=this,e=this.store.get("imageTextInfo.imageText")||[],n=[],o=this.store.get("userInfo")||{},r=o.levelId,i=o.userId,u=(this.store.get("liveInfo")||{}).ActivityId,a=this.store.get("coupon.liveStatus"),s=this.store.get("coupon.watchTime");return e.forEach(function(e){e&&!e.IsDelete&&(e.Context||[]).forEach(function(e){var o;if((null==e?void 0:e.ImageTextType)===_constant.ImageTextTypes.COUPON){var c=null==e?void 0:e.CouponContext;if(c){var p=c.Coupon||c,l=i&&u&&(0,_coupon.isCouponPicked)(u,i,p.Id||c.Id)?1:0,d=null!==(o=c.couponStatus)&&void 0!==o?o:(0,_coupon.calcCouponStatus)(p,l);l&&(d=_coupon.CouponStatusType.Pickup);var f=(0,_utils.getBySplit)(p.Name||"卡券"),h=(0,_utils.getBySplit)(p.Description||""),v=p.Pic||DefaultCouponUrl,y="";if(void 0!==p.Count&&void 0!==p.PickupCount&&-1!==p.Count){var m=Math.max(0,Number(p.Count)-Number(p.PickupCount));y="剩余 ".concat(m,"/").concat(p.Count)}var _=p.EndTime?"有效期至 ".concat(formatTime(p.EndTime)):"",b=t._getBtnState(d),g=(0,_coupon.isCouponLevelEligible)(null!=r?r:"",c),I=(0,_coupon.isCouponWatchEligible)(c,{liveStatus:a,watchTime:s,activityId:u});g&&n.push(_objectSpread(_objectSpread({},c),{},{_display:{title:f,desc:h,imageUrl:v,countText:y,timeText:_,btnText:b.btnText,btnDisabled:b.btnDisabled,couponStatus:d,levelEligible:g,watchEligible:I}}))}}})}),n.sort(function(t,e){return e.SendTime-t.SendTime})},openListDrawer:function(){var t,e;if(!(0,_featureProcess.lockFeatureProcess)(this.sdkInstance,_featureProcess.LockFeatureMap.Coupon)){var n=this._getCouponList();this.setData({couponList:n});var o=this.selectComponent("#coupon-list-drawer");o&&o.showFrame(),this.sdkInstance&&null!==(t=this.sdkInstance.EVENTS)&&void 0!==t&&null!==(e=t.coupon)&&void 0!==e&&e.getList&&this.sdkInstance.emit(this.sdkInstance.EVENTS.coupon.getList,{})}},closeListDrawer:function(){var t=this.selectComponent("#coupon-list-drawer");t&&t.hideFrame()},onCouponItemClick:function(t){if(!(0,_featureProcess.lockFeatureProcess)(this.sdkInstance,_featureProcess.LockFeatureMap.Coupon)){var e=t.currentTarget.dataset.id;this.sdkInstance.setShowCouponId(e,"click")}},onPickupFromList:function(t){var e=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var o,r,i,u,a;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(!(0,_featureProcess.lockFeatureProcess)(e.sdkInstance,_featureProcess.LockFeatureMap.Coupon)){n.next=2;break}return n.abrupt("return");case 2:if(o=t.currentTarget.dataset.id,r=e.data.couponList.find(function(t){return t.Id==o||t.Coupon&&t.Coupon.Id==o})){n.next=6;break}return n.abrupt("return");case 6:if(i=r._display||{},u=i.couponStatus,a=i.watchEligible,u!==_coupon.CouponStatusType.End&&u!==_coupon.CouponStatusType.SendCompleted&&a){n.next=10;break}return e.sdkInstance.setShowCouponId(o,"click"),n.abrupt("return");case 10:return n.next=12,e._doPickup(r);case 12:e.setData({couponList:e._getCouponList()});case 13:case"end":return n.stop()}},n)}))()},_doPickup:function(t){var e=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var o,r,i,u,a,s,c,p,l,d,f;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(i=t.Coupon||t,u=e.store.get("liveInfo")||{},a=u.ActivityId,s=e.store.get("userInfo")||{},c=s.userId,p=s.levelId,a&&c){n.next=6;break}return n.abrupt("return");case 6:if(e._reportCouponTea("pick_up_coupon",{couponId:i.Id,isLogin:!0}),e.isLogin(!0)){n.next=9;break}return n.abrupt("return");case 9:if((0,_coupon.isCouponLevelEligible)(null!=p?p:"",t,function(t,n){return e._reportCouponTea(t,n)})){n.next=13;break}return wx.showToast({title:"当前等级不可领取",icon:"none"}),n.abrupt("return");case 13:if(l=e.store.get("coupon.liveStatus"),d=e.store.get("coupon.watchTime"),(0,_coupon.isCouponWatchEligible)(t,{liveStatus:l,watchTime:d,activityId:a},function(t,n){return e._reportCouponTea(t,n)})){n.next=19;break}return e.closeCouponDrawer(),n.abrupt("return");case 19:return n.next=21,e.sdkInstance.request(_constant.REQUEST_URL_MAP.COUPON_PICKUP,{method:"POST",data:{ActivityID:a,Id:i.Id}});case 21:f=n.sent,e._reportCouponTea("pick_up_coupon_status",{couponId:i.Id,status:null==f?void 0:f.Status,res:f}),e.sdkInstance&&null!==(o=e.sdkInstance.EVENTS)&&void 0!==o&&null!==(r=o.coupon)&&void 0!==r&&r.pickUpStatus&&e.sdkInstance.emit(e.sdkInstance.EVENTS.coupon.pickUpStatus,{couponId:i.Id,status:null==f?void 0:f.Status,res:f});case 24:case"end":return n.stop()}},n)}))()},_getValidCoupons:function(){var t=this.store.get("imageTextInfo.imageText")||[],e=[],n=this.store.get("userInfo")||{},o=n.levelId,r=n.userId,i=(this.store.get("liveInfo")||{}).ActivityId;return t.forEach(function(t){t&&!t.IsDelete&&(t.Context||[]).forEach(function(t){if((null==t?void 0:t.ImageTextType)===_constant.ImageTextTypes.COUPON){var n=null==t?void 0:t.CouponContext;if(n&&void 0!==n.couponStatus){var u=n.Coupon||n,a=!(r&&i&&(0,_coupon.isCouponPicked)(i,r,u.Id||n.Id))?n.couponStatus:_coupon.CouponStatusType.Pickup,s=(0,_coupon.isCouponLevelEligible)(null!=o?o:"",n);a===_coupon.CouponStatusType.Sending&&s&&e.push(n)}}})}),e.sort(function(t,e){return e.SendTime-t.SendTime})},_continuePop:function(){var t=this;if(!this.data.visible){var e=this._getValidCoupons().find(function(e){return!t.shownCouponIds.includes(String(e.Id))});e&&(this.sdkInstance.setShowCouponId(e.Id,"auto"),this._reportCouponTea("show_coupon_by_auto",{couponId:e.Id,coupon:e,showList:_toConsumableArray(this.shownCouponIds)}))}},_updateStatus:function(){if(this.data.visible&&this.data.currentCoupon){var t=this.data.currentCoupon,e=(this.store.get("liveInfo")||{}).ActivityId,n=(this.store.get("userInfo")||{}).levelId,o=this.store.get("coupon.liveStatus"),r=this.store.get("coupon.watchTime"),i=(0,_coupon.isCouponLevelEligible)(null!=n?n:"",t),u=(0,_coupon.isCouponWatchEligible)(t,{liveStatus:o,watchTime:r,activityId:e}),a={};i!==this.data.isLevelEligible&&(a.isLevelEligible=i),u!==this.data.canPickUp&&(a.canPickUp=u);var s=t.couponStatus;if(s===_coupon.CouponStatusType.Sending){var c=this._getBtnState(s);u||(c.btnText="去观看",c.btnDisabled=!1),c.btnText===this.data.btnText&&c.btnDisabled===this.data.btnDisabled||(a.btnText=c.btnText,a.btnDisabled=c.btnDisabled)}Object.keys(a).length>0&&this.setData(a)}},_findCouponById:function(t){var e,n=_createForOfIteratorHelper(this.store.get("imageTextInfo.imageText")||[]);try{for(n.s();!(e=n.n()).done;){var o=e.value;if(o&&!o.IsDelete){var r,i=_createForOfIteratorHelper(o.Context||[]);try{for(i.s();!(r=i.n()).done;){var u,a=r.value;if(12===(null==a?void 0:a.ImageTextType)){var s=null==a?void 0:a.CouponContext,c=(null==s?void 0:s.Id)||(null==s||null===(u=s.Coupon)||void 0===u?void 0:u.Id);if(String(c)===String(t))return s}}}catch(t){i.e(t)}finally{i.f()}}}}catch(t){n.e(t)}finally{n.f()}return null},_getBtnState:function(t){return t===_coupon.CouponStatusType.Sending?{btnText:"立即领取",btnDisabled:!1}:t===_coupon.CouponStatusType.SendCompleted?{btnText:"已领完",btnDisabled:!0}:t===_coupon.CouponStatusType.Pickup?{btnText:"已领取",btnDisabled:!0}:t===_coupon.CouponStatusType.Received?{btnText:_coupon.CouponReceivedLimitText,btnDisabled:!0}:t===_coupon.CouponStatusType.End?{btnText:"已结束",btnDisabled:!0}:{btnText:"立即领取",btnDisabled:!1}},_clearTimer:function(){this.timer&&(clearInterval(this.timer),this.timer=null)},_startCountdown:function(t){var e=this;this._clearTimer();var n=function(){var n=(0,_times.getCurrentServerTimeSecond)(),o=Math.max(0,Math.floor(t-n)),r=Math.floor(o/3600),i=Math.floor(o%3600/60),u=o%60,a=function(t){return t.toString().padStart(2,"0")};e.setData({countdownArr:[a(r),a(i),a(u)]}),o<=0&&e._clearTimer()};n(),this.timer=setInterval(n,1e3)},openCoupon:function(t){var e,n,o,r=this._findCouponById(t);if(r){var i=_objectSpread(_objectSpread({},r.Coupon||{}),r),u=(this.store.get("liveInfo")||{}).ActivityId,a=(this.store.get("userInfo")||{}).userId,s=a&&u&&(0,_coupon.isCouponPicked)(u,a,i.Id||r.Id)?1:0,c=null!==(e=r.couponStatus)&&void 0!==e?e:(0,_coupon.calcCouponStatus)(i,s);s&&(c=_coupon.CouponStatusType.Pickup);var p=(0,_utils.getBySplit)(i.Name||"卡券"),l=(0,_utils.getBySplit)(i.Description||""),d=i.Pic||DefaultCouponUrl,f=(null!==(n=i.IsWatchLiveLimit)&&void 0!==n?n:_coupon.CouponIsWatchLiveLimit.noLimit)===_coupon.CouponIsWatchLiveLimit.hasLimit,h=null!==(o=i.IsViewerLevelLimit)&&void 0!==o?o:_coupon.CouponIsViewerLevelLimit.noLimit,v=(this.store.get("userInfo")||{}).levelId,y=(0,_coupon.isCouponLevelEligible)(null!=v?v:"",i),m=this.store.get("coupon.liveStatus"),_=this.store.get("coupon.watchTime"),b=(0,_coupon.isCouponWatchEligible)(i,{liveStatus:m,watchTime:_,activityId:u}),g=Boolean(h)||f,I=i.Rule,C=[_coupon.CouponRuleType.Duration,_coupon.CouponRuleType.CutOff].includes(I),T=I===_coupon.CouponRuleType.CutOff,S="";T&&i.EndTime&&(S=formatTime(i.EndTime)),C&&i.EndTime?this._startCountdown(i.EndTime):(this._clearTimer(),this.setData({countdownArr:[]}));var k="";if(void 0!==i.Count&&void 0!==i.PickupCount&&-1!==i.Count){var w=Math.max(0,Number(i.Count)-Number(i.PickupCount));k="剩余 ".concat(w,"/").concat(i.Count)}var x=i.EndTime?"有效期至 ".concat(formatTime(i.EndTime)):"",P=this._getBtnState(c);c!==_coupon.CouponStatusType.Sending||b||(P.btnText="去观看",P.btnDisabled=!1);var E=String(t);this.shownCouponIds&&!this.shownCouponIds.includes(E)&&(this.shownCouponIds.push(E),this.store.set("coupon.shownIds",this.shownCouponIds)),this.setData(_objectSpread(_objectSpread({title:p,desc:l,countText:k,timeText:x,imageUrl:d,currentCoupon:_objectSpread(_objectSpread({},i),{},{couponStatus:c})},P),{},{showText:g,isHasLimit:f,canPickUp:b,IsViewerLevelLimit:h,isLevelEligible:y,isNeedCountDown:C,isNeedCutOff:T,cutOffText:S}))}},closeCouponDrawer:function(){var t;this._reportCouponTea("show_coupon_close",{couponId:null===(t=this.data.currentCoupon)||void 0===t?void 0:t.Id,showList:_toConsumableArray(this.shownCouponIds||[])}),this._clearTimer(),this.myCancel()},myCancel:function(){(this.store.get("CouponInfo")||{}).visible&&this.sdkInstance.setShowCouponId(0,"close")},isLogin:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return 2===(this.store.get("mainInfo")||{}).mode||(t&&this.triggerEvent("commentCheck"),!1)},_handleCouponPickupReceivedLimit:function(t){(0,_coupon.updateCouponContextStatusInStore)(this.store,t.Id,_coupon.CouponStatusType.Received),this.sdkInstance.setCouponPickupStatus(_coupon.CouponStatusType.Received),wx.showToast({title:_coupon.CouponReceivedLimitText,icon:"none"}),this.openCoupon(t.Id)},_handleCouponPickupError:function(t,e){var n,o;this._reportCouponTea("pick_up_coupon_err",{couponId:t.Id,res:e}),this.sdkInstance&&null!==(n=this.sdkInstance.EVENTS)&&void 0!==n&&null!==(o=n.coupon)&&void 0!==o&&o.pickUpError&&this.sdkInstance.emit(this.sdkInstance.EVENTS.coupon.pickUpError,{couponId:t.Id,res:e}),this.sdkInstance.setCouponPickupStatus(0),wx.showToast({title:"活动太火爆了,请稍后重试",icon:"none"})},onPickup:function(){var t=this;return _asyncToGenerator(_regeneratorRuntime().mark(function e(){var n,o,r,i,u,a,s,c,p,l,d,f,h,v,y;return _regeneratorRuntime().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!(0,_featureProcess.lockFeatureProcess)(t.sdkInstance,_featureProcess.LockFeatureMap.Coupon)){e.next=2;break}return e.abrupt("return");case 2:if(u=t.data.currentCoupon){e.next=5;break}return e.abrupt("return");case 5:if(a=t.store.get("liveInfo")||{},s=a.ActivityId,c=t.store.get("userInfo")||{},p=c.userId,l=c.levelId,s&&p){e.next=10;break}return e.abrupt("return");case 10:if(t._reportCouponTea("pick_up_coupon",{couponId:u.Id,isLogin:!0}),t.sdkInstance&&null!==(n=t.sdkInstance.EVENTS)&&void 0!==n&&null!==(o=n.coupon)&&void 0!==o&&o.pickUp&&t.sdkInstance.emit(t.sdkInstance.EVENTS.coupon.pickUp,{couponId:u.Id}),t.isLogin(!0)){e.next=14;break}return e.abrupt("return");case 14:if((0,_coupon.isCouponLevelEligible)(null!=l?l:"",u,function(e,n){return t._reportCouponTea(e,n)})){e.next=18;break}return wx.showToast({title:"当前等级不可领取",icon:"none"}),e.abrupt("return");case 18:if(d=t.store.get("coupon.liveStatus"),f=t.store.get("coupon.watchTime"),(0,_coupon.isCouponWatchEligible)(u,{liveStatus:d,watchTime:f,activityId:s},function(e,n){return t._reportCouponTea(e,n)})){e.next=24;break}return t.closeCouponDrawer(),e.abrupt("return");case 24:return e.next=26,t.sdkInstance.request(_constant.REQUEST_URL_MAP.COUPON_PICKUP,{method:"POST",data:{ActivityID:s,Id:u.Id}});case 26:if(h=e.sent,t._reportCouponTea("pick_up_coupon_status",{couponId:u.Id,status:null==h?void 0:h.Status,res:h}),t.sdkInstance&&null!==(r=t.sdkInstance.EVENTS)&&void 0!==r&&null!==(i=r.coupon)&&void 0!==i&&i.pickUpStatus&&t.sdkInstance.emit(t.sdkInstance.EVENTS.coupon.pickUpStatus,{couponId:u.Id,status:null==h?void 0:h.Status,res:h}),v=null==h?void 0:h.Status,y=_coupon.CouponStatusType.Pickup,![_coupon.CouponPickupStatus.Success,_coupon.CouponPickupStatus.Pickup,_coupon.CouponPickupStatus.SendCompleted].includes(v)){e.next=35;break}v===_coupon.CouponPickupStatus.SendCompleted?y=_coupon.CouponStatusType.SendCompleted:(0,_coupon.markCouponPicked)(s,p,u.Id),e.next=51;break;case 35:if(v!==_coupon.CouponPickupStatus.Ended){e.next=44;break}if(!(null!=h&&h.EndTime&&u.SendTime&&h.EndTime<u.SendTime)){e.next=39;break}return t.sdkInstance.setCouponPickupStatus(0),e.abrupt("return");case 39:return t.sdkInstance.setCouponPickupStatus(_coupon.CouponStatusType.End),wx.showToast({title:"已结束",icon:"none"}),e.abrupt("return");case 44:if(v!==_coupon.CouponPickupStatus.Received){e.next=49;break}return t._handleCouponPickupReceivedLimit(u),e.abrupt("return");case 49:return t._handleCouponPickupError(u,h),e.abrupt("return");case 51:v!==_coupon.CouponPickupStatus.Pickup&&(t.sdkInstance.setCouponPickupStatus(y),wx.showToast({title:y===_coupon.CouponStatusType.SendCompleted?"已领完":"领取成功",icon:"none"})),(0,_coupon.updateCouponContextStatusInStore)(t.store,u.Id,y),v===_coupon.CouponPickupStatus.Success||v===_coupon.CouponPickupStatus.Pickup?t.myCancel():t.openCoupon(u.Id);case 54:case"end":return e.stop()}},e)}))()}}}); |