From c6d13e58d85fbaaceb49d4c24401b50143050173 Mon Sep 17 00:00:00 2001 From: zhang_12370 <z2864490065@outlook.com> Date: 星期四, 26 六月 2025 18:01:24 +0800 Subject: [PATCH] 调整 基础管理煤种生产人 更改采购数计算逻辑 处理供应商数据回显问题 --- src/views/procureMent/components/ProductionDialog.vue | 141 ++++++++++++++++++++--------------------------- 1 files changed, 60 insertions(+), 81 deletions(-) diff --git a/src/views/procureMent/components/ProductionDialog.vue b/src/views/procureMent/components/ProductionDialog.vue index 014bf2a..3fc0c99 100644 --- a/src/views/procureMent/components/ProductionDialog.vue +++ b/src/views/procureMent/components/ProductionDialog.vue @@ -50,10 +50,10 @@ </template> </el-input> </el-form-item> - <el-form-item label="鍗曚环(涓嶅惈绋�)" prop="priceExcludingTax"> + <el-form-item label="鍗曚环(鍚◣)" prop="priceIncludingTax"> <el-input - v-model.number="form.priceExcludingTax" - placeholder="璇疯緭鍏�" + v-model.number="form.priceIncludingTax" + placeholder="璇疯緭鍏ュ惈绋庡崟浠�" @blur="handlePriceBlur" :disabled="isViewMode" > @@ -62,9 +62,9 @@ </template> </el-input> </el-form-item> - <el-form-item label="鍗曚环(鍚◣)" prop="priceIncludingTax"> + <el-form-item label="鍗曚环(涓嶅惈绋�)" prop="priceExcludingTax"> <el-input - v-model.number="form.priceIncludingTax" + v-model.number="form.priceExcludingTax" placeholder="鑷姩璁$畻" disabled > @@ -180,116 +180,95 @@ defineExpose({ getDropdownData, }); +// 鏁板�兼牸寮忓寲宸ュ叿鍑芥暟 const toFixed = (num, precision = 2) => { if (isNaN(num) || num === null || num === undefined || num === "") { return 0; } - return ( - Math.floor(parseFloat(num) * Math.pow(10, precision)) / - Math.pow(10, precision) - ); + return Number((Math.floor(parseFloat(num) * Math.pow(10, precision)) / Math.pow(10, precision)).toFixed(precision)); }; -// 鍚◣鍗曚环璁$畻 -const unitPriceWithTax = computed(() => { - const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0; - const taxRate = parseFloat(form.value.taxRate) || 0; - if (!priceExcludingTax || !taxRate) { - return 0; - } - const result = priceExcludingTax * (1 + taxRate / 100); - return toFixed(result, 2); -}); -// 鍚◣鎬讳环璁$畻 -const totalUnitPriceWithTax = computed(() => { - const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0; - const taxRate = parseFloat(form.value.taxRate) || 0; - const purchaseQuantity = parseFloat(form.value.purchaseQuantity) || 0; +// 瀹夊叏鑾峰彇鏁板�� +const safeNumber = (value) => { + const num = parseFloat(value); + return isNaN(num) ? 0 : num; +}; - if (!priceExcludingTax || !taxRate || !purchaseQuantity) { - return 0; - } +// 璁$畻閫昏緫 - 鍩轰簬鍚◣鍗曚环璁$畻涓嶅惈绋庝环鏍� +const calculatePrices = () => { + const priceIncludingTax = safeNumber(form.value.priceIncludingTax); // 鍚◣鍗曚环 + const taxRate = safeNumber(form.value.taxRate); // 绋庣巼 + const quantity = safeNumber(form.value.purchaseQuantity); // 閲囪喘鏁伴噺 - const unitPriceWithTaxValue = priceExcludingTax * (1 + taxRate / 100); - const result = unitPriceWithTaxValue * purchaseQuantity; - return toFixed(result, 2); -}); + // 1. 鏍规嵁鍚◣鍗曚环鍜岀◣鐜囪绠椾笉鍚◣鍗曚环 + // 涓嶅惈绋庡崟浠� = 鍚◣鍗曚环 / (1 + 绋庣巼/100) + const priceExcludingTax = priceIncludingTax && taxRate + ? toFixed(priceIncludingTax / (1 + taxRate / 100), 2) + : 0; -// 涓嶅惈绋庢�讳环璁$畻 -const taxExclusiveTotalPrice = computed(() => { - const purchaseQuantity = parseFloat(form.value.purchaseQuantity) || 0; - const priceExcludingTax = parseFloat(form.value.priceExcludingTax) || 0; + // 2. 璁$畻涓嶅惈绋庢�讳环 = 涓嶅惈绋庡崟浠� 脳 鏁伴噺 + const totalPriceExcludingTax = priceExcludingTax && quantity + ? toFixed(priceExcludingTax * quantity, 2) + : 0; - if (!purchaseQuantity || !priceExcludingTax) { - return 0; - } + // 3. 璁$畻鍚◣鎬讳环 = 鍚◣鍗曚环 脳 鏁伴噺 + const totalPriceIncludingTax = priceIncludingTax && quantity + ? toFixed(priceIncludingTax * quantity, 2) + : 0; - const result = purchaseQuantity * priceExcludingTax; - return toFixed(result, 2); -}); + // 鏇存柊琛ㄥ崟鏁版嵁 + form.value.priceExcludingTax = priceExcludingTax; + form.value.totalPriceExcludingTax = totalPriceExcludingTax; + form.value.totalPriceIncludingTax = totalPriceIncludingTax; +}; -// 鐩戝惉璁$畻鍊煎彉鍖栵紝鍚屾鍒� form 瀵硅薄涓� -watch(unitPriceWithTax, (newValue) => { - form.value.priceIncludingTax = newValue; -}); - -watch(totalUnitPriceWithTax, (newValue) => { - form.value.totalPriceIncludingTax = newValue; -}); - -watch(taxExclusiveTotalPrice, (newValue) => { - form.value.totalPriceExcludingTax = newValue; -}); +// 鐩戝惉琛ㄥ崟瀵硅薄鍙樺寲锛岀敤浜庡鐞嗙紪杈戞ā寮忎笅鐨勬暟鎹姞杞藉拰瀹炴椂璁$畻 +watch( + () => [form.value.priceIncludingTax, form.value.taxRate, form.value.purchaseQuantity], + () => { + // 闃叉姈澶勭悊锛岄伩鍏嶉绻佽绠� + nextTick(() => { + calculatePrices(); + }); + }, + { deep: true } +); const userStore = useUserStore(); const userInfo = ref({}); const match = () => { return userInfo.value.nickName || "鏈煡鐢ㄦ埛"; }; -// 澶勭悊绋庣巼杈撳叆妗嗗け鐒︼紝纭繚绮惧害 +// 澶勭悊绋庣巼杈撳叆妗嗗け鐒︿簨浠� const handleTaxRateBlur = () => { - if ( - form.value.taxRate !== null && - form.value.taxRate !== undefined && - form.value.taxRate !== "" - ) { + if (form.value.taxRate !== null && form.value.taxRate !== undefined && form.value.taxRate !== "") { form.value.taxRate = toFixed(parseFloat(form.value.taxRate), 2); + // watch 浼氳嚜鍔ㄨЕ鍙� calculatePrices锛屼笉闇�瑕佹墜鍔ㄨ皟鐢� } }; -// 澶勭悊涓嶅惈绋庡崟浠疯緭鍏ユ澶辩劍锛岀‘淇濈簿搴� +// 澶勭悊鍚◣鍗曚环杈撳叆妗嗗け鐒︿簨浠� const handlePriceBlur = () => { - if ( - form.value.priceExcludingTax !== null && - form.value.priceExcludingTax !== undefined && - form.value.priceExcludingTax !== "" - ) { - form.value.priceExcludingTax = toFixed( - parseFloat(form.value.priceExcludingTax), - 2 - ); + if (form.value.priceIncludingTax !== null && form.value.priceIncludingTax !== undefined && form.value.priceIncludingTax !== "") { + form.value.priceIncludingTax = toFixed(parseFloat(form.value.priceIncludingTax), 2); + // watch 浼氳嚜鍔ㄨЕ鍙� calculatePrices锛屼笉闇�瑕佹墜鍔ㄨ皟鐢� } }; -// 澶勭悊閲囪喘鏁伴噺杈撳叆妗嗗け鐒︼紝纭繚绮惧害 +// 澶勭悊閲囪喘鏁伴噺杈撳叆妗嗗け鐒︿簨浠� const handleQuantityBlur = () => { - if ( - form.value.purchaseQuantity !== null && - form.value.purchaseQuantity !== undefined && - form.value.purchaseQuantity !== "" - ) { - form.value.purchaseQuantity = toFixed( - parseFloat(form.value.purchaseQuantity), - 3 - ); // 鏁伴噺淇濈暀3浣嶅皬鏁� + if (form.value.purchaseQuantity !== null && form.value.purchaseQuantity !== undefined && form.value.purchaseQuantity !== "") { + form.value.purchaseQuantity = toFixed(parseFloat(form.value.purchaseQuantity), 3); // 鏁伴噺淇濈暀3浣嶅皬鏁� + // watch 浼氳嚜鍔ㄨЕ鍙� calculatePrices锛屼笉闇�瑕佹墜鍔ㄨ皟鐢� } }; onMounted(async () => { let res = await userStore.getInfo(); userInfo.value = res.user; - getDropdownData() - + await getDropdownData(); + // 缁勪欢鍔犺浇瀹屾垚鍚庤Е鍙戜竴娆¤绠� + calculatePrices(); }); const rules = { supplierName: [ -- Gitblit v1.9.3