JewelryMall/miniprogram/unpackage/dist/dev/mp-weixin/pages/calculator/index.js

145 lines
5.2 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const common_assets = require("../../common/assets.js");
const utils_calculator = require("../../utils/calculator.js");
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "index",
setup(__props) {
const statusBarHeight = common_vendor.ref(20);
const navBarHeight = common_vendor.ref(44);
try {
const sysInfo = common_vendor.index.getSystemInfoSync();
statusBarHeight.value = sysInfo.statusBarHeight || 20;
const menuBtn = common_vendor.index.getMenuButtonBoundingClientRect();
navBarHeight.value = (menuBtn.top - (sysInfo.statusBarHeight || 20)) * 2 + menuBtn.height;
} catch {
}
function goBack() {
common_vendor.index.navigateBack({ delta: 1 });
}
const basicFields = [
{ key: "goldWeight", label: "金重", unit: "g" },
{ key: "mainStoneWeight", label: "主石重", unit: "ct" },
{ key: "sideStoneWeight", label: "副石重", unit: "ct" },
{ key: "lossRate", label: "损耗", unit: "倍率" },
{ key: "moldGoldPrice", label: "倒模金价", unit: "元" }
];
const feeFields = [
{ key: "mainStoneUnitPrice", label: "主石单价", unit: "元" },
{ key: "sideStoneUnitPrice", label: "副石单价", unit: "元" },
{ key: "sideStoneCount", label: "副石粒数", unit: "p" },
{ key: "microSettingFee", label: "微镶费", unit: "元/粒" },
{ key: "mainStoneSettingFee", label: "主石镶费", unit: "元" },
{ key: "threeDFee", label: "3D起板费", unit: "元" },
{ key: "basicLaborCost", label: "基本工费", unit: "元" },
{ key: "otherCost", label: "其他费用", unit: "元" }
];
const form = common_vendor.reactive({
goldWeight: 0,
mainStoneWeight: 0,
sideStoneWeight: 0,
lossRate: 1,
moldGoldPrice: 0,
mainStoneUnitPrice: 0,
sideStoneUnitPrice: 0,
sideStoneCount: 0,
microSettingFee: 0,
mainStoneSettingFee: 0,
threeDFee: 0,
basicLaborCost: 0,
otherCost: 0
});
const errors = common_vendor.reactive({});
function onInput(key, event) {
const raw = event.detail.value;
const num = Number(raw);
if (raw === "" || raw === "-") {
form[key] = 0;
delete errors[key];
return;
}
if (isNaN(num)) {
errors[key] = "请输入有效数字";
return;
}
if (num < 0) {
errors[key] = "不能为负数";
return;
}
delete errors[key];
form[key] = num;
}
const result = common_vendor.computed(() => {
const hasErrors = Object.keys(errors).length > 0;
if (hasErrors)
return null;
try {
return utils_calculator.calculateRing({ ...form });
} catch {
return null;
}
});
const resultRows = common_vendor.computed(() => {
const r = result.value;
if (!r)
return [];
return [
{ label: "净金重", value: r.netGoldWeight.toFixed(4) + " g" },
{ label: "含耗重", value: r.weightWithLoss.toFixed(4) + " g" },
{ label: "金值", value: "¥" + r.goldValue.toFixed(2) },
{ label: "主石总价", value: "¥" + r.mainStoneTotal.toFixed(2) },
{ label: "副石总价", value: "¥" + r.sideStoneTotal.toFixed(2) },
{ label: "微镶总价", value: "¥" + r.microSettingTotal.toFixed(2) },
{ label: "总价", value: "¥" + r.totalPrice.toFixed(2) }
];
});
return (_ctx, _cache) => {
return {
a: common_assets._imports_0$2,
b: common_vendor.o(goBack),
c: navBarHeight.value + "px",
d: statusBarHeight.value + "px",
e: statusBarHeight.value + navBarHeight.value + "px",
f: common_vendor.f(basicFields, (field, k0, i0) => {
return common_vendor.e({
a: common_vendor.t(field.label),
b: common_vendor.t(field.unit),
c: "请输入" + field.label,
d: String(form[field.key]),
e: common_vendor.o(($event) => onInput(field.key, $event), field.key),
f: errors[field.key]
}, errors[field.key] ? {
g: common_vendor.t(errors[field.key])
} : {}, {
h: field.key
});
}),
g: common_vendor.f(feeFields, (field, k0, i0) => {
return common_vendor.e({
a: common_vendor.t(field.label),
b: common_vendor.t(field.unit),
c: "请输入" + field.label,
d: String(form[field.key]),
e: common_vendor.o(($event) => onInput(field.key, $event), field.key),
f: errors[field.key]
}, errors[field.key] ? {
g: common_vendor.t(errors[field.key])
} : {}, {
h: field.key
});
}),
h: common_vendor.f(resultRows.value, (r, k0, i0) => {
return {
a: common_vendor.t(r.label),
b: common_vendor.t(r.value),
c: r.label
};
})
};
};
}
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-0b43ee93"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/calculator/index.js.map