From 2a79ac97a7e2ec68236e6c470a4f13e6a6cd768c Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Mon, 9 Feb 2026 11:56:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E5=AD=97=E7=B2=BE=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../production-inbound/inboundRegister.vue | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/views/modules/production-inbound/inboundRegister.vue b/src/views/modules/production-inbound/inboundRegister.vue index 0858ef6..0e8e4e8 100644 --- a/src/views/modules/production-inbound/inboundRegister.vue +++ b/src/views/modules/production-inbound/inboundRegister.vue @@ -210,7 +210,11 @@ export default { }, computed: { totalQty() { - const sum = this.handlingUnit.reduce((sum, item) => sum + Number(item.qty), 0); + // 使用整数运算避免浮点数精度问题 + const sumInCents = this.handlingUnit.reduce((sum, item) => { + return sum + Math.round(Number(item.qty) * 100); + }, 0); + const sum = sumInCents / 100; this.inboundItem.transQty = sum; return sum; }, @@ -413,9 +417,18 @@ export default { return; } + const qtyToReceive = parseFloat(this.inboundItem.transQty) || 0; + if (qtyToReceive <= 0) { + this.$message.warning('请先输入入库数量'); + return; + } + const perQtyValue = parseFloat(perQty); const packageQty = Math.floor(qtyToReceive / perQtyValue); - const remainder = qtyToReceive - (packageQty * perQtyValue); + + // 使用整数运算避免浮点数精度问题 + const remainderInCents = Math.round(qtyToReceive * 100) - Math.round(perQtyValue * 100) * packageQty; + const remainder = remainderInCents / 100; this.handlingUnit = []; @@ -456,7 +469,8 @@ export default { if (!perQty || !packageQty || isNaN(perQty) || isNaN(packageQty)) { return this.$message.warning("请填写有效的包装信息"); } - const qty = parseFloat(perQty) * parseInt(packageQty); + // 使用整数运算避免浮点数精度问题 + const qty = Math.round(parseFloat(perQty) * 100) * parseInt(packageQty) / 100; const code = String(this.handlingUnit.length + 1); const newItem = { ...this.hanlingItem, qty, code }; this.handlingUnit.push(newItem);