From c9d83a5f64985d17a9f97bdcb96a41421865f264 Mon Sep 17 00:00:00 2001 From: "han\\hanst" Date: Wed, 15 Oct 2025 09:46:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=9B=E9=87=8D=E5=87=80=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ecss/components/PackingDetailTab.vue | 85 ++++++++++++++++++- 1 file changed, 82 insertions(+), 3 deletions(-) diff --git a/src/views/modules/ecss/components/PackingDetailTab.vue b/src/views/modules/ecss/components/PackingDetailTab.vue index cba24bf..b93fbc5 100644 --- a/src/views/modules/ecss/components/PackingDetailTab.vue +++ b/src/views/modules/ecss/components/PackingDetailTab.vue @@ -112,17 +112,17 @@ - + - + - + @@ -611,6 +611,85 @@ export default { this.editDetailDialogVisible = true; }, + /** + * 箱数改变时自动计算净重 + * 保持毛重不变,重新计算净重 + * 计算公式:净重 = 毛重 - box_qty/2 + */ + onBoxQtyChange(value) { + // 防止循环触发,使用标志位 + if (this._isCalculating) { + return; + } + + this._isCalculating = true; + + try { + const boxQty = parseFloat(value) || 0; + const grossWeight = parseFloat(this.editBoxForm.grossWeight) || 0; + + // 计算净重:净重 = 毛重 - box_qty/2 + const netWeight = grossWeight - (boxQty / 2); + + // 保留2位小数 + this.editBoxForm.netWeight = netWeight.toFixed(2); + } finally { + this._isCalculating = false; + } + }, + + /** + * 毛重改变时自动计算净重 + * 计算公式:净重 = 毛重 - box_qty/2 + */ + onGrossWeightChange(value) { + // 防止循环触发,使用标志位 + if (this._isCalculating) { + return; + } + + this._isCalculating = true; + + try { + const grossWeight = parseFloat(value) || 0; + const boxQty = parseFloat(this.editBoxForm.box_qty) || 0; + + // 计算净重:净重 = 毛重 - box_qty/2 + const netWeight = grossWeight - (boxQty / 2); + + // 保留2位小数 + this.editBoxForm.netWeight = netWeight.toFixed(2); + } finally { + this._isCalculating = false; + } + }, + + /** + * 净重改变时自动计算毛重 + * 反向计算公式:毛重 = 净重 + box_qty/2 + */ + onNetWeightChange(value) { + // 防止循环触发,使用标志位 + if (this._isCalculating) { + return; + } + + this._isCalculating = true; + + try { + const netWeight = parseFloat(value) || 0; + const boxQty = parseFloat(this.editBoxForm.box_qty) || 0; + + // 反向计算毛重:毛重 = 净重 + box_qty/2 + const grossWeight = netWeight + (boxQty / 2); + + // 保留2位小数 + this.editBoxForm.grossWeight = grossWeight.toFixed(2); + } finally { + this._isCalculating = false; + } + }, + // 提交修改箱信息 submitEditBox() { this.$refs.editBoxForm.validate(valid => {