acdr-ui/dist/build/mp-weixin/modules/mall/sheep/components/s-coupon-block/s-coupon-block.js
2024-10-01 09:15:35 +08:00

2 lines
2.5 KiB
JavaScript

"use strict";var e=(e,t,o)=>new Promise(((n,r)=>{var i=e=>{try{u(o.next(e))}catch(t){r(t)}},a=e=>{try{u(o.throw(e))}catch(t){r(t)}},u=e=>e.done?n(e.value):Promise.resolve(e.value).then(i,a);u((o=o.apply(e,t)).next())}));const t=require("../../../../../common/vendor.js"),o=require("../../index.js"),n=require("../../api/promotion/coupon.js"),r=require("../../util/const.js"),i=require("../../util/index.js");if(!Array){t.resolveComponent("su-coupon")()}Math;const a={__name:"s-coupon-block",props:{data:{type:Object,default:()=>({})},styles:{type:Object,default:()=>({})}},setup(a){const u=a,{columns:s,button:p}=u.data,c=["lg","md","xs"],d={background:`url(${o.sheep.$url.cdn(u.data.bgImg)}) no-repeat top center / 100% 100%`},l={background:p.bgColor,color:p.color},y={display:"flex","justify-content":"space-between"},m={display:"flex","justify-content":"space-around"},T=t.computed((()=>{const{bgType:e,bgImg:t,bgColor:o}=u.styles;return{background:"img"===e?`url(${t}) no-repeat top center / 100% 100%`:o}})),f=e=>e.discountType===r.PromotionDiscountTypeEnum.PRICE.type?i.floatToFixed2(e.discountPrice):e.discountType===r.PromotionDiscountTypeEnum.PERCENT.type?e.discountPercent:`未知【${e.discountType}`,g=t.ref([]);function v(o){return e(this,null,(function*(){const{error:e,msg:r}=yield n.CouponApi.takeCoupon(o);0!==e?yield b():t.index.showToast({title:r,icon:"none"})}))}const b=()=>e(this,null,(function*(){const{data:e}=yield n.CouponApi.getCouponTemplateListByIds(u.data.couponIds.join(","));g.value=e}));return t.onMounted((()=>{b()})),(e,o)=>({a:t.f(g.value,((e,o,n)=>{return t.e(2===t.unref(s)?{a:t.o((t=>v(e.id)),o),b:t.s(l)}:{c:t.s(l),d:t.o((t=>v(e.id)),o)},{e:"0f7b8e2e-0-"+n,f:t.p({size:c[t.unref(s)-1],textColor:a.data.textColor,background:"",couponId:e.id,title:e.name,type:(p=e,p.discountType===r.PromotionDiscountTypeEnum.PRICE.type?"reduce":p.discountType===r.PromotionDiscountTypeEnum.PERCENT.type?"percent":`未知【${p.discountType}`),value:f(e),sellBy:(u=e,u.validityType===r.CouponTemplateValidityTypeEnum.DATE.type?`${i.formatDate(u.validStartTime)}${i.formatDate(u.validEndTime)}`:u.validityType===r.CouponTemplateValidityTypeEnum.TERM.type?`领取后第 ${u.fixedStartTerm} - ${u.fixedEndTerm} 天内可用`:"未知【"+u.validityType+"】")}),g:o});var u,p})),b:2===t.unref(s),c:t.s(d),d:t.s({marginLeft:`${a.data.space}px`}),e:t.s(2===g.value.length?m:y),f:t.s(T.value),g:t.s({marginLeft:`${a.data.space}px`})})}},u=t._export_sfc(a,[["__scopeId","data-v-0f7b8e2e"]]);wx.createComponent(u);