chore: 提交收货明细页修改

This commit is contained in:
zm2000 2026-05-06 17:52:07 +08:00
parent 104423eec4
commit 52e7d21a99

View File

@ -98,9 +98,9 @@
</u-form-item>
</view>
<!-- 箱数 -->
<!-- 总箱数 -->
<view class="form-item">
<u-form-item label="箱数" prop="box_quantity">
<u-form-item label="总箱数" prop="box_quantity">
<view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_quantity" placeholder="默认自动计算,可手动输入" type="number" clearable
@blur="handleBoxQuantityBlur" />
@ -109,6 +109,17 @@
</u-form-item>
</view>
<!-- 尾箱数 -->
<view class="form-item">
<u-form-item label="尾箱数" prop="tail_box_quantity">
<view class="input-with-unit">
<u-input class="input-field" v-model="formData.tail_box_quantity" placeholder="请输入尾箱数" type="number" clearable
@blur="handleTailBoxQuantityBlur" />
<text class="unit-text">个/箱</text>
</view>
</u-form-item>
</view>
<!-- 托盘数(可选) -->
<view class="form-item">
<u-form-item label="托盘数" prop="pallet_quantity">
@ -125,7 +136,6 @@
<view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_length" placeholder="箱长(cm)" type="number" clearable
@blur="handleBoxesPerPalletBlur" />
<text class="unit-text">cm</text>
</view>
</u-form-item>
</view>
@ -135,7 +145,6 @@
<view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_width" placeholder="箱宽(cm)" type="number" clearable
@blur="handleBoxesPerPalletBlur" />
<text class="unit-text">cm</text>
</view>
</u-form-item>
</view>
@ -145,7 +154,15 @@
<view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_height" placeholder="箱高(cm)" type="number" clearable
@blur="handleBoxesPerPalletBlur" />
<text class="unit-text">cm</text>
</view>
</u-form-item>
</view>
<view class="form-item">
<u-form-item label="箱重量(g)" prop="box_weight">
<view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_weight" placeholder="箱重量(g)" type="number" clearable
@blur="emitFormData" />
</view>
</u-form-item>
</view>
@ -254,6 +271,7 @@
barcode: '',
batch_number: '',
box_quantity: '',
tail_box_quantity: '',
boxes_per_pallet: '',
expiry_date: '',
pallet_quantity: '',
@ -272,6 +290,7 @@
box_width: "",
box_height: "",
box_length: "",
box_weight: "",
weight: "",
},
spaceName: "默认收货区",
@ -317,13 +336,31 @@
box_quantity: [{
validator: (rule, value, callback) => {
if (value && parseFloat(value) < 0) {
callback(new Error('箱数不能为负数'));
callback(new Error('总箱数不能为负数'));
} else {
callback();
}
},
trigger: ['blur', 'change']
}],
tail_box_quantity: [{
validator: (rule, value, callback) => {
if (value && parseFloat(value) < 0) {
callback(new Error('尾箱数不能为负数'));
return;
}
const tailBoxQuantity = parseFloat(value);
const boxesPerPallet = parseFloat(this.formData.boxes_per_pallet);
if (!isNaN(tailBoxQuantity) && !isNaN(boxesPerPallet) && boxesPerPallet > 0 && tailBoxQuantity >= boxesPerPallet) {
callback(new Error('尾箱数必须小于箱规'));
return;
}
callback();
},
trigger: ['blur', 'change']
}],
production_date: [{
validator: (rule, value, callback) => {
if (this.isShelfLifeMgmt && !String(value || '').trim()) {
@ -368,6 +405,7 @@
isInitializing: false,
initialized: false,
boxQuantityManuallyEdited: false,
tailBoxQuantityManuallyEdited: false,
};
},
computed: {
@ -527,6 +565,7 @@
this.formData = newFormData;
this.boxQuantityManuallyEdited = false;
this.tailBoxQuantityManuallyEdited = false;
if (this.formData.production_date && this.formData.expiry_date && !String(this.formData.shelf_life || '').trim()) {
this.syncShelfLifeFromDates();
}
@ -538,8 +577,11 @@
}));
}
// 无已有箱数时默认自动计算;有值时保留原值,允许后续手动修改
if (newFormData.box_quantity === null || newFormData.box_quantity === undefined || newFormData.box_quantity === '') {
// 无已有箱数/尾箱数时默认自动计算;有值时保留原值,允许后续手动修改
if (
newFormData.box_quantity === null || newFormData.box_quantity === undefined || newFormData.box_quantity === '' ||
newFormData.tail_box_quantity === null || newFormData.tail_box_quantity === undefined || newFormData.tail_box_quantity === ''
) {
this.calculateBoxQuantity(false, {
force: true
});
@ -660,6 +702,15 @@
// 箱规输入处理
handleBoxesPerPalletBlur() {
const hasManualBoxes = this.boxQuantityManuallyEdited || this.tailBoxQuantityManuallyEdited;
if (hasManualBoxes) {
this.calculateActualQuantityFromBoxes(false);
this.$refs.uForm.validateField('tail_box_quantity');
this.emitFormData();
return;
}
this.$refs.uForm.validateField('tail_box_quantity');
this.calculateBoxQuantity(true);
},
@ -675,14 +726,53 @@
}
this.boxQuantityManuallyEdited = true;
this.emitFormData();
this.calculateActualQuantityFromBoxes(true);
},
// 尾箱数输入处理
handleTailBoxQuantityBlur() {
const tailBoxQuantity = String(this.formData.tail_box_quantity || '').trim();
if (!tailBoxQuantity) {
this.tailBoxQuantityManuallyEdited = false;
this.calculateBoxQuantity(true, {
force: true
});
return;
}
this.tailBoxQuantityManuallyEdited = true;
this.calculateActualQuantityFromBoxes(true);
},
// 根据总箱数、尾箱数回算实际数量
calculateActualQuantityFromBoxes(shouldEmit = true) {
const boxesPerPallet = parseFloat(this.formData.boxes_per_pallet);
if (isNaN(boxesPerPallet) || boxesPerPallet <= 0) {
if (shouldEmit) {
this.emitFormData();
}
return;
}
const boxQuantity = parseFloat(this.formData.box_quantity);
const tailBoxQuantity = parseFloat(this.formData.tail_box_quantity);
const safeBoxQuantity = !isNaN(boxQuantity) && boxQuantity >= 0 ? boxQuantity : 0;
const safeTailBoxQuantity = !isNaN(tailBoxQuantity) && tailBoxQuantity >= 0 ? tailBoxQuantity : 0;
const actualQuantity = safeBoxQuantity * boxesPerPallet + safeTailBoxQuantity;
this.formData.actual_quantity = String(Number(actualQuantity.toFixed(6)));
if (shouldEmit) {
this.emitFormData();
}
},
// 计算箱数
calculateBoxQuantity(shouldEmit = true, options = {}) {
console.log("计算箱数", shouldEmit);
const force = !!options.force;
if (this.boxQuantityManuallyEdited && !force) {
if (this.boxQuantityManuallyEdited && this.tailBoxQuantityManuallyEdited && !force) {
if (shouldEmit) {
this.emitFormData();
}
@ -693,18 +783,28 @@
let boxesPerPallet = parseFloat(this.formData.boxes_per_pallet);
let newBoxQuantity = "";
let newTailBoxQuantity = "";
if (!isNaN(actualQuantity) && actualQuantity > 0) {
if (!isNaN(boxesPerPallet) && boxesPerPallet > 0) {
// 计算箱数:实际数量 ÷ 箱规,向上取整
let boxQuantity = Math.ceil(actualQuantity / boxesPerPallet);
// 计算总箱数:实际数量 ÷ 箱规,向下取整
// 保证关系:实际数量 = 箱规 * 总箱数 + 尾箱数
let boxQuantity = Math.floor(actualQuantity / boxesPerPallet);
newBoxQuantity = boxQuantity.toString();
const remainder = actualQuantity % boxesPerPallet;
newTailBoxQuantity = String(Number(remainder.toFixed(6)));
} else {
// 箱规未设置,默认1箱
newBoxQuantity = "1";
// 箱规未设置时无法计算总箱数和尾箱数
newBoxQuantity = "";
newTailBoxQuantity = '';
}
}
this.formData.box_quantity = newBoxQuantity;
if (!this.boxQuantityManuallyEdited || force) {
this.formData.box_quantity = newBoxQuantity;
}
if (!this.tailBoxQuantityManuallyEdited || force) {
this.formData.tail_box_quantity = newTailBoxQuantity;
}
if (shouldEmit) {
console.log("提交更改");
this.emitFormData();
@ -728,7 +828,9 @@
// 确保数字类型
actual_quantity: parseFloat(this.formData.actual_quantity) || 0,
box_quantity: this.formData.box_quantity ? parseInt(this.formData.box_quantity) : null,
tail_box_quantity: this.formData.tail_box_quantity ? parseFloat(this.formData.tail_box_quantity) : null,
boxes_per_pallet: this.formData.boxes_per_pallet ? parseFloat(this.formData.boxes_per_pallet) : null,
box_weight: this.formData.box_weight ? parseFloat(this.formData.box_weight) : null,
shelf_life: this.formData.shelf_life ? parseInt(this.formData.shelf_life) : null,
pallet_quantity: this.formData.pallet_quantity ? parseFloat(this.formData.pallet_quantity) : null,
};