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