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> </u-form-item>
</view> </view>
<!-- 箱数 --> <!-- 总箱数 -->
<view class="form-item"> <view class="form-item">
<u-form-item label="箱数" prop="box_quantity"> <u-form-item label="总箱数" prop="box_quantity">
<view class="input-with-unit"> <view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_quantity" placeholder="默认自动计算,可手动输入" type="number" clearable <u-input class="input-field" v-model="formData.box_quantity" placeholder="默认自动计算,可手动输入" type="number" clearable
@blur="handleBoxQuantityBlur" /> @blur="handleBoxQuantityBlur" />
@ -109,6 +109,17 @@
</u-form-item> </u-form-item>
</view> </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"> <view class="form-item">
<u-form-item label="托盘数" prop="pallet_quantity"> <u-form-item label="托盘数" prop="pallet_quantity">
@ -125,7 +136,6 @@
<view class="input-with-unit"> <view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_length" placeholder="箱长(cm)" type="number" clearable <u-input class="input-field" v-model="formData.box_length" placeholder="箱长(cm)" type="number" clearable
@blur="handleBoxesPerPalletBlur" /> @blur="handleBoxesPerPalletBlur" />
<text class="unit-text">cm</text>
</view> </view>
</u-form-item> </u-form-item>
</view> </view>
@ -135,7 +145,6 @@
<view class="input-with-unit"> <view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_width" placeholder="箱宽(cm)" type="number" clearable <u-input class="input-field" v-model="formData.box_width" placeholder="箱宽(cm)" type="number" clearable
@blur="handleBoxesPerPalletBlur" /> @blur="handleBoxesPerPalletBlur" />
<text class="unit-text">cm</text>
</view> </view>
</u-form-item> </u-form-item>
</view> </view>
@ -145,7 +154,15 @@
<view class="input-with-unit"> <view class="input-with-unit">
<u-input class="input-field" v-model="formData.box_height" placeholder="箱高(cm)" type="number" clearable <u-input class="input-field" v-model="formData.box_height" placeholder="箱高(cm)" type="number" clearable
@blur="handleBoxesPerPalletBlur" /> @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> </view>
</u-form-item> </u-form-item>
</view> </view>
@ -254,6 +271,7 @@
barcode: '', barcode: '',
batch_number: '', batch_number: '',
box_quantity: '', box_quantity: '',
tail_box_quantity: '',
boxes_per_pallet: '', boxes_per_pallet: '',
expiry_date: '', expiry_date: '',
pallet_quantity: '', pallet_quantity: '',
@ -272,6 +290,7 @@
box_width: "", box_width: "",
box_height: "", box_height: "",
box_length: "", box_length: "",
box_weight: "",
weight: "", weight: "",
}, },
spaceName: "默认收货区", spaceName: "默认收货区",
@ -317,13 +336,31 @@
box_quantity: [{ box_quantity: [{
validator: (rule, value, callback) => { validator: (rule, value, callback) => {
if (value && parseFloat(value) < 0) { if (value && parseFloat(value) < 0) {
callback(new Error('箱数不能为负数')); callback(new Error('总箱数不能为负数'));
} else { } else {
callback(); callback();
} }
}, },
trigger: ['blur', 'change'] 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: [{ production_date: [{
validator: (rule, value, callback) => { validator: (rule, value, callback) => {
if (this.isShelfLifeMgmt && !String(value || '').trim()) { if (this.isShelfLifeMgmt && !String(value || '').trim()) {
@ -368,6 +405,7 @@
isInitializing: false, isInitializing: false,
initialized: false, initialized: false,
boxQuantityManuallyEdited: false, boxQuantityManuallyEdited: false,
tailBoxQuantityManuallyEdited: false,
}; };
}, },
computed: { computed: {
@ -527,6 +565,7 @@
this.formData = newFormData; this.formData = newFormData;
this.boxQuantityManuallyEdited = false; this.boxQuantityManuallyEdited = false;
this.tailBoxQuantityManuallyEdited = false;
if (this.formData.production_date && this.formData.expiry_date && !String(this.formData.shelf_life || '').trim()) { if (this.formData.production_date && this.formData.expiry_date && !String(this.formData.shelf_life || '').trim()) {
this.syncShelfLifeFromDates(); 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, { this.calculateBoxQuantity(false, {
force: true force: true
}); });
@ -660,6 +702,15 @@
// 箱规输入处理 // 箱规输入处理
handleBoxesPerPalletBlur() { 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); this.calculateBoxQuantity(true);
}, },
@ -675,14 +726,53 @@
} }
this.boxQuantityManuallyEdited = true; 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 = {}) { calculateBoxQuantity(shouldEmit = true, options = {}) {
console.log("计算箱数", shouldEmit); console.log("计算箱数", shouldEmit);
const force = !!options.force; const force = !!options.force;
if (this.boxQuantityManuallyEdited && !force) { if (this.boxQuantityManuallyEdited && this.tailBoxQuantityManuallyEdited && !force) {
if (shouldEmit) { if (shouldEmit) {
this.emitFormData(); this.emitFormData();
} }
@ -693,18 +783,28 @@
let boxesPerPallet = parseFloat(this.formData.boxes_per_pallet); let boxesPerPallet = parseFloat(this.formData.boxes_per_pallet);
let newBoxQuantity = ""; let newBoxQuantity = "";
let newTailBoxQuantity = "";
if (!isNaN(actualQuantity) && actualQuantity > 0) { if (!isNaN(actualQuantity) && actualQuantity > 0) {
if (!isNaN(boxesPerPallet) && boxesPerPallet > 0) { if (!isNaN(boxesPerPallet) && boxesPerPallet > 0) {
// 计算箱数:实际数量 ÷ 箱规,向上取整 // 计算总箱数:实际数量 ÷ 箱规,向下取整
let boxQuantity = Math.ceil(actualQuantity / boxesPerPallet); // 保证关系:实际数量 = 箱规 * 总箱数 + 尾箱数
let boxQuantity = Math.floor(actualQuantity / boxesPerPallet);
newBoxQuantity = boxQuantity.toString(); newBoxQuantity = boxQuantity.toString();
const remainder = actualQuantity % boxesPerPallet;
newTailBoxQuantity = String(Number(remainder.toFixed(6)));
} else { } 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) { if (shouldEmit) {
console.log("提交更改"); console.log("提交更改");
this.emitFormData(); this.emitFormData();
@ -728,7 +828,9 @@
// 确保数字类型 // 确保数字类型
actual_quantity: parseFloat(this.formData.actual_quantity) || 0, actual_quantity: parseFloat(this.formData.actual_quantity) || 0,
box_quantity: this.formData.box_quantity ? parseInt(this.formData.box_quantity) : null, 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, 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, shelf_life: this.formData.shelf_life ? parseInt(this.formData.shelf_life) : null,
pallet_quantity: this.formData.pallet_quantity ? parseFloat(this.formData.pallet_quantity) : null, pallet_quantity: this.formData.pallet_quantity ? parseFloat(this.formData.pallet_quantity) : null,
}; };