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 => {