index.15e122d4.js 6.2 KB

1
  1. import{d,j as n,A as p,F as r,C,aT as f,B as L,g as h,y as I,aS as S}from"./ResizeObserver.es.b7226882.js";import{C as g}from"./index.40f703b6.js";import{u as y}from"./hooks.a4ed20cb.js";import{I as m}from"./item.a48bb030.js";const E="_useCoupon_ne7c2_1",A="_couponCount_ne7c2_4",T="_choiceCoupon_ne7c2_13",b="_couponTitle_ne7c2_19",U="_iconClose_ne7c2_31",N="_couponContent_ne7c2_38",_="_couponFooter_ne7c2_45",V="_couponSelectText_ne7c2_52",O="_btnTenant_ne7c2_61";var c={useCoupon:E,couponCount:A,choiceCoupon:T,couponTitle:b,iconClose:U,couponContent:N,couponFooter:_,couponSelectText:V,btnTenant:O},P=d({name:"choice-coupon",props:{orderAmount:{type:Number,default:0},orderGoodsType:{type:Array,default:()=>[]},useCoupon:{type:Array,default:()=>[]},couponCategory:{type:String,default:"UNIVERSAL"},couponList:{type:Array,default:()=>[]},usedLength:{type:String,default:"MULTIPLE"}},emits:["close","submit"],data(){return{list:[],dataLoading:!1}},computed:{useLength(){return this.list.filter(o=>o.checked).length||0}},async mounted(){this.couponList.forEach(t=>{this.useCoupon.forEach(e=>{t.couponIssueId===e.couponIssueId&&(t.checked=!0)})});const o=this.couponList.filter(t=>!t.disabled),s=this.couponList.filter(t=>t.disabled);this.list=[...o,...s],this.calcCoupon(),y("\u4F18\u60E0\u5238")},methods:{onSubmit(){this.$emit("submit",this.list.filter(o=>o.checked)),this.list.forEach(o=>{o.checked=!1})},onSelect(o){o.checked=!o.checked,this.calcCoupon()},calcCoupon(){const o=this.list.filter(s=>s.checked);if(this.usedLength==="SINGLE"){let s={};o.forEach(t=>{const e=s[t.couponCategory];s[t.couponCategory]=(e||0)+t.useLimit}),this.list.forEach(t=>{let e=!0;if(t.couponCategory==="UNIVERSAL"){let u=0;this.orderGoodsType.forEach(a=>{u+=a.price});let i=0;for(let a in s)i=i+s[a];e=t.useLimit>u-i}else{const u=this.orderGoodsType.find(a=>l[a.orderType]===t.couponCategory),i=u?u.price-(s[t.couponCategory]||0):0;e=Number(t.useLimit)>i}!t.checked&&(o.length>0||e)?t.disabled=!0:t.disabled=!1}),s=null}else{const s=o.map(u=>Number(u.useLimit||0)),t=s.length>0?s.reduce((u,i)=>u+i):0,e=this.orderAmount-t;this.list.forEach(u=>{Number(u.useLimit)>e&&!u.checked?u.disabled=!0:u.disabled=!1})}}},render(){return n("div",{class:c.choiceCoupon},[n("div",{class:c.couponTitle},[n("span",null,[p("\u4F18\u60E0\u5238")]),n("i",{class:c.iconClose,onClick:()=>this.$emit("close")},null)]),n("div",{class:c.couponContent},[this.dataLoading?n(f,{size:48,color:"#2dc7aa",vertical:!0,style:{height:"100%",justifyContent:"center"}},{default:()=>[p("\u52A0\u8F7D\u4E2D...")]}):n(r,null,[this.list.length>0?n(r,null,[this.list.map(o=>n(m,{item:o,isSelect:!0,onClick:this.onSelect},null))]):n(C,{btnStatus:!1,tips:"\u6682\u65E0\u4F18\u60E0\u5238",classImgSize:"SMALL"},null)])]),n("div",{class:[c.couponFooter,"van-hairline--top"]},[n("div",{class:c.couponSelectText},[p("\u5DF2\u9009"),n("span",null,[this.useLength]),p("\u5F20")]),n(L,{type:"primary",round:!0,class:h.projectType==="tenant"&&c.btnTenant,style:{minWidth:"105px",fontSize:"16px"},onClick:this.onSubmit},{default:()=>[p("\u786E\u5B9A")]})])])}});const l={UNIVERSAL:"UNIVERSAL",VIP:"VIP",SVIP:"SVIP",PIANO_ROOM:"PIANO",GOODS:"MALL",MUSIC:"MUSIC",VIP_COURSE:"VIP_COURSE",DISCOUNT:"DISCOUNT",PRACTICE:"SPARRING",LIVE:"LIVE",GROUP:"GROUP",VIDEO:"VIDEO",ALBUM:"ALBUM"},D={UNIVERSAL:"UNIVERSAL",VIP:"VIP",SVIP:"SVIP",PIANO:"PIANO_ROOM",MALL:"GOODS",MUSIC:"MUSIC",VIP_COURSE:"VIP_COURSE",DISCOUNT:"DISCOUNT",SPARRING:"PRACTICE",LIVE:"LIVE",GROUP:"GROUP",VIDEO:"VIDEO",ALBUM:"ALBUM"};var F=d({name:"use-conpon",props:{disabled:{type:Boolean,default:!1},orderAmount:{type:Number,default:0},orderType:{type:String,default:""},orderGoodsType:{type:Array,default:()=>[]},discountPrice:{type:Number,default:0},couponId:{type:String,default:""},usedLength:{type:String,default:"SINGLE"}},emits:["couponSelect"],data(){return{popupStatus:!1,popupLoading:!1,useCouponList:[],useCouponLoading:!1,useCouponCount:0,dataLoading:!1,list:[]}},computed:{couponCount(){const o=this.useCouponList.map(t=>Number(t.discountPrice||0));let s=0;return this.disabled?s=this.discountPrice:s=o.length>0?o.reduce((t,e)=>t+e):0,s},couponCategory(){const o=[];return this.orderGoodsType.forEach(s=>{l[s.orderType]&&o.push(l[s.orderType])}),o.join(",")+(o.length?",UNIVERSAL":"UNIVERSAL")}},watch:{couponId(o){const s=o?o.split(",").map(e=>Number(e)):[],t=[];this.useCouponList.forEach(e=>{s.includes(e.couponIssueId)&&t.push(e)}),this.useCouponList=t}},mounted(){this.getList()},methods:{resetCouponList(){this.list=[],this.getList()},async getList(){if(!this.dataLoading){this.dataLoading=!0;try{const o=await I.post(`${h.platformApi}/couponInfo/page`,{data:{couponCategory:this.couponCategory,couponType:"FULL_DISCOUNT",useState:"USABLE",orderUse:1,page:1,rows:100}});this.dataLoading=!1;const s=o.data||{};if(this.list.length>0&&s.pageNo===1)return;this.list=s.rows||[],this.list.forEach(e=>{if(e.checked=!1,e.couponCategory==="UNIVERSAL"){let u=0;this.orderGoodsType.forEach(i=>{u+=Number(i.price)}),console.log(u,"1212"),e.disabled=!(e.useLimit<=u)}else{const i=this.orderGoodsType.find(a=>l[a.orderType]===e.couponCategory).price||0;e.useLimit>i?e.disabled=!0:e.disabled=!1}});let t=0;this.list.forEach(e=>{e.disabled||t++}),this.useCouponCount=t}catch{}}},onSubmit(o){this.useCouponList=o,this.$emit("couponSelect",o),this.popupStatus=!1,this.popupLoading=!1}},render(){return n(r,null,[n(g,{title:"\u4F18\u60E0\u5238",class:c.useCoupon,isLink:!this.disabled,clickable:!1,onClick:()=>{this.disabled||(this.popupStatus=!0,this.popupLoading=!0)}},{value:()=>!this.useCouponLoading&&n(r,null,[this.couponCount>0?n("span",{class:c.couponCount},[n("i",null,[p("-\uFFE5")]),this.couponCount]):n(r,null,[this.useCouponCount>0?`${this.useCouponCount}\u5F20\u53EF\u4F7F\u7528`:"\u6682\u65E0\u53EF\u4F7F\u7528\u4F18\u60E0\u5238"])])}),n(S,{show:this.popupStatus,"onUpdate:show":o=>this.popupStatus=o,position:"bottom",round:!0,safeAreaInsetBottom:!0,style:{height:"75%"},onClosed:()=>{this.popupLoading=!1}},{default:()=>[this.popupLoading&&n(P,{usedLength:this.usedLength,couponCategory:this.couponCategory,useCoupon:this.useCouponList,orderAmount:this.orderAmount,orderGoodsType:this.orderGoodsType,couponList:this.list,onClose:()=>this.popupStatus=!1,onSubmit:o=>this.onSubmit(o)},null)]})])}});export{F as U,D as c};