45 lines
1.6 KiB
JavaScript
45 lines
1.6 KiB
JavaScript
"use strict";
|
|
function validateInput(input) {
|
|
const fields = [
|
|
["goldWeight", "金重"],
|
|
["mainStoneWeight", "主石重"],
|
|
["sideStoneWeight", "副石重"],
|
|
["lossRate", "损耗"],
|
|
["moldGoldPrice", "倒模金价"],
|
|
["mainStoneUnitPrice", "主石单价"],
|
|
["sideStoneUnitPrice", "副石单价"],
|
|
["sideStoneCount", "副石粒数"],
|
|
["microSettingFee", "微镶费"],
|
|
["mainStoneSettingFee", "主石镶费"],
|
|
["threeDFee", "3D起板费"],
|
|
["basicLaborCost", "基本工费"],
|
|
["otherCost", "其他费用"]
|
|
];
|
|
for (const [key, label] of fields) {
|
|
if (input[key] < 0) {
|
|
throw new Error(`${label}不能为负数`);
|
|
}
|
|
}
|
|
}
|
|
function calculateRing(input) {
|
|
validateInput(input);
|
|
const netGoldWeight = input.goldWeight - input.mainStoneWeight * 0.2 - input.sideStoneWeight * 0.2;
|
|
const weightWithLoss = netGoldWeight * input.lossRate;
|
|
const goldValue = weightWithLoss * input.moldGoldPrice;
|
|
const mainStoneTotal = input.mainStoneWeight * input.mainStoneUnitPrice;
|
|
const sideStoneTotal = input.sideStoneWeight * input.sideStoneUnitPrice;
|
|
const microSettingTotal = input.sideStoneCount * input.microSettingFee;
|
|
const totalPrice = goldValue + mainStoneTotal + sideStoneTotal + input.mainStoneSettingFee + microSettingTotal + input.threeDFee + input.basicLaborCost + input.otherCost;
|
|
return {
|
|
netGoldWeight,
|
|
weightWithLoss,
|
|
goldValue,
|
|
mainStoneTotal,
|
|
sideStoneTotal,
|
|
microSettingTotal,
|
|
totalPrice
|
|
};
|
|
}
|
|
exports.calculateRing = calculateRing;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/calculator.js.map
|