index-61252f21.js 3.9 KB

1
  1. import{d as m,bh as h,a as e,A as d,P as f,C as k,a1 as S}from"./index-fac4d009.js";import{u as g,S as _}from"./student-register-store-5f367f9a.js";import{R as y,a as I}from"./index-5a3fcd76.js";import{C as c}from"./index-5cba6af7.js";import{I as u}from"./index-fdcc93f3.js";import{T as C}from"./index-a0c979fe.js";const x=""+new URL("icon-sell-out-437e8d6c.png",import.meta.url).href,b="_addGoodsCart_1x0mj_1",L="_addCartBtn_1x0mj_18",j="_goodsSection_1x0mj_26",D="_sellOut_1x0mj_33",O="_goodsImg_1x0mj_45",N="_goodsPrice_1x0mj_51",v="_goodsStore_1x0mj_60",A="_title_1x0mj_65",B="_radio_1x0mj_70",a={addGoodsCart:b,addCartBtn:L,goodsSection:j,sellOut:D,goodsImg:O,goodsPrice:N,goodsStore:v,title:A,"radio-group":"_radio-group_1x0mj_70",radio:B};function G(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!S(t)}const n=g(),T=m({name:"add-goods-cart",props:{show:{type:Boolean,default:!1},item:{type:Object,default:{}},defaultRadio:{type:Number,default:0},showType:{type:String,default:"cart"},onClose:{type:Function,default:()=>{}}},watch:{show(t){t&&(this.totalData={},this.total=1,this.radio="",this.setList())}},data(){return{radio:"",total:1,totalData:{},skuStockList:[]}},computed:{selectItem(){const t=this.radio,o=this.skuStockList.find(i=>i.id==t);if(o){let i=o.stock-o.lockStock;return{...o,stock:i}}return{stock:0}}},mounted(){this.setList()},methods:{setList(){let t=[];const o=JSON.parse(JSON.stringify(this.item));if(Array.isArray(o.skuStockList)&&(t=o.skuStockList.map(s=>{if(s.pic=s.pic||o.pic,s.cartNum=0,s.spData){const r=JSON.parse(s.spData);let l="";r.forEach(p=>{l+=`${p.value}`}),s.spDataJson=l}else s.spDataJson="默认";return s.lockStock=s.lockStock>0?s.lockStock:0,{...s}})),!t.length)return t;let i=0;if(this.defaultRadio){let s=t.findIndex(r=>r.id==this.defaultRadio);i=s>-1?s:0}this.radio=t[i].id,this.skuStockList=t},async onAddCart(){const t=this.selectItem,o=this.item,i={pic:o.pic,name:o.name,brandName:o.brandName,productSn:o.productSn,price:t.price,originalPrice:o.originalPrice,productSkuId:t.id,stock:t.stock,quantity:this.total,productId:o.id,spDataJson:t.spDataJson,hidden:this.showType==="cart"?0:1,promoterId:this.$route.query.promoterId?this.$route.query.promoterId:void 0};try{let s=!1;n.getGoods.forEach(r=>{r.productId===i.productId&&r.productSkuId===i.productSkuId&&(s=!0,r.quantity+=i.quantity)}),s||n.setGoods(i),h("添加成功"),this.onClose()}catch(s){}},setProductStock(t){for(let o=0;o<this.skuStockList.length;o++)this.skuStockList[o].id===this.radio&&(this.skuStockList[o].cartNum=t)}},render(){return e("div",{class:a.addGoodsCart},[e(c,{titleStyle:{paddingLeft:"12px"}},{icon:()=>e("div",{class:a.goodsSection},[e(u,{src:this.selectItem.pic,class:a.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&e("div",{class:a.sellOut},[e(u,{src:x,fit:"cover",class:a.sellOutImg},null)])]),title:()=>e("div",{class:a.goodsInfo},[e("p",{class:a.goodsPrice},[e("span",null,[d("¥")]),f(this.selectItem.price)]),e("p",{class:a.goodsStore},[d("库存:"),this.selectItem.stock])])}),e(c,null,{title:()=>e("div",{class:a.title},[d("规格")]),label:()=>{let t;return e(y,{class:a["radio-group"],modelValue:this.radio},G(t=this.skuStockList.map(o=>{const i=o.id===this.radio,s=i?"primary":"default";return e(I,{class:a.radio,name:o.id,onClick:()=>{this.radio!=o.id&&(this.radio=o.id)}},{default:()=>[e(C,{size:"large",plain:i,type:s},{default:()=>[o.spDataJson]})]})}))?t:{default:()=>[t]})}}),e(c,{title:"购买数量",style:{margin:"12px 0"},border:!1,titleClass:a.title,center:!0},{default:()=>[e(_,{modelValue:this.total,"onUpdate:modelValue":t=>this.total=t,inputWidth:"50px",theme:"round",buttonSize:"24px",max:this.selectItem.stock>200?200:this.selectItem.stock,min:1,disabled:this.selectItem.stock<=0,integer:!0},null)]}),e("div",{class:["btnGroup"],style:{marginBottom:"8px"}},[e(k,{block:!0,type:"primary",text:"确定",class:a.addCartBtn,disabled:this.selectItem.stock<=0,onClick:()=>this.onAddCart()},null)])])}});export{T as A,x as i};