var k=Object.defineProperty,y=Object.defineProperties;var S=Object.getOwnPropertyDescriptors;var u=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,C=Object.prototype.propertyIsEnumerable;var p=(t,s,o)=>s in t?k(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o,r=(t,s)=>{for(var o in s||(s={}))_.call(s,o)&&p(t,o,s[o]);if(u)for(var o of u(s))C.call(s,o)&&p(t,o,s[o]);return t},h=(t,s)=>y(t,S(s));import{r as m,m as I}from"./index.3d95a92c.js";import{d as x,T as b,a as e,q as c,I as f,j as l,ac as j,ad as v,z as O,x as A,O as D,B as L}from"./vendor.a0144ce9.js";/* empty css               *//* empty css               *//* empty css               *//* empty css                *//* empty css                *//* empty css                */import{i as G}from"./icon-sell-out.bc315722.js";const T="_addGoodsCart_17hfd_1",N="_goodsSection_17hfd_16",P="_sellOut_17hfd_23",F="_goodsImg_17hfd_35",J="_goodsPrice_17hfd_41",V="_goodsStore_17hfd_50",w="_title_17hfd_55",R="_radio_17hfd_60";var i={addGoodsCart:T,goodsSection:N,sellOut:P,goodsImg:F,goodsPrice:J,goodsStore:V,title:w,"radio-group":"_radio-group_17hfd_60",radio:R};function q(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!A(t)}var X=x({name:"add-goods-cart",props:{item:{type:Object,default:{}},defaultRadio:{type:Number,default:0},showType:{type:String,default:"cart"},onGetCartCount:{type:Function,default:t=>{}}},data(){return{radio:"",total:1,totalData:{},skuStockList:[]}},mounted(){this.setList()},computed:{selectItem(){const t=this.skuStockList.find(s=>s.id==this.radio);return t?h(r({},t),{stock:t.stock-(t.lockStock<0?0:t.lockStock)}):{stock:0}}},methods:{setList(){let t=[];const s=JSON.parse(JSON.stringify(this.item));if(Array.isArray(s.skuStockList)&&(t=s.skuStockList.map(a=>{if(a.pic=a.pic||s.pic,a.spData){const d=JSON.parse(a.spData);let n="";d.forEach(g=>{n+=`${g.value}`}),a.spDataJson=n}else a.spDataJson="\u9ED8\u8BA4";return a.lock=a.stock-a.lockStock,r({},a)})),!t.length)return t;let o=0;if(this.defaultRadio){let a=t.findIndex(d=>d.id==this.defaultRadio);o=a>-1?a:0}this.getProductAddCartCount(t[o].id),this.radio=t[o].id,this.skuStockList=t},async onAddCart(){const t=this.selectItem,s=this.item,o={price:t.price,productSkuId:t.id,quantity:this.total,productId:s.id,hidden:this.showType==="cart"?0:1};try{let{code:a,data:d}=await m.post("/api-mall-portal/cart/add",{data:o});a===200&&(this.totalData[t.id]=this.total,this.showType==="cart"?(this.onGetCartCount(),this.$nextTick(()=>{setTimeout(()=>{b({icon:"success",message:"\u6DFB\u52A0\u5546\u54C1\u6210\u529F"})},500)})):this.$router.push({path:"/cartConfirm",query:{cartIds:d.id}}))}catch{}},async getProductAddCartCount(t){if(t=t||this.selectItem.id,this.totalData[t]){this.total=this.totalData[t];return}if(!!t)try{let s=await m.get(`/api-mall-portal/product/cart/${t}`);this.totalData[t]=this.total=s.data||1}catch{}}},render(){return e("div",{class:i.addGoodsCart},[e(c,{titleStyle:{paddingLeft:"12px"}},{icon:()=>e("div",{class:i.goodsSection},[e(f,{src:this.selectItem.pic,class:i.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&e("div",{class:i.sellOut},[e(f,{src:G,fit:"cover",class:i.sellOutImg},null)])]),title:()=>e("div",{class:i.goodsInfo},[e("p",{class:i.goodsPrice},[e("span",null,[l("\uFFE5")]),I(this.selectItem.price)]),e("p",{class:i.goodsStore},[l("\u5E93\u5B58\uFF1A"),this.selectItem.stock])])}),e(c,null,{title:()=>e("div",{class:i.title},[l("\u89C4\u683C")]),label:()=>{let t;return e(j,{class:i["radio-group"],modelValue:this.radio},q(t=this.skuStockList.map(s=>{const o=s.id===this.radio,a=o?"primary":"default";return e(v,{class:i.radio,name:s.id,onClick:()=>{this.radio!=s.id&&(this.radio=s.id,this.getProductAddCartCount(s.id))}},{default:()=>[e(O,{size:"large",plain:o,type:a},{default:()=>[s.spDataJson]})]})}))?t:{default:()=>[t]})}}),e(c,{title:"\u8D2D\u4E70\u6570\u91CF",style:{margin:"12px 0"},border:!1,titleClass:i.title,center:!0},{default:()=>[e(D,{modelValue:this.total,"onUpdate:modelValue":t=>this.total=t,inputWidth:"50px",theme:"round",buttonSize:"24px",max:this.selectItem.stock,min:1,disabled:this.selectItem.stock<=0,integer:!0},null)]}),e("div",{class:["btnGroup"],style:{marginBottom:"8px"}},[e(L,{block:!0,round:!0,type:"primary",text:"\u786E\u5B9A",disabled:this.selectItem.stock<=0,onClick:()=>this.onAddCart()},null)])])}});export{X as A};
