import{d as h,x as u,T as m,j as e,z as d,bz as f,B as k,Z as g}from"./index.3bfa6a0e.js";import{C as c}from"./index.79997a38.js";import{I as n}from"./index.0fd5538f.js";import{R as S,a as y}from"./index.f272c75f.js";import"./index.fb1da5d0.js";import{S as _}from"./index.7d6c10fe.js";import{T as I}from"./index.c171ade0.js";import{i as C}from"./icon-sell-out.98742fd0.js";import{g as b}from"./shop-mall.d29c3bd4.js";const L="_addGoodsCart_17hfd_1",x="_goodsSection_17hfd_16",O="_sellOut_17hfd_23",v="_goodsImg_17hfd_35",D="_goodsPrice_17hfd_41",T="_goodsStore_17hfd_50",w="_title_17hfd_55",A="_radio_17hfd_60";var i={addGoodsCart:L,goodsSection:x,sellOut:O,goodsImg:v,goodsPrice:D,goodsStore:T,title:w,"radio-group":"_radio-group_17hfd_60",radio:A};function G(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!g(t)}var B=h({name:"add-goods-cart",props:{show:{type:Boolean,default:!1},item:{type:Object,default:{}},defaultRadio:{type:Number,default:0},showType:{type:String,default:"cart"},onGetCartCount:{type:Function,default:t=>{}}},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(a=>a.id==t);if(o){let a=o.stock-o.lockStock;return{...o,stock:a}}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="\u9ED8\u8BA4";return s.lockStock=s.lockStock>0?s.lockStock:0,{...s}})),!t.length)return t;let a=0;if(this.defaultRadio){let s=t.findIndex(r=>r.id==this.defaultRadio);a=s>-1?s:0}this.radio=t[a].id,this.skuStockList=t},async onAddCart(){const t=this.selectItem,o=this.item,a={price:t.price,productSkuId:t.id,quantity:this.total,productId:o.id,hidden:this.showType==="cart"?0:1,promoterId:this.$route.query.promoterId?this.$route.query.promoterId:void 0};try{let{code:s,data:r}=await u.post("/api-mall-portal/cart/add",{data:a});s===200&&(this.showType==="cart"?(this.onGetCartCount(),this.$nextTick(()=>{setTimeout(()=>{m({icon:"success",message:"\u6DFB\u52A0\u5546\u54C1\u6210\u529F"})},500)})):this.$router.push({path:"/cartConfirm",query:{cartIds:r.id}}),b())}catch{}},async getProductAddCartCount(t,o=!1){if(t=t||this.selectItem.id,this.totalData.hasOwnProperty(t)&&!o){this.setProductStock(this.totalData[t]);return}if(!!t)try{let a=await u.get(`/api-mall-portal/product/cart/${t}`);this.setProductStock(a.data||0),this.totalData[t]=a.data||0}catch{}},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:i.addGoodsCart},[e(c,{titleStyle:{paddingLeft:"12px"}},{icon:()=>e("div",{class:i.goodsSection},[e(n,{src:this.selectItem.pic,class:i.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&e("div",{class:i.sellOut},[e(n,{src:C,fit:"cover",class:i.sellOutImg},null)])]),title:()=>e("div",{class:i.goodsInfo},[e("p",{class:i.goodsPrice},[e("span",null,[d("\uFFE5")]),f(this.selectItem.price)]),e("p",{class:i.goodsStore},[d("\u5E93\u5B58\uFF1A"),this.selectItem.stock])])}),e(c,null,{title:()=>e("div",{class:i.title},[d("\u89C4\u683C")]),label:()=>{let t;return e(S,{class:i["radio-group"],modelValue:this.radio},G(t=this.skuStockList.map(o=>{const a=o.id===this.radio,s=a?"primary":"default";return e(y,{class:i.radio,name:o.id,onClick:()=>{this.radio!=o.id&&(this.radio=o.id)}},{default:()=>[e(I,{size:"large",plain:a,type:s},{default:()=>[o.spDataJson]})]})}))?t:{default:()=>[t]})}}),e(c,{title:"\u8D2D\u4E70\u6570\u91CF",style:{margin:"12px 0"},border:!1,titleClass:i.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,round:!0,type:"primary",text:"\u786E\u5B9A",disabled:this.selectItem.stock<=0,onClick:()=>this.onAddCart()},null)])])}});export{B as A};
