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

2 lines
3.0 KiB
JavaScript
Raw Normal View History

2024-10-01 09:15:35 +08:00
"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,c=r,u=e.reactive({goodsInfo:e.computed((()=>c.modelValue)),selectedSku:{},currentPropertyArray:[]}),d=t.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}));u.goodsInfo.is_sku||(u.selectedSku=u.goodsInfo.skus[0]),e.watch((()=>u.selectedSku),(e=>{n("change",e)}),{immediate:!0,deep:!0});const i=()=>{u.selectedSku.id?u.selectedSku.stock<=0?o.sheep.$helper.toast("库存不足"):n("buy",u.selectedSku):o.sheep.$helper.toast("请选择规格")};const l=(e=!1,o=0,t=0)=>{let r=[];if(e)for(const c of a.value)c.stock<=0||c.value_id_array.indexOf(t)>=0&&r.push(c);else r=p();let s=[];for(const c of r)s=s.concat(c.value_id_array);if(s=Array.from(new Set(s)),e){const e=s.indexOf(t);s.splice(e,1)}else u.currentPropertyArray.forEach((e=>{if(""!==e.toString())return;const o=s.indexOf(e);o>=0&&s.splice(o,1)}));let n=[];e?n=[o]:u.currentPropertyArray.forEach(((e,o)=>{""!==e&&n.push(o)}));for(const c in d)if(!(n.indexOf(d[c].id)>=0))for(const e in d[c].values)d[c].values[e].disabled=s.indexOf(d[c].values[e].id)<0},p=()=>{const e=[];for(const o of a.value){if(o.stock<=0)continue;let t=!0;u.currentPropertyArray.forEach((e=>{""!==e.toString()&&o.value_id_array.indexOf(e)<0&&(t=!1)})),t&&e.push(o)}return e};return l(!1),(s,c)=>({a:e.unref(o.sheep).$url.cdn(u.selectedSku.picUrl||u.goodsInfo.picUrl),b:e.t(u.goodsInfo.name),c:e.t(e.unref(t.fen2yuan)(u.selectedSku.price||u.goodsInfo.price)),d:e.t(u.selectedSku.stock||u.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":u.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!==u.currentPropertyArray[e]&&u.currentPropertyArray[e]===o?(t=!1,u.currentPropertyArray.splice(e,1,"")):u.currentPropertyArray[e]=o;const r=[];u.currentPropertyArray.forEach((e=>{""!==e&&r.push(e)}));const s=p();r.length===d.length&&s.length?(s[0].count=u.selectedSku.count||1,u.selectedSku=s[0]):u.selectedSku={},l(t,e,o)})(o.id,t.id)),t.id)}))),c:o.id}))),f:e.o((e=>{var o;(o=e)>0&&u.selectedSku.count!==o&&(u.selectedSku.count=o)})),g:e.o((e=>u.selectedSku.count=e)),h:e.p({min:1,max:e.unref(e.min)([r.singleLimitCount,u.selectedSku.stock]),step:1,activity:"seckill",modelValue:u.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-4cc43c0d"]]);wx.createComponent(s);