From 2a8dc0db849bcafba80acda057bb554fc566dc53 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期日, 25 十月 2026 21:09:51 +0800
Subject: [PATCH] fix: 优化采购和销售金额展示
---
src/views/salesManagement/salesLedger/index.vue | 194 ++++++++++++++++++++++++++++++++----------------
1 files changed, 128 insertions(+), 66 deletions(-)
diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 5da3fd9..be991b3 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -117,7 +117,7 @@
</el-table-column>
<el-table-column label="瀹℃壒涓暟閲�" width="120" align="center">
<template #default="scope">
- <span>{{ scope.row.pendingApprovalQuantity || 0 }}</span>
+ <span>{{ formatDecimal6(scope.row.pendingApprovalQuantity) }}</span>
</template>
</el-table-column>
<el-table-column
@@ -150,9 +150,17 @@
</div>
</template>
</el-table-column>
- <el-table-column label="鏁伴噺" prop="quantity" />
- <el-table-column label="寰呭彂璐ф暟閲�" prop="noQuantity" />
- <el-table-column label="绋庣巼(%)" prop="taxRate" />
+ <el-table-column
+ label="鏁伴噺"
+ prop="quantity"
+ :formatter="formattedNumber"
+ />
+ <el-table-column label="寰呭彂璐ф暟閲�"
+ prop="noQuantity"
+ :formatter="formattedNumber" />
+ <el-table-column label="绋庣巼(%)"
+ prop="taxRate"
+ :formatter="formattedNumber" />
<el-table-column
label="鍚◣鍗曚环(鍏�)"
prop="taxInclusiveUnitPrice"
@@ -161,12 +169,12 @@
<el-table-column
label="鍚◣鎬讳环(鍏�)"
prop="taxInclusiveTotalPrice"
- :formatter="formattedAmount"
+ :formatter="formattedRawAmount"
/>
<el-table-column
label="涓嶅惈绋庢�讳环(鍏�)"
prop="taxExclusiveTotalPrice"
- :formatter="formattedAmount"
+ :formatter="formattedRawAmount"
/>
<!--鎿嶄綔-->
<el-table-column Width="60px" label="鎿嶄綔" align="center">
@@ -219,7 +227,7 @@
prop="contractAmount"
width="220"
show-overflow-tooltip
- :formatter="formattedAmount"
+ :formatter="formattedRawAmount"
/>
<el-table-column
label="褰曞叆浜�"
@@ -513,7 +521,11 @@
<el-table-column label="浜у搧澶х被" prop="productCategory" />
<el-table-column label="瑙勬牸鍨嬪彿" prop="specificationModel" />
<el-table-column label="鍗曚綅" prop="unit" />
- <el-table-column label="鏁伴噺" prop="quantity" />
+ <el-table-column
+ label="鏁伴噺"
+ prop="quantity"
+ :formatter="formattedNumber"
+ />
<el-table-column label="绋庣巼(%)" prop="taxRate" />
<el-table-column
label="鍚◣鍗曚环(鍏�)"
@@ -523,12 +535,12 @@
<el-table-column
label="鍚◣鎬讳环(鍏�)"
prop="taxInclusiveTotalPrice"
- :formatter="formattedAmount"
+ :formatter="formattedRawAmount"
/>
<el-table-column
label="涓嶅惈绋庢�讳环(鍏�)"
prop="taxExclusiveTotalPrice"
- :formatter="formattedAmount"
+ :formatter="formattedRawAmount"
/>
<el-table-column label="鏄惁鐢熶骇" prop="isProduction" width="150">
<template #default="scope">
@@ -766,7 +778,6 @@
:min="0"
v-model="productForm.taxInclusiveUnitPrice"
style="width: 100%"
- :precision="6"
placeholder="璇疯緭鍏�"
clearable
@change="calculateFromUnitPrice"
@@ -781,7 +792,6 @@
v-model="productForm.quantity"
placeholder="璇疯緭鍏�"
clearable
- :precision="6"
@change="calculateFromQuantity"
style="width: 100%"
/>
@@ -959,10 +969,10 @@
<td>{{ product.productCategory || "" }}</td>
<td>{{ product.specificationModel || "" }}</td>
<td>{{ product.unit || "" }}</td>
- <td>{{ trimZeros(product.taxInclusiveUnitPrice, 6) }}</td>
- <td>{{ trimZeros(product.quantity, 6) }}</td>
+ <td>{{ formatDecimal6(product.taxInclusiveUnitPrice) }}</td>
+ <td>{{ formatDecimal6(product.quantity) }}</td>
<td>
- {{ formatAmount(product.taxInclusiveTotalPrice) }}
+ {{ formatDecimal6(product.taxInclusiveTotalPrice) }}
</td>
</tr>
<tr v-if="!item.products || item.products.length === 0">
@@ -1051,7 +1061,7 @@
<el-col :span="24">
<el-form-item label="寰呭彂璐ф暟閲忥細">
<el-input
- :model-value="currentDeliveryRow?.noQuantity"
+ :model-value="formatDecimal6(currentDeliveryRow?.noQuantity)"
disabled
/>
</el-form-item>
@@ -1123,7 +1133,7 @@
align="center"
>
<template #default="scope">
- {{ getDeliveryBatchQuantity(scope.row) }}
+ {{ formatDecimal6(getDeliveryBatchQuantity(scope.row)) }}
</template>
</el-table-column>
<el-table-column
@@ -1190,7 +1200,7 @@
import FileUpload from "@/components/AttachmentUpload/file/index.vue";
import ImageUpload from "@/components/AttachmentUpload/image/index.vue";
import { getCurrentDate } from "@/utils/index.js";
-import { roundHalfUp, trimZeros } from "@/utils/formatNumber.js";
+import { formatDecimal6, roundHalfUp } from "@/utils/formatNumber.js";
import { listCustomer } from "@/api/basicData/customer.js";
const FileList = defineAsyncComponent(() =>
@@ -1534,15 +1544,35 @@
});
};
const formattedNumber = (row, column, cellValue) => {
- return trimZeros(cellValue, 6);
+ return formatDecimal6(cellValue);
};
-// 閲戦鏄剧ず鏍煎紡鍖栵細鎸夊崄杩涘埗鍥涜垗浜斿叆鍒� 2 浣嶅皬鏁帮紙涓庢暟鎹簱 ROUND 涓�鑷达級锛屽啀鍘绘帀鏈熬澶氫綑鐨� 0
+// 鎶ヤ环閲戦鏄剧ず锛氭寜鍗佽繘鍒跺洓鑸嶄簲鍏ュ埌 2 浣嶅皬鏁帮紙涓庢暟鎹簱 ROUND 涓�鑷达級锛屽啀鍘绘帀鏈熬澶氫綑鐨� 0
const formatAmount = (value) => {
- return trimZeros(roundHalfUp(value, 2), 2);
+ return formatDecimal6(roundHalfUp(value, 2));
};
-// 閲戦鍒楃殑琛ㄦ牸鏍煎紡鍖栧嚱鏁帮紙鍗曚环鍒椾粛鐢� formattedNumber 淇濈暀 6 浣嶅皬鏁帮級
-const formattedAmount = (row, column, cellValue) => {
- return formatAmount(cellValue);
+// 閲戦鍒楁樉绀猴細鏈�澶氫繚鐣� 6 浣嶅皬鏁帮紝瓒呰繃 6 浣嶇殑鎸夊崄杩涘埗鍥涜垗浜斿叆
+const formattedRawAmount = (row, column, cellValue) => {
+ return formatDecimal6(cellValue);
+};
+// 鎶婇噾棰濊绠楃粨鏋滆浆鎴愩�岃緭鍏ュ嚑浣嶅氨鍑犱綅銆嶇殑鏁板瓧锛堟渶澶� 6 浣嶅皬鏁帮紝瓒呭嚭鍥涜垗浜斿叆锛�
+const toDisplayNumber = (value) => {
+ const num = Number(formatDecimal6(value));
+ return Number.isFinite(num) ? num : 0;
+};
+// 浜у搧寮圭獥鍗曚釜鏁板�煎瓧娈靛綊涓�鍖栵細杈撳叆瓒呰繃 6 浣嶅皬鏁版椂鍥涜垗浜斿叆鍒� 6 浣�
+const normalizeProductNumber = (key) => {
+ const val = productForm.value[key];
+ if (val === null || val === undefined || val === "") return;
+ productForm.value[key] = toDisplayNumber(val);
+};
+// 浜у搧寮圭獥鍙備笌鑱斿姩璁$畻鐨勬暟鍊煎瓧娈电粺涓�褰掍竴鍖�
+const normalizeProductNumbers = () => {
+ [
+ "quantity",
+ "taxInclusiveUnitPrice",
+ "taxInclusiveTotalPrice",
+ "taxExclusiveTotalPrice",
+ ].forEach(normalizeProductNumber);
};
const findLedgerRecordByRow = (row) => {
if (!row) return null;
@@ -1702,10 +1732,10 @@
param,
["contractAmount", "taxInclusiveTotalPrice", "taxExclusiveTotalPrice"],
{
- // 閲戦鍒楋細姣忚鍏堟寜 2 浣嶅皬鏁板洓鑸嶄簲鍏ュ啀姹傚拰锛屼繚璇佸悎璁′笌鍒楀唴灞曠ず鍊间竴鑷�
- contractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
- taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
- taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
+ // 閲戦鍒楀悎璁″悗鏈�澶氫繚鐣� 6 浣嶅皬鏁帮紝瓒呰繃 6 浣嶆寜鍗佽繘鍒跺洓鑸嶄簲鍏�
+ contractAmount: { formatter: formatDecimal6 },
+ taxInclusiveTotalPrice: { formatter: formatDecimal6 },
+ taxExclusiveTotalPrice: { formatter: formatDecimal6 },
}
);
};
@@ -1719,10 +1749,10 @@
"taxExclusiveTotalPrice",
],
{
- taxInclusiveUnitPrice: { decimalPlaces: 6, trimZeros: true },
- // 閲戦鍒楋細姣忚鍏堟寜 2 浣嶅皬鏁板洓鑸嶄簲鍏ュ啀姹傚拰锛屼繚璇佸悎璁′笌鍒楀唴灞曠ず鍊间竴鑷�
- taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
- taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
+ taxInclusiveUnitPrice: { formatter: formatDecimal6 },
+ // 閲戦鍒楀悎璁″悗鏈�澶氫繚鐣� 6 浣嶅皬鏁帮紝瓒呰繃 6 浣嶆寜鍗佽繘鍒跺洓鑸嶄簲鍏�
+ taxInclusiveTotalPrice: { formatter: formatDecimal6 },
+ taxExclusiveTotalPrice: { formatter: formatDecimal6 },
}
);
};
@@ -1875,11 +1905,9 @@
const quantity = Number(p.quantity ?? 0) || 0;
const unitPrice = Number(p.unitPrice ?? 0) || 0;
const taxRate = "13"; // 榛樿 13%锛屼究浜庣洿鎺ユ彁浜わ紙濡傞渶鍙湪浜у搧涓嚜琛屼慨鏀癸級
- const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6);
- const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice(
- taxInclusiveTotalPrice,
- taxRate,
- 6
+ const taxInclusiveTotalPrice = toDisplayNumber(unitPrice * quantity);
+ const taxExclusiveTotalPrice = toDisplayNumber(
+ proxy.calculateTaxExclusiveTotalPrice(taxInclusiveTotalPrice, taxRate, 6)
);
return {
// 鍙拌处瀛楁
@@ -1888,7 +1916,7 @@
unit: p.unit || "",
quantity: quantity,
taxRate: taxRate,
- taxInclusiveUnitPrice: unitPrice.toFixed(6),
+ taxInclusiveUnitPrice: toDisplayNumber(unitPrice),
taxInclusiveTotalPrice: taxInclusiveTotalPrice,
taxExclusiveTotalPrice: taxExclusiveTotalPrice,
invoiceType: "澧炴櫘绁�",
@@ -1953,6 +1981,17 @@
proxy.resetForm("productFormRef");
if (type === "edit") {
productForm.value = { ...row };
+ // 鍥炲~鏃舵妸閲戦/鏁伴噺缁熶竴鎴愭暟瀛楋紝閬垮厤 "5000.000000" 杩欑被琛ラ浂瀛楃涓茬洿鎺ヨ繘杈撳叆妗�
+ [
+ "quantity",
+ "taxInclusiveUnitPrice",
+ "taxInclusiveTotalPrice",
+ "taxExclusiveTotalPrice",
+ ].forEach((key) => {
+ const val = productForm.value[key];
+ if (val === null || val === undefined || val === "") return;
+ productForm.value[key] = toDisplayNumber(val);
+ });
productIndex.value = index;
// 缂栬緫鏃舵牴鎹骇鍝佸ぇ绫诲悕绉板弽鏌� tree 鑺傜偣 id锛屽苟鍔犺浇瑙勬牸鍨嬪彿鍒楄〃
try {
@@ -1988,6 +2027,8 @@
const submitProduct = () => {
proxy.$refs["productFormRef"].validate((valid) => {
if (valid) {
+ // 鎻愪氦鍓嶇粺涓�鎶婃暟鍊兼敹鏁涘埌鏈�澶� 6 浣嶅皬鏁帮紙瓒呭嚭鍥涜垗浜斿叆锛�
+ normalizeProductNumbers();
if (operationType.value === "edit") {
submitProductEdit();
} else {
@@ -2454,16 +2495,19 @@
""
}</td>
<td>${
- product.taxInclusiveUnitPrice ||
- "0"
+ formatDecimal6(
+ product.taxInclusiveUnitPrice
+ )
}</td>
<td>${
- product.quantity ||
- "0"
+ formatDecimal6(
+ product.quantity
+ )
}</td>
<td>${
- product.taxInclusiveTotalPrice ||
- "0"
+ formatDecimal6(
+ product.taxInclusiveTotalPrice
+ )
}</td>
</tr>
`
@@ -2566,7 +2610,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.quantity) || 0);
}, 0);
- return trimZeros(total, 6);
+ return formatDecimal6(total);
};
// 璁$畻浜у搧鎬婚噾棰�
@@ -2575,7 +2619,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
}, 0);
- return formatAmount(total);
+ return formatDecimal6(total);
};
// 鐢ㄤ簬鎵撳嵃鐨勮绠楀嚱鏁�
@@ -2584,7 +2628,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.quantity) || 0);
}, 0);
- return trimZeros(total, 6);
+ return formatDecimal6(total);
};
const getTotalAmountForPrint = (products) => {
@@ -2592,11 +2636,12 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
}, 0);
- return formatAmount(total);
+ return formatDecimal6(total);
};
const mathNum = () => {
console.log("productForm.value", productForm.value);
+ normalizeProductNumbers();
if (!productForm.value.taxInclusiveUnitPrice) {
return;
}
@@ -2604,25 +2649,28 @@
return;
}
// 鍚◣鎬讳环璁$畻
- productForm.value.taxInclusiveTotalPrice =
+ productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
proxy.calculateTaxIncludeTotalPrice(
productForm.value.taxInclusiveUnitPrice,
productForm.value.quantity,
6
- );
+ )
+ );
if (productForm.value.taxRate) {
// 涓嶅惈绋庢�讳环璁$畻
- productForm.value.taxExclusiveTotalPrice =
+ productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
proxy.calculateTaxExclusiveTotalPrice(
productForm.value.taxInclusiveTotalPrice,
productForm.value.taxRate,
6
- );
+ )
+ );
}
};
// 鏍规嵁鍚◣鎬讳环璁$畻鍚◣鍗曚环鍜屾暟閲�
const calculateFromTotalPrice = () => {
+ normalizeProductNumbers();
if (isCalculating.value) return;
const totalPrice = parseFloat(productForm.value.taxInclusiveTotalPrice);
@@ -2635,16 +2683,19 @@
isCalculating.value = true;
// 璁$畻鍚◣鍗曚环 = 鍚◣鎬讳环 / 鏁伴噺
- productForm.value.taxInclusiveUnitPrice = (totalPrice / quantity).toFixed(6);
+ productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
+ totalPrice / quantity
+ );
// 濡傛灉鏈夌◣鐜囷紝璁$畻涓嶅惈绋庢�讳环
if (productForm.value.taxRate) {
- productForm.value.taxExclusiveTotalPrice =
+ productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
proxy.calculateTaxExclusiveTotalPrice(
totalPrice,
productForm.value.taxRate,
6
- );
+ )
+ );
}
isCalculating.value = false;
@@ -2652,6 +2703,7 @@
// 鏍规嵁涓嶅惈绋庢�讳环璁$畻鍚◣鍗曚环鍜屾暟閲�
const calculateFromExclusiveTotalPrice = () => {
+ normalizeProductNumbers();
if (!productForm.value.taxRate) {
proxy.$modal.msgWarning("璇峰厛閫夋嫨绋庣巼");
return;
@@ -2673,18 +2725,19 @@
// 鍏堣绠楀惈绋庢�讳环 = 涓嶅惈绋庢�讳环 / (1 - 绋庣巼/100)
const taxRateDecimal = taxRate / 100;
const inclusiveTotalPrice = exclusiveTotalPrice / (1 - taxRateDecimal);
- productForm.value.taxInclusiveTotalPrice = inclusiveTotalPrice.toFixed(6);
+ productForm.value.taxInclusiveTotalPrice = toDisplayNumber(inclusiveTotalPrice);
// 璁$畻鍚◣鍗曚环 = 鍚◣鎬讳环 / 鏁伴噺
- productForm.value.taxInclusiveUnitPrice = (
+ productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
inclusiveTotalPrice / quantity
- ).toFixed(6);
+ );
isCalculating.value = false;
};
// 鏍规嵁鏁伴噺鍙樺寲璁$畻鎬讳环
const calculateFromQuantity = () => {
+ normalizeProductNumbers();
if (!productForm.value.taxRate) {
proxy.$modal.msgWarning("璇峰厛閫夋嫨绋庣巼");
return;
@@ -2701,16 +2754,19 @@
isCalculating.value = true;
// 璁$畻鍚◣鎬讳环
- productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6);
+ productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
+ unitPrice * quantity
+ );
// 濡傛灉鏈夌◣鐜囷紝璁$畻涓嶅惈绋庢�讳环
if (productForm.value.taxRate) {
- productForm.value.taxExclusiveTotalPrice =
+ productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
proxy.calculateTaxExclusiveTotalPrice(
productForm.value.taxInclusiveTotalPrice,
productForm.value.taxRate,
6
- );
+ )
+ );
}
isCalculating.value = false;
@@ -2718,6 +2774,7 @@
// 鏍规嵁鍚◣鍗曚环鍙樺寲璁$畻鎬讳环
const calculateFromUnitPrice = () => {
+ normalizeProductNumbers();
if (!productForm.value.taxRate) {
proxy.$modal.msgWarning("璇峰厛閫夋嫨绋庣巼");
return;
@@ -2734,16 +2791,19 @@
isCalculating.value = true;
// 璁$畻鍚◣鎬讳环
- productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6);
+ productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
+ unitPrice * quantity
+ );
// 濡傛灉鏈夌◣鐜囷紝璁$畻涓嶅惈绋庢�讳环
if (productForm.value.taxRate) {
- productForm.value.taxExclusiveTotalPrice =
+ productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
proxy.calculateTaxExclusiveTotalPrice(
productForm.value.taxInclusiveTotalPrice,
productForm.value.taxRate,
6
- );
+ )
+ );
}
isCalculating.value = false;
@@ -2751,6 +2811,7 @@
// 鏍规嵁绋庣巼鍙樺寲璁$畻涓嶅惈绋庢�讳环
const calculateFromTaxRate = () => {
+ normalizeProductNumbers();
if (!productForm.value.taxRate) {
proxy.$modal.msgWarning("璇峰厛閫夋嫨绋庣巼");
return;
@@ -2769,8 +2830,9 @@
isCalculating.value = true;
// 璁$畻涓嶅惈绋庢�讳环
- productForm.value.taxExclusiveTotalPrice =
- proxy.calculateTaxExclusiveTotalPrice(inclusiveTotalPrice, taxRate, 6);
+ productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
+ proxy.calculateTaxExclusiveTotalPrice(inclusiveTotalPrice, taxRate, 6)
+ );
isCalculating.value = false;
};
--
Gitblit v1.9.3