1 |
- import{d as m,bf as h,a as e,A as r,P as f,C as k,a2 as g}from"./index-5e5e4ebc.js";import{u as S}from"./student-register-store-64ec444b.js";import{C as c}from"./index-4bcfa431.js";import{I as u}from"./index-fa23aaeb.js";import{R as _,a as y}from"./index-cb21536d.js";import{T as I}from"./index-cc5b42dd.js";import{S as C}from"./index-8338d355.js";const b=""+new URL("icon-sell-out-437e8d6c.png",import.meta.url).href,L="_addGoodsCart_16cde_1",D="_addCartBtn_16cde_25",O="_goodsSection_16cde_33",N="_sellOut_16cde_40",v="_goodsImg_16cde_52",x="_goodsPrice_16cde_58",A="_goodsStore_16cde_67",B="_title_16cde_72",G="_radio_16cde_77",a={addGoodsCart:L,addCartBtn:D,goodsSection:O,sellOut:N,goodsImg:v,goodsPrice:x,goodsStore:A,title:B,"radio-group":"_radio-group_16cde_77",radio:G};function R(t){return typeof t=="function"||Object.prototype.toString.call(t)==="[object Object]"&&!g(t)}const n=S(),q=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;n.getGoods.forEach(d=>{d.productId===i.productId&&d.productSkuId===i.productSkuId&&(s=!0,d.quantity+=i.quantity)}),s||n.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(u,{src:this.selectItem.pic,class:a.goodsImg,fit:"cover"},null),this.selectItem.stock<=0&&e("div",{class:a.sellOut},[e(u,{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},R(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{q as A,b as i};
|