;(function(){function _toConsumableArray(arr){return _arrayWithoutHoles(arr)||_iterableToArray(arr)||_unsupportedIterableToArray(arr)||_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 _unsupportedIterableToArray(o,minLen){if(!o)return;if(typeof o==="string")return _arrayLikeToArray(o,minLen);var n=Object.prototype.toString.call(o).slice(8,-1);if(n==="Object"&&o.constructor)n=o.constructor.name;if(n==="Map"||n==="Set")return Array.from(o);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _arrayLikeToArray(o,minLen);}function _iterableToArray(iter){if(typeof Symbol!=="undefined"&&iter[Symbol.iterator]!=null||iter["@@iterator"]!=null)return Array.from(iter);}function _arrayWithoutHoles(arr){if(Array.isArray(arr))return _arrayLikeToArray(arr);}function _arrayLikeToArray(arr,len){if(len==null||len>arr.length)len=arr.length;for(var i=0,arr2=new Array(len);i 0 && result.pageNo === 1) return // this.list = result.rows || [] // // 处理可用优惠券是否支付使用 // this.list.forEach((item: any) => { // item.checked = false // // 如果使用金额大于订单金额则优惠券不可用 // if (item.useLimit > this.orderAmount) { // item.disabled = true // } else { // item.disabled = false // } // // 处理显示已选择的优惠券 // this.useCoupon.forEach((coupon: any) => { // if (item.couponIssueId === coupon.couponIssueId) { // item.checked = true // } // }) // }) // // 初始化排序 // const canUsable = this.list.filter((list: any) => !list.disabled) // const canUsed = this.list.filter((list: any) => list.disabled) // this.list = [...canUsable, ...canUsed] // this.calcCoupon() // } catch { // // // } // }, onSubmit:function onSubmit(){// 返回选中的优惠券 this.$emit('submit',this.list.filter(function(list){return list.checked;}));this.list.forEach(function(item){item.checked=false;});},onSelect:function onSelect(item){item.checked=!item.checked;this.calcCoupon();},calcCoupon:function calcCoupon(){// 计算优惠券 // 已使用的优惠券 var useList=this.list.filter(function(list){return list.checked;});var limitCount=useList.map(function(list){return Number(list.useLimit||0);});var usePrice=limitCount.length>0?limitCount.reduce(function(sum,list){return sum+list;}):0;// 使用优惠券后,可判断的金额 var useLastAmount=this.orderAmount-usePrice;// 判断使用优惠券之后还有没有其它优惠券可用 this.list.forEach(function(item){if(Number(item.useLimit)>useLastAmount&&!item.checked){item.disabled=true;}else{item.disabled=false;}});}},render:function render(){var _this2=this;return createVNode("div",{"class":styles.choiceCoupon},[createVNode("div",{"class":styles.couponTitle},[createVNode("span",null,[createTextVNode("\u4F18\u60E0\u5238")]),createVNode("i",{"class":styles.iconClose,"onClick":function onClick(){return _this2.$emit('close');}},null)]),createVNode("div",{"class":styles.couponContent},[!this.dataLoading?createVNode(Fragment,null,[this.list.length>0?createVNode(Fragment,null,[this.list.map(function(item){return createVNode(Item,{"item":item,"isSelect":true,"onClick":_this2.onSelect},null);})]):createVNode(ColResult,{"btnStatus":false,"tips":"暂无优惠券","classImgSize":"SMALL"},null)]):createVNode(Loading,{"size":48,"color":"#2dc7aa","vertical":true,"style":{height:'100%',justifyContent:'center'}},{default:function _default(){return[createTextVNode("\u52A0\u8F7D\u4E2D...")];}})]),createVNode("div",{"class":[styles.couponFooter,'van-hairline--top']},[createVNode("div",{"class":styles.couponSelectText},[createTextVNode("\u5DF2\u9009"),createVNode("span",null,[this.useLength]),createTextVNode("\u5F20")]),createVNode(Button,{"type":"primary","round":true,"style":{minWidth:'105px',fontSize:'16px'},"onClick":this.onSubmit},{default:function _default(){return[createTextVNode("\u786E\u5B9A")];}})])]);}});/* * 订单类型对应优惠券类型 */var couponEnum={UNIVERSAL:'UNIVERSAL',VIP:'VIP',PINAO_ROOM:'PIANO',GOODS:'MALL',MUSIC:'MUSIC',PRACTICE:'SPARRING',LIVE:'LIVE',VIDEO:'VIDEO'};var UseCoupons=exports('U',defineComponent({name:'use-conpon',props:{disabled:{type:Boolean,default:false},orderAmount:{type:Number,default:0},orderType:{type:String,default:''},discountPrice:{// 优惠券使用金额 type:Number,default:0}},emits:['couponSelect'],data:function data(){return{popupStatus:false,popupLoading:false,useCouponList:[],useCouponLoading:false,useCouponCount:0,dataLoading:false,list:[]};},computed:{couponCount:function couponCount(){var limitCount=this.useCouponList.map(function(list){return Number(list.discountPrice||0);});var count=0;if(this.disabled){count=this.discountPrice;}else{count=limitCount.length>0?limitCount.reduce(function(sum,list){return sum+list;}):0;}return count;},couponCategory:function couponCategory(){// 如果订单类型不在优惠券类型里面,则默认查询通用券 return couponEnum[this.orderType]||'UNIVERSAL';}},mounted:function mounted(){// this.getUseableCoupon() this.getList();},methods:{getList:function getList(){var _this3=this;return _asyncToGenerator(/*#__PURE__*/regeneratorRuntime.mark(function _callee2(){var res,result,count;return regeneratorRuntime.wrap(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:if(!_this3.dataLoading){_context2.next=2;break;}return _context2.abrupt("return");case 2:_this3.dataLoading=true;_context2.prev=3;_context2.next=6;return request.post("".concat(state.platformApi,"/couponInfo/page"),{data:{couponCategory:_this3.couponCategory,couponType:'FULL_DISCOUNT',useState:'USABLE',orderUse:1,page:1,rows:100}});case 6:res=_context2.sent;_this3.dataLoading=false;result=res.data||{};// 处理重复请求数据 if(!(_this3.list.length>0&&result.pageNo===1)){_context2.next=11;break;}return _context2.abrupt("return");case 11:_this3.list=result.rows||[];// 处理可用优惠券是否支付使用 _this3.list.forEach(function(item){item.checked=false;// 如果使用金额大于订单金额则优惠券不可用 if(item.useLimit>_this3.orderAmount){item.disabled=true;}else{item.disabled=false;}});count=0;_this3.list.forEach(function(item){if(!item.disabled){count++;}});console.log(_this3.list,'list');_this3.useCouponCount=count;_context2.next=21;break;case 19:_context2.prev=19;_context2.t0=_context2["catch"](3);case 21:case"end":return _context2.stop();}}},_callee2,null,[[3,19]]);}))();},// async getUseableCoupon() { // try { // this.useCouponLoading = true // // 判断是哪个端 // const url = // state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher' // const res = await request.get(`${url}/couponInfo/statInfo`) // this.useCouponLoading = false // const result = (res.data || []).find( // result => result.useState === 'USABLE' // ) // this.useCouponCount = result.total || 0 // } catch { // // TODO: handle // } // }, onSubmit:function onSubmit(item){// useCouponList this.useCouponList=item;this.$emit('couponSelect',item);this.popupStatus=false;this.popupLoading=false;}},render:function render(){var _this4=this;return createVNode(Fragment,null,[createVNode(Cell,{"title":"优惠券","class":styles.useCoupon,"style":{borderRadius:'8px'},"isLink":!this.disabled,"clickable":false,"onClick":function onClick(){if(_this4.disabled)return;_this4.popupStatus=true;_this4.popupLoading=true;}},{value:function value(){return!_this4.useCouponLoading&&createVNode(Fragment,null,[_this4.couponCount>0?createVNode("span",{"class":styles.couponCount},[createVNode("i",null,[createTextVNode("-\uFFE5")]),_this4.couponCount]):createVNode(Fragment,null,[_this4.useCouponCount>0?"".concat(_this4.useCouponCount,"\u5F20\u53EF\u4F7F\u7528"):'暂无可使用优惠券'])]);}}),createVNode(Popup,{"show":this.popupStatus,"onUpdate:show":function onUpdateShow($event){return _this4.popupStatus=$event;},"position":"bottom","round":true,"safeAreaInsetBottom":true,"style":{height:'75%'},"onClosed":function onClosed(){_this4.popupLoading=false;}},{default:function _default(){return[_this4.popupLoading&&createVNode(ChoiceCoupon,{"couponCategory":_this4.couponCategory,"useCoupon":_this4.useCouponList,"orderAmount":_this4.orderAmount,"couponList":_this4.list,"onClose":function onClose(){return _this4.popupStatus=false;},"onSubmit":function onSubmit(item){return _this4.onSubmit(item);}},null)];}})]);}}));}};});})();