JewelryMall/miniprogram/unpackage/dist/dev/mp-weixin/components/SpecPanel.js
2026-02-25 01:21:16 +08:00

169 lines
6.2 KiB
JavaScript

"use strict";
const common_vendor = require("../common/vendor.js");
const api_product = require("../api/product.js");
const store_cart = require("../store/cart.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "SpecPanel",
props: {
productId: {}
},
emits: ["close"],
setup(__props, { emit: __emit }) {
const props = __props;
const emit = __emit;
const config = common_vendor.ref(null);
const loadingConfig = common_vendor.ref(false);
const loadingData = common_vendor.ref(false);
const specDataList = common_vendor.ref([]);
const selectedSpecs = common_vendor.ref(/* @__PURE__ */ new Map());
const cartStore = store_cart.useCartStore();
const selected = common_vendor.reactive({ fineness: "", mainStone: "", ringSize: "" });
function selectOption(key, item) {
selected[key] = selected[key] === item ? "" : item;
if (selected.fineness || selected.mainStone || selected.ringSize) {
querySpecData();
} else {
specDataList.value = [];
}
}
function toggleSelect(spec) {
if (selectedSpecs.value.has(spec.id)) {
selectedSpecs.value.delete(spec.id);
} else {
selectedSpecs.value.set(spec.id, spec);
}
selectedSpecs.value = new Map(selectedSpecs.value);
}
function handleAddToCart() {
if (selectedSpecs.value.size === 0)
return;
selectedSpecs.value.forEach((spec) => {
cartStore.addToCart({
id: Date.now() + spec.id,
userId: 0,
productId: props.productId,
specDataId: spec.id,
quantity: 1,
product: {},
specData: spec,
checked: true
});
});
common_vendor.index.showToast({ title: `已加入${selectedSpecs.value.size}`, icon: "success" });
selectedSpecs.value = /* @__PURE__ */ new Map();
emit("close");
}
common_vendor.onMounted(async () => {
loadingConfig.value = true;
try {
config.value = await api_product.getProductSpecs(props.productId);
} catch {
} finally {
loadingConfig.value = false;
}
});
async function querySpecData() {
loadingData.value = true;
try {
specDataList.value = await api_product.getSpecDataList(props.productId, {
fineness: selected.fineness || void 0,
mainStone: selected.mainStone || void 0,
ringSize: selected.ringSize || void 0
});
} catch {
} finally {
loadingData.value = false;
}
}
return (_ctx, _cache) => {
return common_vendor.e({
a: loadingConfig.value
}, loadingConfig.value ? {} : config.value ? common_vendor.e({
c: config.value.fineness.length
}, config.value.fineness.length ? {
d: common_vendor.f(config.value.fineness, (item, k0, i0) => {
return {
a: common_vendor.t(item),
b: item,
c: selected.fineness === item ? 1 : "",
d: common_vendor.o(($event) => selectOption("fineness", item), item)
};
})
} : {}, {
e: config.value.mainStone.length
}, config.value.mainStone.length ? {
f: common_vendor.f(config.value.mainStone, (item, k0, i0) => {
return {
a: common_vendor.t(item),
b: item,
c: selected.mainStone === item ? 1 : "",
d: common_vendor.o(($event) => selectOption("mainStone", item), item)
};
})
} : {}, {
g: config.value.ringSize.length
}, config.value.ringSize.length ? {
h: common_vendor.f(config.value.ringSize, (item, k0, i0) => {
return {
a: common_vendor.t(item),
b: item,
c: selected.ringSize === item ? 1 : "",
d: common_vendor.o(($event) => selectOption("ringSize", item), item)
};
})
} : {}) : {}, {
b: config.value,
i: loadingData.value
}, loadingData.value ? {} : specDataList.value.length ? {
k: common_vendor.f(specDataList.value, (spec, k0, i0) => {
return {
a: common_vendor.t(spec.modelName),
b: common_vendor.t(spec.fineness),
c: common_vendor.t(spec.goldPrice),
d: common_vendor.t(spec.modelName),
e: common_vendor.t(spec.goldTotalWeight),
f: common_vendor.t(spec.goldNetWeight),
g: common_vendor.t(spec.goldLoss),
h: common_vendor.t(spec.goldValue),
i: common_vendor.t(spec.mainStoneCount),
j: common_vendor.t(spec.mainStoneWeight),
k: common_vendor.t(spec.mainStoneUnitPrice),
l: common_vendor.t(spec.mainStoneAmount),
m: common_vendor.t(spec.accessoryAmount),
n: common_vendor.t(spec.totalLaborCost),
o: common_vendor.t(spec.fineness),
p: common_vendor.t(spec.loss),
q: common_vendor.t(spec.mainStone),
r: common_vendor.t(spec.ringSize),
s: common_vendor.t(spec.goldPrice),
t: common_vendor.t(spec.sideStoneCount),
v: common_vendor.t(spec.sideStoneWeight),
w: common_vendor.t(spec.sideStoneUnitPrice),
x: common_vendor.t(spec.sideStoneAmount),
y: common_vendor.t(spec.processingFee),
z: common_vendor.t(spec.settingFee),
A: common_vendor.t(spec.totalPrice),
B: spec.id,
C: selectedSpecs.value.has(spec.id) ? 1 : "",
D: common_vendor.o(($event) => toggleSelect(spec), spec.id)
};
})
} : {}, {
j: specDataList.value.length,
l: selectedSpecs.value.size
}, selectedSpecs.value.size ? {
m: common_vendor.t(selectedSpecs.value.size)
} : {}, {
n: selectedSpecs.value.size === 0 ? 1 : "",
o: common_vendor.o(handleAddToCart),
p: common_vendor.o(() => {
}),
q: common_vendor.o(($event) => _ctx.$emit("close"))
});
};
}
});
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c30573e9"]]);
wx.createComponent(Component);
//# sourceMappingURL=../../.sourcemap/mp-weixin/components/SpecPanel.js.map