acdr-ui/dist/build/mp-weixin/sheep/components/s-select-sku/s-select-sku.js

2 lines
3.0 KiB
JavaScript

"use strict";const e=require("../../../common/vendor.js"),o=require("../../index.js"),r=require("../../hooks/useGoods.js");if(!Array){(e.resolveComponent("su-number-box")+e.resolveComponent("su-popup"))()}Math||((()=>"../../ui/su-number-box/su-number-box.js")+(()=>"../../ui/su-popup/su-popup.js"))();const t={__name:"s-select-sku",props:{goodsInfo:{type:Object,default(){}},show:{type:Boolean,default:!1}},emits:["change","addCart","buy","close"],setup(t,{emit:s}){const n=s,u=t,c=e.reactive({selectedSku:{},currentPropertyArray:[]}),d=r.convertProductPropertyList(u.goodsInfo.skus),a=e.computed((()=>{const e=u.goodsInfo.skus;for(const o of e)o.value_id_array=o.properties.map((e=>e.valueId));return e}));function i(){c.selectedSku.id<=0?o.sheep.$helper.toast("请选择规格"):c.selectedSku.stock<=0?o.sheep.$helper.toast("库存不足"):n("addCart",c.selectedSku)}function l(){c.selectedSku.id<=0?o.sheep.$helper.toast("请选择规格"):c.selectedSku.stock<=0?o.sheep.$helper.toast("库存不足"):n("buy",c.selectedSku)}function p(e=!1,o=0,r=0){let t=[];if(e)for(const u of a.value)u.stock<=0||u.value_id_array.indexOf(r)>=0&&t.push(u);else t=f();let s=[];for(const u of t)s=s.concat(u.value_id_array);if(s=Array.from(new Set(s)),e){const e=s.indexOf(r);s.splice(e,1)}else c.currentPropertyArray.forEach((e=>{if(""!==e.toString())return;const o=s.indexOf(e);o>=0&&s.splice(o,1)}));let n=[];e?n=[o]:c.currentPropertyArray.forEach(((e,o)=>{""!==e&&n.push(o)}));for(const u in d)if(!(n.indexOf(d[u].id)>=0))for(const e in d[u].values)d[u].values[e].disabled=s.indexOf(d[u].values[e].id)<0}function f(){const e=[];for(const o of a.value){if(o.stock<=0)continue;let r=!0;c.currentPropertyArray.forEach((e=>{""!==e.toString()&&o.value_id_array.indexOf(e)<0&&(r=!1)})),r&&e.push(o)}return e}return e.watch((()=>c.selectedSku),(e=>{n("change",e)}),{immediate:!0,deep:!0}),p(!1),(o,s)=>({a:c.selectedSku.picUrl||t.goodsInfo.picUrl,b:e.t(t.goodsInfo.name),c:e.t(e.unref(r.fen2yuan)(c.selectedSku.price||t.goodsInfo.price)),d:e.t(e.unref(r.formatStock)("exact",c.selectedSku.stock||t.goodsInfo.stock)),e:e.f(e.unref(d),((o,r,t)=>({a:e.t(o.name),b:e.f(o.values,((r,t,s)=>({a:e.t(r.name),b:e.n({"ui-BG-Main-Gradient":c.currentPropertyArray[o.id]===r.id}),c:e.n({"disabled-btn":!0===r.disabled}),d:r.id,e:!0===r.disabled,f:e.o((e=>function(e,o){let r=!0;void 0!==c.currentPropertyArray[e]&&c.currentPropertyArray[e]===o?(r=!1,c.currentPropertyArray.splice(e,1,"")):c.currentPropertyArray[e]=o;const t=[];c.currentPropertyArray.forEach((e=>{""!==e&&t.push(e)}));const s=f();t.length===d.length&&s.length?(s[0].goods_num=c.selectedSku.goods_num||1,c.selectedSku=s[0]):c.selectedSku={},p(r,e,o)}(o.id,r.id)),r.id)}))),c:o.id}))),f:e.o((e=>{var o;0!==(o=e)&&c.selectedSku.goods_num!==o&&(c.selectedSku.goods_num=o)})),g:e.o((e=>c.selectedSku.goods_num=e)),h:e.p({min:1,max:c.selectedSku.stock,step:1,modelValue:c.selectedSku.goods_num}),i:e.o((()=>{})),j:e.o(i),k:e.o(l),l:e.o((e=>n("close"))),m:e.p({show:t.show,round:"10"})})}},s=e._export_sfc(t,[["__scopeId","data-v-59ce5475"]]);wx.createComponent(s);