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

2 lines
3.0 KiB
JavaScript

"use strict";const e=require("../../../common/vendor.js"),o=require("../../index.js"),t=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 r={__name:"s-select-seckill-sku",props:{modelValue:{type:Object,default(){}},show:{type:Boolean,default:!1},singleLimitCount:{type:Number,default:1}},emits:["change","addCart","buy","close"],setup(r,{emit:s}){const n=s,u=r,c=e.reactive({goodsInfo:e.computed((()=>u.modelValue)),selectedSku:{},currentPropertyArray:[]}),d=t.convertProductPropertyList(c.goodsInfo.skus),a=e.computed((()=>{const e=c.goodsInfo.skus;for(const o of e)o.value_id_array=o.properties.map((e=>e.valueId));return e}));c.goodsInfo.is_sku||(c.selectedSku=c.goodsInfo.skus[0]),e.watch((()=>c.selectedSku),(e=>{n("change",e)}),{immediate:!0,deep:!0});const i=()=>{c.selectedSku.id?c.selectedSku.stock<=0?o.sheep.$helper.toast("库存不足"):n("buy",c.selectedSku):o.sheep.$helper.toast("请选择规格")};const l=(e=!1,o=0,t=0)=>{let r=[];if(e)for(const u of a.value)u.stock<=0||u.value_id_array.indexOf(t)>=0&&r.push(u);else r=p();let s=[];for(const u of r)s=s.concat(u.value_id_array);if(s=Array.from(new Set(s)),e){const e=s.indexOf(t);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},p=()=>{const e=[];for(const o of a.value){if(o.stock<=0)continue;let t=!0;c.currentPropertyArray.forEach((e=>{""!==e.toString()&&o.value_id_array.indexOf(e)<0&&(t=!1)})),t&&e.push(o)}return e};return l(!1),(s,u)=>({a:e.unref(o.sheep).$url.cdn(c.selectedSku.picUrl||c.goodsInfo.picUrl),b:e.t(c.goodsInfo.name),c:e.t(e.unref(t.fen2yuan)(c.selectedSku.price||c.goodsInfo.price)),d:e.t(c.selectedSku.stock||c.goodsInfo.stock),e:e.f(e.unref(d),((o,t,r)=>({a:e.t(o.name),b:e.f(o.values,((t,r,s)=>({a:e.t(t.name),b:e.n({"checked-btn":c.currentPropertyArray[o.id]===t.id}),c:e.n({"disabled-btn":!0===t.disabled}),d:t.id,e:!0===t.disabled,f:e.o((e=>((e,o)=>{let t=!0;void 0!==c.currentPropertyArray[e]&&c.currentPropertyArray[e]===o?(t=!1,c.currentPropertyArray.splice(e,1,"")):c.currentPropertyArray[e]=o;const r=[];c.currentPropertyArray.forEach((e=>{""!==e&&r.push(e)}));const s=p();r.length===d.length&&s.length?(s[0].count=c.selectedSku.count||1,c.selectedSku=s[0]):c.selectedSku={},l(t,e,o)})(o.id,t.id)),t.id)}))),c:o.id}))),f:e.o((e=>{var o;(o=e)>0&&c.selectedSku.count!==o&&(c.selectedSku.count=o)})),g:e.o((e=>c.selectedSku.count=e)),h:e.p({min:1,max:e.unref(e.min)([r.singleLimitCount,c.selectedSku.stock]),step:1,activity:"seckill",modelValue:c.selectedSku.count}),i:e.o(i),j:e.o((e=>n("close"))),k:e.p({show:r.show,round:"10"})})}},s=e._export_sfc(r,[["__scopeId","data-v-fecdb027"]]);wx.createComponent(s);