import{d as m,be as h,a as e,A as r,P as f,C as k,a1 as g}from"./index-5a763f46.js";import{u as S}from"./student-register-store-095bcb1b.js";import{C as c}from"./index-18ed1ff2.js";import{I as n}from"./index-ee50f8d6.js";import{R as _,a as y}from"./index-70bfd940.js";import{T as I}from"./index-2a3fa569.js";import{S as C}from"./index-10ed028c.js";const b=""+new URL("icon-sell-out-437e8d6c.png",import.meta.url).href,L="_addGoodsCart_16cde_1",O="_addCartBtn_16cde_25",N="_goodsSection_16cde_33",v="_sellOut_16cde_40",x="_goodsImg_16cde_52",D="_goodsPrice_16cde_58",A="_goodsStore_16cde_67",G="_title_16cde_72",R="_radio_16cde_77",a={addGoodsCart:L,addCartBtn:O,goodsSection:N,sellOut:v,goodsImg:x,goodsPrice:D,goodsStore:A,title:G,"radio-group":"_radio-group_16cde_77",radio:R};function B(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!g(t)}const u=S(),E=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 d=JSON.parse(s.spData);let l="";d.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(d=>d.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(d=>{d.productId===i.productId&&d.productSkuId===i.productSkuId&&(s=!0,d.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:b,fit:"cover",class:a.sellOutImg},null)])]),title:()=>e("div",{class:a.goodsInfo},[e("p",{class:a.goodsPrice},[e("span",null,[r("￥")]),f(this.selectItem.price)]),e("p",{class:a.goodsStore},[r("库存："),this.selectItem.stock])])}),e(c,null,{title:()=>e("div",{class:a.title},[r("规格")]),label:()=>{let t;return e(_,{class:a["radio-group"],modelValue:this.radio},B(t=this.skuStockList.map(o=>{const i=o.id===this.radio,s=i?"primary":"default";return e(y,{class:a.radio,name:o.id,onClick:()=>{this.radio!=o.id&&(this.radio=o.id)}},{default:()=>[e(I,{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(C,{modelValue:this.total,"onUpdate:modelValue":t=>this.total=t,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{E as A,b as i};
