- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡 - 药品百科: 搜索 + 分类筛选 + 20种药品静态数据 - 惠教中心: 4条药品使用指南课程 - 我的: 家庭成员信息管理 - 自定义TabBar + navigation-bar组件 - SVG药品分类插图
1 line
18 KiB
JavaScript
1 line
18 KiB
JavaScript
"use strict";var _constant=require("../../../utils/constant"),_utils=require("../../../utils/utils"),_theme=require("../../../utils/theme"),_coupon=require("../../../utils/coupon"),_featureProcess=require("../../../utils/feature-process");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 _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 c(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,n){return t[e]=n}}function s(t,e,n,r){var i=e&&e.prototype instanceof f?e:f,u=Object.create(i.prototype),a=new T(r||[]);return o(u,"_invoke",{value:S(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=s;var l={};function f(){}function d(){}function h(){}var v={};c(v,i,function(){return this});var y=Object.getPrototypeOf,m=y&&y(y(I([])));m&&m!==e&&n.call(m,i)&&(v=m);var g=h.prototype=f.prototype=Object.create(v);function b(t){["next","throw","return"].forEach(function(e){c(t,e,function(t){return this._invoke(e,t)})})}function _(t,e){function r(o,i,u,a){var c=p(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.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){s.value=t,u(s)},function(t){return r("throw",t,u,a)})}a(c.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 S(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=w(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 c=p(t,e,n);if("normal"===c.type){if(o=n.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(o="completed",n.method="throw",n.arg=c.arg)}}}function w(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,w(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 C(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 k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function T(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(C,this),this.reset(!0)}function I(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 d.prototype=h,o(g,"constructor",{value:h,configurable:!0}),o(h,"constructor",{value:d,configurable:!0}),d.displayName=c(h,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},b(_.prototype),c(_.prototype,u,function(){return this}),t.AsyncIterator=_,t.async=function(e,n,o,r,i){void 0===i&&(i=Promise);var u=new _(s(e,n,o,r),i);return t.isGeneratorFunction(n)?u:u.next().then(function(t){return t.done?t.value:u.next()})},b(g),c(g,a,"Generator"),c(g,i,function(){return this}),c(g,"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=I,T.prototype={constructor:T,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(k),!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"),c=n.call(i,"finallyLoc");if(a&&c){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(!c)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),k(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;k(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:I(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),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).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},showEntry:{type:Boolean,value:!1},entryTheme:{type:String,value:"light"},mode:{type:String,value:"portrait"}},data:{couponList:[],useDarkTheme:!1,hasValidCoupons:!1,drawerTheme:{Fill_7:"#FFFFFF"}},lifetimes:{attached:function(){this.shownCouponIds=[]},detached:function(){"function"==typeof this.unsub&&this.unsub(),this.unsub=null}},observers:{sdkInstance:function(t){if(t){this.sdkInstance=t,this.store=t.store;var e=this;"function"==typeof this.unsub&&this.unsub(),this.unsub=null,this.unsub=this.store.get({liveInfo:function(t){(0,_utils.setDataIfChanged)(e,{useDarkTheme:(0,_theme.isUseDarkTheme)(null==t?void 0:t.Basic)})},imageTextInfo:function(){(0,_utils.setDataIfChanged)(e,{hasValidCoupons:e._hasAnyCoupons()})}})}}},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&&i.CouponContext)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"),c=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||null!=e&&e.CouponContext){var s=null==e?void 0:e.CouponContext;if(s){var p=s.Coupon||s,l=i&&u&&(0,_coupon.isCouponPicked)(u,i,p.Id||s.Id)?1:0,f=(0,_coupon.calcCouponStatus)(p,l),d=f===_coupon.CouponStatusType.Pickup?f:null!==(o=s.couponStatus)&&void 0!==o?o:f,h=(0,_utils.getBySplit)(p.Name||"卡券"),v=(0,_utils.getBySplit)(p.Description||""),y=p.Pic||DefaultCouponUrl,m="";if(void 0!==p.Count&&void 0!==p.PickupCount&&-1!==p.Count){var g=Math.max(0,Number(p.Count)-Number(p.PickupCount));m="剩余 ".concat(g,"/").concat(p.Count)}var b=p.EndTime?"有效期至 ".concat(formatTime(p.EndTime)):"",_=t._getBtnState(d),S=(0,_coupon.isCouponLevelEligible)(null!=r?r:"",s),w=(0,_coupon.isCouponWatchEligible)(s,{liveStatus:a,watchTime:c,activityId:u});S&&n.push(_objectSpread(_objectSpread({},s),{},{_display:{title:h,desc:v,imageUrl:y,countText:m,timeText:b,btnText:_.btnText,btnDisabled:_.btnDisabled,isReceived:_.isReceived,couponStatus:d,levelEligible:S,watchEligible:w}}))}}})}),n.sort(function(t,e){return(e.SendTime||0)-(t.SendTime||0)})},_getBtnState:function(t){return t===_coupon.CouponStatusType.Sending?{btnText:"立即领取",btnDisabled:!1,isReceived:!1}:t===_coupon.CouponStatusType.SendCompleted?{btnText:"已领完",btnDisabled:!0,isReceived:!1}:t===_coupon.CouponStatusType.Pickup?{btnText:"已领取",btnDisabled:!0,isReceived:!0}:t===_coupon.CouponStatusType.Received?{btnText:_coupon.CouponReceivedLimitText,btnDisabled:!0,isReceived:!1}:t===_coupon.CouponStatusType.End?{btnText:"已结束",btnDisabled:!0,isReceived:!1}:{btnText:"立即领取",btnDisabled:!1,isReceived:!1}},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(){this.setData({})},onViewProducts:function(){var t=this.selectComponent("#coupon-list-drawer");t&&t.hideFrame&&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)}))()},_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"})},_doPickup:function(t){var e=this;return _asyncToGenerator(_regeneratorRuntime().mark(function n(){var o,r,i,u,a,c,s,p,l,f,d,h,v;return _regeneratorRuntime().wrap(function(n){for(;;)switch(n.prev=n.next){case 0:if(o=t.Coupon||t,r=e.store.get("liveInfo")||{},i=r.ActivityId,u=e.store.get("userInfo")||{},a=u.userId,c=u.levelId,i&&a){n.next=6;break}return n.abrupt("return");case 6:if(e._reportCouponTea("pick_up_coupon",{couponId:o.Id,isLogin:!0}),e.isLogin(!0)){n.next=9;break}return n.abrupt("return");case 9:if((0,_coupon.isCouponLevelEligible)(null!=c?c:"",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(s=e.store.get("coupon.liveStatus"),p=e.store.get("coupon.watchTime"),(0,_coupon.isCouponWatchEligible)(t,{liveStatus:s,watchTime:p,activityId:i},function(t,n){return e._reportCouponTea(t,n)})){n.next=19;break}return wx.showToast({title:"观看后可领取",icon:"none"}),n.abrupt("return");case 19:return n.next=21,e.sdkInstance.request(_constant.REQUEST_URL_MAP.COUPON_PICKUP,{method:"POST",data:{ActivityID:i,Id:o.Id}});case 21:if(l=n.sent,e._reportCouponTea("pick_up_coupon_status",{couponId:o.Id,status:null==l?void 0:l.Status,res:l}),f=null==l?void 0:l.Status,d=_coupon.CouponStatusType.Pickup,![_coupon.CouponPickupStatus.Success,_coupon.CouponPickupStatus.Pickup,_coupon.CouponPickupStatus.SendCompleted].includes(f)){n.next=29;break}f===_coupon.CouponPickupStatus.SendCompleted?d=_coupon.CouponStatusType.SendCompleted:(0,_coupon.markCouponPicked)(i,a,o.Id),n.next=48;break;case 29:if(f!==_coupon.CouponPickupStatus.Ended){n.next=38;break}if(!(null!=l&&l.EndTime&&o.SendTime&&l.EndTime<o.SendTime)){n.next=33;break}return e.sdkInstance.setCouponPickupStatus(0),n.abrupt("return");case 33:return e.sdkInstance.setCouponPickupStatus(_coupon.CouponStatusType.End),wx.showToast({title:"已结束",icon:"none"}),n.abrupt("return");case 38:if(f!==_coupon.CouponPickupStatus.Received){n.next=43;break}return e._handleCouponPickupReceivedLimit(o),n.abrupt("return");case 43:return e._reportCouponTea("pick_up_coupon_err",{couponId:o.Id,res:l}),e.sdkInstance&&null!==(h=e.sdkInstance.EVENTS)&&void 0!==h&&null!==(v=h.coupon)&&void 0!==v&&v.pickUpError&&e.sdkInstance.emit(e.sdkInstance.EVENTS.coupon.pickUpError,{couponId:o.Id,res:l}),e.sdkInstance.setCouponPickupStatus(0),wx.showToast({title:"活动太火爆了,请稍后重试",icon:"none"}),n.abrupt("return");case 48:f!==_coupon.CouponPickupStatus.Pickup&&(e.sdkInstance.setCouponPickupStatus(d),wx.showToast({title:d===_coupon.CouponStatusType.SendCompleted?"已领完":"领取成功",icon:"none"}));case 49:case"end":return n.stop()}},n)}))()},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)}}}); |