import{d as m,b5 as h,a as e,A as d,P as f,C as k,a1 as S}from"./index-971588a5.js";import{u as g,S as _}from"./student-register-store-6f724b72.js";import{R as y,a as I}from"./index-29f034b9.js";import{C as c}from"./index-a1fa647c.js";import{I as n}from"./index-96cc08e7.js";import{T as x}from"./index-78498c0e.js";const C=""+new URL("icon-sell-out-437e8d6c.png",import.meta.url).href,b="_addGoodsCart_1x0mj_1",L="_addCartBtn_1x0mj_18",j="_goodsSection_1x0mj_26",O="_sellOut_1x0mj_33",N="_goodsImg_1x0mj_45",v="_goodsPrice_1x0mj_51",D="_goodsStore_1x0mj_60",A="_title_1x0mj_65",G="_radio_1x0mj_70",a={addGoodsCart:b,addCartBtn:L,goodsSection:j,sellOut:O,goodsImg:N,goodsPrice:v,goodsStore:D,title:A,"radio-group":"_radio-group_1x0mj_70",radio:G};function R(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!S(t)}const u=g(),V=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;u.getGoods.forEach(r=>{r.productId===i.productId&&r.productSkuId===i.productSkuId&&(s=!0,r.quantity+=i.quantity)}),s||u.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(n,{src:this.selectItem.pic,class:a.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&e("div",{class:a.sellOut},[e(n,{src:C,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},R(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(x,{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{V as A,C as i};
