From 9f3bc47b98cbc51df7cfcea94d4aa0c35f40cbc5 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期二, 13 十月 2026 14:09:06 +0800
Subject: [PATCH] feat: 添加数字格式化工具,支持去掉小数末尾多余的 0 和四舍五入功能
---
src/views/salesManagement/salesLedger/index.vue | 36 ++++++++++++++++++------------------
1 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/src/views/salesManagement/salesLedger/index.vue b/src/views/salesManagement/salesLedger/index.vue
index 86deb71..93d5ef6 100644
--- a/src/views/salesManagement/salesLedger/index.vue
+++ b/src/views/salesManagement/salesLedger/index.vue
@@ -654,7 +654,7 @@
align="right"
>
<template #default="scope">
- {{ Number(scope.row.totalAmount ?? 0).toFixed(6) }}
+ {{ trimZeros(scope.row.totalAmount, 6) }}
</template>
</el-table-column>
<el-table-column fixed="right" label="鎿嶄綔" width="120" align="center">
@@ -959,9 +959,11 @@
<td>{{ product.productCategory || "" }}</td>
<td>{{ product.specificationModel || "" }}</td>
<td>{{ product.unit || "" }}</td>
- <td>{{ product.taxInclusiveUnitPrice || "0" }}</td>
- <td>{{ product.quantity || "0" }}</td>
- <td>{{ product.taxInclusiveTotalPrice || "0" }}</td>
+ <td>{{ trimZeros(product.taxInclusiveUnitPrice, 6) }}</td>
+ <td>{{ trimZeros(product.quantity, 6) }}</td>
+ <td>
+ {{ trimZeros(product.taxInclusiveTotalPrice, 6) }}
+ </td>
</tr>
<tr v-if="!item.products || item.products.length === 0">
<td colspan="6" style="text-align: center; color: #999">
@@ -1188,6 +1190,7 @@
import FileUpload from "@/components/AttachmentUpload/file/index.vue";
import ImageUpload from "@/components/AttachmentUpload/image/index.vue";
import { getCurrentDate } from "@/utils/index.js";
+import { trimZeros } from "@/utils/formatNumber.js";
import { listCustomer } from "@/api/basicData/customer.js";
const FileList = defineAsyncComponent(() =>
@@ -1531,10 +1534,7 @@
});
};
const formattedNumber = (row, column, cellValue) => {
- if (cellValue === undefined || cellValue === null || cellValue === "") {
- return "0.000000";
- }
- return parseFloat(cellValue).toFixed(6);
+ return trimZeros(cellValue, 6);
};
const findLedgerRecordByRow = (row) => {
if (!row) return null;
@@ -1694,9 +1694,9 @@
param,
["contractAmount", "taxInclusiveTotalPrice", "taxExclusiveTotalPrice"],
{
- contractAmount: { decimalPlaces: 6 },
- taxInclusiveTotalPrice: { decimalPlaces: 6 },
- taxExclusiveTotalPrice: { decimalPlaces: 6 },
+ contractAmount: { decimalPlaces: 6, trimZeros: true },
+ taxInclusiveTotalPrice: { decimalPlaces: 6, trimZeros: true },
+ taxExclusiveTotalPrice: { decimalPlaces: 6, trimZeros: true },
}
);
};
@@ -1710,9 +1710,9 @@
"taxExclusiveTotalPrice",
],
{
- taxInclusiveUnitPrice: { decimalPlaces: 6 },
- taxInclusiveTotalPrice: { decimalPlaces: 6 },
- taxExclusiveTotalPrice: { decimalPlaces: 6 },
+ taxInclusiveUnitPrice: { decimalPlaces: 6, trimZeros: true },
+ taxInclusiveTotalPrice: { decimalPlaces: 6, trimZeros: true },
+ taxExclusiveTotalPrice: { decimalPlaces: 6, trimZeros: true },
}
);
};
@@ -2535,7 +2535,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.quantity) || 0);
}, 0);
- return total.toFixed(6);
+ return trimZeros(total, 6);
};
// 璁$畻浜у搧鎬婚噾棰�
@@ -2544,7 +2544,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
}, 0);
- return total.toFixed(6);
+ return trimZeros(total, 6);
};
// 鐢ㄤ簬鎵撳嵃鐨勮绠楀嚱鏁�
@@ -2553,7 +2553,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.quantity) || 0);
}, 0);
- return total.toFixed(6);
+ return trimZeros(total, 6);
};
const getTotalAmountForPrint = (products) => {
@@ -2561,7 +2561,7 @@
const total = products.reduce((sum, product) => {
return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0);
}, 0);
- return total.toFixed(6);
+ return trimZeros(total, 6);
};
const mathNum = () => {
--
Gitblit v1.9.3