From 2a8dc0db849bcafba80acda057bb554fc566dc53 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期日, 25 十月 2026 21:09:51 +0800
Subject: [PATCH] fix: 优化采购和销售金额展示
---
src/views/procurementManagement/procurementLedger/index.vue | 165 ++++++++++++++--------
src/utils/formatNumber.js | 19 ++
src/views/salesManagement/salesLedger/index.vue | 194 ++++++++++++++++++---------
3 files changed, 250 insertions(+), 128 deletions(-)
diff --git a/src/utils/formatNumber.js b/src/utils/formatNumber.js
index af819be..4f94521 100644
--- a/src/utils/formatNumber.js
+++ b/src/utils/formatNumber.js
@@ -73,3 +73,22 @@
// 閬垮厤鍑虹幇 "-0.00" 杩欑被璐熼浂鏄剧ず
return parseFloat(text) === 0 ? text.replace(/^-/, "") : text;
};
+
+/**
+ * 鏈�澶氫繚鐣� 6 浣嶅皬鏁帮細瓒呰繃 6 浣嶇殑鎸夊崄杩涘埗鍥涜垗浜斿叆锛屽啀鍘绘帀鏈熬澶氫綑鐨� 0
+ * 鐢ㄤ簬閲囪喘/閿�鍞彴璐︾殑閲戦銆佹暟閲忋�佸崟浠风瓑瀛楁
+ * 渚嬶細52333.580000 -> 52333.58 锛�1.23456789 -> 1.234568 锛�0.1 + 0.2 -> 0.3
+ * @param {string|number} value 鍘熷鍊�
+ * @returns {string} 鏍煎紡鍖栧悗鐨勫瓧绗︿覆
+ */
+export const formatDecimal6 = (value) => {
+ if (value === undefined || value === null || value === "") {
+ return "0";
+ }
+ const num = typeof value === "number" ? value : Number(value);
+ // 闈炴暟瀛楋紙濡� "-"銆�"--"锛夊師鏍疯繑鍥烇紝閬垮厤鎶婂崰浣嶇鏄剧ず鎴� 0
+ if (!Number.isFinite(num)) {
+ return String(value);
+ }
+ return trimZeros(roundHalfUp(num, 6), 6);
+};
diff --git a/src/views/procurementManagement/procurementLedger/index.vue b/src/views/procurementManagement/procurementLedger/index.vue
index b28df5d..f4f3a31 100644
--- a/src/views/procurementManagement/procurementLedger/index.vue
+++ b/src/views/procurementManagement/procurementLedger/index.vue
@@ -121,13 +121,17 @@
</template>
</el-table-column>
<el-table-column label="鏁伴噺"
- prop="quantity" />
+ prop="quantity"
+ :formatter="formattedNumber" />
<el-table-column label="鍙敤鏁伴噺"
- prop="availableQuality" />
+ prop="availableQuality"
+ :formatter="formattedNumber" />
<el-table-column label="閫�璐ф暟閲�"
- prop="returnQuantity" />
+ prop="returnQuantity"
+ :formatter="formattedNumber" />
<el-table-column label="绋庣巼(%)"
- prop="taxRate" />
+ prop="taxRate"
+ :formatter="formattedNumber" />
<el-table-column label="鍚◣鍗曚环(鍏�)"
prop="taxInclusiveUnitPrice"
:formatter="formattedNumber" />
@@ -418,11 +422,13 @@
width="70" />
<el-table-column label="鏁伴噺"
prop="quantity"
- width="70" />
+ width="70"
+ :formatter="formattedNumber" />
<el-table-column label="搴撳瓨棰勮鏁伴噺"
prop="warnNum"
width="120"
- show-overflow-tooltip />
+ show-overflow-tooltip
+ :formatter="formattedNumber" />
<el-table-column label="绋庣巼(%)"
prop="taxRate"
width="80" />
@@ -599,7 +605,6 @@
<el-form-item label="鍚◣鍗曚环(鍏�)锛�"
prop="taxInclusiveUnitPrice">
<el-input-number v-model="productForm.taxInclusiveUnitPrice"
- :precision="6"
:step="0.1"
:min="0"
clearable
@@ -612,7 +617,6 @@
prop="quantity">
<el-input-number :step="0.1"
clearable
- :precision="6"
:min="0"
style="width: 100%"
v-model="productForm.quantity"
@@ -626,7 +630,6 @@
<el-form-item label="鍚◣鎬讳环(鍏�)锛�"
prop="taxInclusiveTotalPrice">
<el-input-number v-model="productForm.taxInclusiveTotalPrice"
- :precision="6"
:step="0.1"
:min="0"
clearable
@@ -638,7 +641,6 @@
<el-form-item label="涓嶅惈绋庢�讳环(鍏�)锛�"
prop="taxExclusiveTotalPrice">
<el-input-number v-model="productForm.taxExclusiveTotalPrice"
- :precision="6"
:step="0.1"
:min="0"
clearable
@@ -665,11 +667,11 @@
<el-form-item label="搴撳瓨棰勮鏁伴噺锛�"
prop="warnNum">
<el-input-number v-model="productForm.warnNum"
- :precision="6"
:step="0.1"
:min="0"
clearable
- style="width: 100%" />
+ style="width: 100%"
+ @change="normalizeProductNumber('warnNum')" />
</el-form-item>
</el-col>
</el-row>
@@ -761,7 +763,7 @@
import { modelList, productTreeList } from "@/api/basicData/product.js";
import dayjs from "dayjs";
import FileUpload from "@/components/AttachmentUpload/file/index.vue";
- import { roundHalfUp, trimZeros } from "@/utils/formatNumber.js";
+ import { formatDecimal6 } from "@/utils/formatNumber.js";
const userStore = useUserStore();
@@ -1086,15 +1088,11 @@
};
const formattedNumber = (row, column, cellValue) => {
- return trimZeros(cellValue, 6);
+ return formatDecimal6(cellValue);
};
- // 閲戦鏄剧ず鏍煎紡鍖栵細鎸夊崄杩涘埗鍥涜垗浜斿叆鍒� 2 浣嶅皬鏁帮紙涓庢暟鎹簱 ROUND 涓�鑷达級锛屽啀鍘绘帀鏈熬澶氫綑鐨� 0
- const formatAmount = value => {
- return trimZeros(roundHalfUp(value, 2), 2);
- };
- // 閲戦鍒楃殑琛ㄦ牸鏍煎紡鍖栧嚱鏁帮紙鍗曚环鍒椾粛鐢� formattedNumber 淇濈暀 6 浣嶅皬鏁帮級
+ // 閲戦鏄剧ず鏍煎紡鍖栵細鏈�澶氫繚鐣� 6 浣嶅皬鏁帮紝瓒呰繃 6 浣嶇殑鎸夊崄杩涘埗鍥涜垗浜斿叆
const formattedAmount = (row, column, cellValue) => {
- return formatAmount(cellValue);
+ return formatDecimal6(cellValue);
};
// 鏌ヨ鍒楄〃
/** 鎼滅储鎸夐挳鎿嶄綔 */
@@ -1214,10 +1212,10 @@
"futureTicketsAmount",
],
{
- 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 },
ticketsAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
futureTicketsAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
ticketsNum: { noDecimal: true }, // 涓嶄繚鐣欏皬鏁�
@@ -1289,9 +1287,9 @@
param,
["contractAmount", "netContractAmount"],
{
- // 閲戦鍒楋細姣忚鍏堟寜 2 浣嶅皬鏁板洓鑸嶄簲鍏ュ啀姹傚拰锛屼繚璇佸悎璁′笌鍒楀唴灞曠ず鍊间竴鑷�
- contractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
- netContractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true },
+ // 閲戦鍒楋細鍚堣鍚庢渶澶氫繚鐣� 6 浣嶅皬鏁帮紝瓒呰繃 6 浣嶆寜鍗佽繘鍒跺洓鑸嶄簲鍏�
+ contractAmount: { formatter: formatDecimal6 },
+ netContractAmount: { formatter: formatDecimal6 },
}
);
};
@@ -1305,10 +1303,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 },
}
);
};
@@ -1517,6 +1515,20 @@
// 澶嶅埗琛屾暟鎹�
productForm.value = { ...row };
+ // 鍚庣鏁伴噺/閲戦瀛楁鎸� 6 浣嶅皬鏁拌繑鍥烇紙濡� 10.000000锛夛紝杞垚鏅�氭暟鍊硷紝
+ // 閬垮厤杈撳叆妗嗗洖鏄惧浣欑殑 0
+ [
+ "quantity",
+ "taxInclusiveUnitPrice",
+ "taxInclusiveTotalPrice",
+ "taxExclusiveTotalPrice",
+ "warnNum",
+ ].forEach(key => {
+ const val = productForm.value[key];
+ if (val === null || val === undefined || val === "") return;
+ productForm.value[key] = toDisplayNumber(val);
+ });
+
// 濡傛灉鏄粠妯℃澘鍔犺浇鐨勬暟鎹紝鍙兘娌℃湁 productId 鍜� productModelId
// 闇�瑕佹牴鎹� productCategory 鍜� specificationModel 鏉ユ煡鎵惧搴旂殑 ID
if (!productForm.value.productId && productForm.value.productCategory) {
@@ -1645,6 +1657,8 @@
const submitProduct = () => {
proxy.$refs["productFormRef"].validate(valid => {
if (valid) {
+ // 鎻愪氦鍓嶇粺涓�鎶婃暟鍊兼敹鏁涘埌鏈�澶� 6 浣嶅皬鏁帮紙瓒呭嚭鍥涜垗浜斿叆锛�
+ normalizeProductNumbers();
if (operationType.value === "edit") {
submitProductEdit();
} else {
@@ -1803,7 +1817,33 @@
return `${year}-${month}-${day}`;
}
+ // 璁$畻缁撴灉杞垚鏁板瓧锛氭渶澶氫繚鐣� 6 浣嶅皬鏁帮紙瓒呰繃 6 浣嶇殑鍥涜垗浜斿叆锛夛紝骞跺幓鎺夋湯灏炬棤鎰忎箟鐨� 0锛�
+ // 閬垮厤鍥炲~鍒� el-input-number 鏃跺嚭鐜� 100.000000 杩欑被灞曠ず
+ 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",
+ "warnNum",
+ ].forEach(normalizeProductNumber);
+ };
+
const mathNum = () => {
+ normalizeProductNumbers();
if (!productForm.value.taxRate) {
proxy.$modal.msgWarning("璇峰厛閫夋嫨绋庣巼");
return;
@@ -1815,23 +1855,26 @@
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 reverseMathNum = field => {
+ normalizeProductNumbers();
if (!productForm.value.taxRate) {
proxy.$modal.msgWarning("璇峰厛閫夋嫨绋庣巼");
return;
@@ -1846,7 +1889,7 @@
) {
const value = Number(productForm.value[field]);
if (value < 0) {
- productForm.value[field] = "0";
+ productForm.value[field] = 0;
proxy.$modal.msgWarning("鍊间笉鑳藉皬浜�0");
return;
}
@@ -1855,65 +1898,63 @@
if (field === "taxInclusiveTotalPrice") {
// 宸茬煡鍚◣鎬讳环鍜屾暟閲忥紝鍙嶇畻鍚◣鍗曚环
if (productForm.value.quantity) {
- productForm.value.taxInclusiveUnitPrice = (
+ productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
Number(productForm.value.taxInclusiveTotalPrice) /
- Number(productForm.value.quantity)
- ).toFixed(6);
+ Number(productForm.value.quantity)
+ );
// 纭繚缁撴灉涓嶄负璐熸暟
if (Number(productForm.value.taxInclusiveUnitPrice) < 0) {
- productForm.value.taxInclusiveUnitPrice = "0";
+ productForm.value.taxInclusiveUnitPrice = 0;
}
}
// 宸茬煡鍚◣鎬讳环鍜屽惈绋庡崟浠凤紝鍙嶇畻鏁伴噺
else if (productForm.value.taxInclusiveUnitPrice) {
- productForm.value.quantity = (
+ productForm.value.quantity = toDisplayNumber(
Number(productForm.value.taxInclusiveTotalPrice) /
- Number(productForm.value.taxInclusiveUnitPrice)
- ).toFixed(6);
+ Number(productForm.value.taxInclusiveUnitPrice)
+ );
// 纭繚缁撴灉涓嶄负璐熸暟
if (Number(productForm.value.quantity) < 0) {
- productForm.value.quantity = "0";
+ productForm.value.quantity = 0;
}
}
// 鍙嶇畻涓嶅惈绋庢�讳环
- productForm.value.taxExclusiveTotalPrice = (
- Number(productForm.value.taxInclusiveTotalPrice) /
- (1 + taxRate / 100)
- ).toFixed(6);
+ productForm.value.taxExclusiveTotalPrice = toDisplayNumber(
+ Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100)
+ );
// 纭繚缁撴灉涓嶄负璐熸暟
if (Number(productForm.value.taxExclusiveTotalPrice) < 0) {
- productForm.value.taxExclusiveTotalPrice = "0";
+ productForm.value.taxExclusiveTotalPrice = 0;
}
} else if (field === "taxExclusiveTotalPrice") {
// 鍙嶇畻鍚◣鎬讳环
- productForm.value.taxInclusiveTotalPrice = (
- Number(productForm.value.taxExclusiveTotalPrice) *
- (1 + taxRate / 100)
- ).toFixed(6);
+ productForm.value.taxInclusiveTotalPrice = toDisplayNumber(
+ Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100)
+ );
// 纭繚缁撴灉涓嶄负璐熸暟
if (Number(productForm.value.taxInclusiveTotalPrice) < 0) {
- productForm.value.taxInclusiveTotalPrice = "0";
+ productForm.value.taxInclusiveTotalPrice = 0;
}
// 宸茬煡鏁伴噺锛屽弽绠楀惈绋庡崟浠�
if (productForm.value.quantity) {
- productForm.value.taxInclusiveUnitPrice = (
+ productForm.value.taxInclusiveUnitPrice = toDisplayNumber(
Number(productForm.value.taxInclusiveTotalPrice) /
- Number(productForm.value.quantity)
- ).toFixed(6);
+ Number(productForm.value.quantity)
+ );
// 纭繚缁撴灉涓嶄负璐熸暟
if (Number(productForm.value.taxInclusiveUnitPrice) < 0) {
- productForm.value.taxInclusiveUnitPrice = "0";
+ productForm.value.taxInclusiveUnitPrice = 0;
}
}
// 宸茬煡鍚◣鍗曚环锛屽弽绠楁暟閲�
else if (productForm.value.taxInclusiveUnitPrice) {
- productForm.value.quantity = (
+ productForm.value.quantity = toDisplayNumber(
Number(productForm.value.taxInclusiveTotalPrice) /
- Number(productForm.value.taxInclusiveUnitPrice)
- ).toFixed(6);
+ Number(productForm.value.taxInclusiveUnitPrice)
+ );
// 纭繚缁撴灉涓嶄负璐熸暟
if (Number(productForm.value.quantity) < 0) {
- productForm.value.quantity = "0";
+ productForm.value.quantity = 0;
}
}
}
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