1 |
- var g=Object.defineProperty,S=Object.defineProperties;var y=Object.getOwnPropertyDescriptors;var u=Object.getOwnPropertySymbols;var _=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var p=(t,s,o)=>s in t?g(t,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[s]=o,d=(t,s)=>{for(var o in s||(s={}))_.call(s,o)&&p(t,o,s[o]);if(u)for(var o of u(s))I.call(s,o)&&p(t,o,s[o]);return t},h=(t,s)=>S(t,y(s));import{r as m,m as C}from"./index.b8b9219f.js";import{d as x,T as b,b as i,p as c,I as f,j as l,H as j,J as v,X as L,v as O,Y as D,B as w}from"./vendor.2bcdc9cf.js";/* empty css *//* empty css *//* empty css *//* empty css */import{i as A}from"./index.903a2347.js";/* empty css */import{g as G}from"./shop-mall.fff18e3c.js";const N="_addGoodsCart_17hfd_1",P="_goodsSection_17hfd_16",T="_sellOut_17hfd_23",J="_goodsImg_17hfd_35",F="_goodsPrice_17hfd_41",V="_goodsStore_17hfd_50",$="_title_17hfd_55",q="_radio_17hfd_60";var a={addGoodsCart:N,goodsSection:P,sellOut:T,goodsImg:J,goodsPrice:F,goodsStore:V,title:$,"radio-group":"_radio-group_17hfd_60",radio:q};function B(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!O(t)}var Q=x({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,s=this.skuStockList.find(o=>o.id==t);if(s){let o=s.stock-s.lockStock;return h(d({},s),{stock:o})}return{stock:0}}},mounted(){this.setList()},methods:{setList(){let t=[];const s=JSON.parse(JSON.stringify(this.item));if(Array.isArray(s.skuStockList)&&(t=s.skuStockList.map(e=>{if(e.pic=e.pic||s.pic,e.cartNum=0,e.spData){const r=JSON.parse(e.spData);let n="";r.forEach(k=>{n+=`${k.value}`}),e.spDataJson=n}else e.spDataJson="\u9ED8\u8BA4";return e.lockStock=e.lockStock>0?e.lockStock:0,d({},e)})),!t.length)return t;let o=0;if(this.defaultRadio){let e=t.findIndex(r=>r.id==this.defaultRadio);o=e>-1?e:0}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,promoterId:this.$route.query.promoterId?this.$route.query.promoterId:void 0};try{let{code:e,data:r}=await m.post("/api-mall-portal/cart/add",{data:o});e===200&&(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:r.id}}),G())}catch{}},async getProductAddCartCount(t,s=!1){if(t=t||this.selectItem.id,this.totalData.hasOwnProperty(t)&&!s){this.setProductStock(this.totalData[t]);return}if(!!t)try{let o=await m.get(`/api-mall-portal/product/cart/${t}`);this.setProductStock(o.data||0),this.totalData[t]=o.data||0}catch{}},setProductStock(t){for(let s=0;s<this.skuStockList.length;s++)this.skuStockList[s].id===this.radio&&(this.skuStockList[s].cartNum=t)}},render(){return i("div",{class:a.addGoodsCart},[i(c,{titleStyle:{paddingLeft:"12px"}},{icon:()=>i("div",{class:a.goodsSection},[i(f,{src:this.selectItem.pic,class:a.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&i("div",{class:a.sellOut},[i(f,{src:A,fit:"cover",class:a.sellOutImg},null)])]),title:()=>i("div",{class:a.goodsInfo},[i("p",{class:a.goodsPrice},[i("span",null,[l("\uFFE5")]),C(this.selectItem.price)]),i("p",{class:a.goodsStore},[l("\u5E93\u5B58\uFF1A"),this.selectItem.stock])])}),i(c,null,{title:()=>i("div",{class:a.title},[l("\u89C4\u683C")]),label:()=>{let t;return i(j,{class:a["radio-group"],modelValue:this.radio},B(t=this.skuStockList.map(s=>{const o=s.id===this.radio,e=o?"primary":"default";return i(v,{class:a.radio,name:s.id,onClick:()=>{this.radio!=s.id&&(this.radio=s.id)}},{default:()=>[i(L,{size:"large",plain:o,type:e},{default:()=>[s.spDataJson]})]})}))?t:{default:()=>[t]})}}),i(c,{title:"\u8D2D\u4E70\u6570\u91CF",style:{margin:"12px 0"},border:!1,titleClass:a.title,center:!0},{default:()=>[i(D,{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)]}),i("div",{class:["btnGroup"],style:{marginBottom:"8px"}},[i(w,{block:!0,round:!0,type:"primary",text:"\u786E\u5B9A",disabled:this.selectItem.stock<=0,onClick:()=>this.onAddCart()},null)])])}});export{Q as A};
|