Commit 8223901a by yubin

修bug

parent 92fcc23b
......@@ -603,39 +603,75 @@ export default {
this.$set(row, 'plannedQuantity', 1);
}
},
syncDetails(strict = true) {
// 改造后的 syncDetails:仅校验有实际数量的行,且有值才校验
syncDetails(strict = true) {
this.details = [];
const errorMessages = []; // 收集有值但不合规的字段提示
let validRows = [];
if (strict) {
validRows = this.inventoryList.filter(row => {
const availableQty = (row.quantity || 0) - (row.lockedQuantity || 0);
return row.actualQuantity !== null &&
row.actualQuantity !== undefined &&
row.actualQuantity >= 1 &&
row.actualQuantity <= availableQty &&
row.plannedQuantity !== null &&
row.plannedQuantity !== undefined &&
row.plannedQuantity >= 1 &&
row.plannedQuantity <= availableQty &&
row.divisor !== null &&
row.labelColor !== '' &&
row.voucherNumber !== '' &&
row.shippedBy !== '';
// 第一步:先过滤出「实际数量有值」的行(核心:无实际数量的行直接排除)
const rowsWithActualQty = this.inventoryList.filter(row => {
return row.actualQuantity !== null && row.actualQuantity !== undefined;
});
} else {
validRows = this.inventoryList.filter(row => {
return row.actualQuantity !== null ||
row.plannedQuantity !== null ||
row.divisor !== null ||
row.labelColor !== '' ||
row.unitPrice !== null ||
row.shippedBy !== '' ||
row.voucherNumber !== '' ||
row.remark !== '';
if (strict && rowsWithActualQty.length > 0) {
// 严格模式:仅校验有实际数量的行,且「有值才校验」
validRows = rowsWithActualQty.filter((row, index) => {
const rowErrors = [];
const rowName = `第${index + 1}行【${row.materialName || '未知物料'}】`;
const availableQty = (row.quantity || 0) - (row.lockedQuantity || 0);
// 1. 实际数量(必校验,因为能走到这步说明有值)
if (row.actualQuantity < 1) {
rowErrors.push('实际数量不能小于1');
}
if (row.actualQuantity > availableQty) {
rowErrors.push(`实际数量不能超过可用库存(${availableQty})`);
}
// 2. 计划数量(有值才校验)
if (row.plannedQuantity !== null && row.plannedQuantity !== undefined) {
if (row.plannedQuantity < 1) {
rowErrors.push('计划数量不能小于1');
}
if (row.plannedQuantity > availableQty) {
rowErrors.push(`计划数量不能超过可用库存(${availableQty})`);
}
}
// 3. 除数(有值才校验,无值不提示)
if (row.divisor !== null && row.divisor !== undefined) {
// 若有值但为0/负数,可补充校验(按需)
if (row.divisor <= 0) {
rowErrors.push('换算率(除数)必须大于0');
}
}
// 4. 标签颜色(有值才校验,空字符串算不合规)
if (row.labelColor !== undefined && row.labelColor === '') {
rowErrors.push('请填写标签颜色');
}
// 5. 凭证号(有值才校验,空字符串算不合规)
if (row.voucherNumber !== undefined && row.voucherNumber === '') {
rowErrors.push('请填写凭证号');
}
// 6. 发货人(有值才校验,空字符串算不合规)
if (row.shippedBy !== undefined && row.shippedBy === '') {
rowErrors.push('请填写发货人');
}
// 收集当前行的错误(仅有值但不合规的字段)
if (rowErrors.length > 0) {
errorMessages.push(`${rowName}${rowErrors.join('、')}`);
return false;
}
return true;
});
}
// 格式化通过校验的行并同步到details
validRows.forEach(row => {
const newDetail = {
inventoryId: row.inventoryId,
......@@ -659,44 +695,50 @@ export default {
};
this.details.push(newDetail);
});
},
removeDetail(row) {
this.details = this.details.filter(d => d.inventoryId !== row.inventoryId);
const inventoryRow = this.inventoryList.find(item => item.inventoryId === row.inventoryId);
if (inventoryRow) {
this.$set(inventoryRow, 'actualQuantity', null);
this.$set(inventoryRow, 'plannedQuantity', null);
this.$set(inventoryRow, 'divisor', null);
this.$set(inventoryRow, 'labelColor', '');
this.$set(inventoryRow, 'unitPrice', null);
this.$set(inventoryRow, 'shippedBy', '');
this.$set(inventoryRow, 'voucherNumber', '');
this.$set(inventoryRow, 'remark', '');
if (this.currentSelectedRowId === row.inventoryId) {
this.currentSelectedRowId = this.inventoryList.length > 0 ? this.inventoryList[0].inventoryId : null;
}
}
this.syncDetails(this.initDetails.length === 0);
},
handleSubmit() {
// 返回错误信息,供提交方法使用
return errorMessages;
},
// 提交方法:集成精准提示
handleSubmit() {
// 1. 校验物料ID
if (!this.form.materialId?.trim()) {
this.$message.error('请先选择物料ID');
return;
}
// 2. 校验表单基础项
this.$refs.detailForm.validate(async (valid) => {
if (!valid) {
this.$message.error('表单校验失败,请检查必填项');
return;
}
this.syncDetails(true);
console.log("syncDetails前", this.details);
// 执行明细校验,接收错误信息
const detailErrors = this.syncDetails(true);
console.log("syncDetails后", this.details);
// 3. 提示有值但不合规的字段
if (detailErrors.length > 0) {
this.$message.error({
title: '明细数据校验失败',
message: detailErrors.join('<br/>'),
dangerouslyUseHTMLString: true,
duration: 15000,
showClose: true
});
return;
}
// 4. 兜底:有实际数量的行都校验通过,但无有效行(比如实际数量都<1
if (this.details.length === 0) {
this.$message.error('请填写实际数量并完善所有必填明细信息');
this.$message.error('无有效明细数据,请检查实际数量及相关字段');
return;
}
// 5. 组装提交数据
const submitDetails = this.details.map(detail => ({
...detail,
materialName: this.form.materialName || detail.materialName,
......@@ -709,7 +751,26 @@ export default {
this.$emit('submit', submitDetails);
this.$emit('update:open', false);
});
},
removeDetail(row) {
this.details = this.details.filter(d => d.inventoryId !== row.inventoryId);
const inventoryRow = this.inventoryList.find(item => item.inventoryId === row.inventoryId);
if (inventoryRow) {
this.$set(inventoryRow, 'actualQuantity', null);
this.$set(inventoryRow, 'plannedQuantity', null);
this.$set(inventoryRow, 'divisor', null);
this.$set(inventoryRow, 'labelColor', '');
this.$set(inventoryRow, 'unitPrice', null);
this.$set(inventoryRow, 'shippedBy', '');
this.$set(inventoryRow, 'voucherNumber', '');
this.$set(inventoryRow, 'remark', '');
if (this.currentSelectedRowId === row.inventoryId) {
this.currentSelectedRowId = this.inventoryList.length > 0 ? this.inventoryList[0].inventoryId : null;
}
}
this.syncDetails(this.initDetails.length === 0);
},
handleClose() {
this.closeLoading();
this.$nextTick(() => {
......
......@@ -556,24 +556,25 @@ and inventory_status = '1'
<select id="selectInventoryTopTenByAmount" resultType="java.util.Map">
select
m.material_name as name,
sum(i.quantity) as value
sum(i.quantity)*i.unit_price as value
from inventory i
left join materials m on i.material_id = m.id
where i.is_used = 1 and i.last_inbound_time &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
where i.is_used = 1 and i.unit_price >0 and i.last_inbound_time &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and i.last_inbound_time &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.material_name
order by sum(i.quantity) desc
order by sum(i.quantity)*i.unit_price desc
</select>
<select id="selectInventoryTopTenByQuantity" resultType="java.util.Map">
select
m.material_name as name,
sum(i.quantity)*i.unit_price as value
sum(i.quantity) as value
from inventory i
left join materials m on i.material_id = m.id
where i.is_used = 1 and i.last_inbound_time &gt;= DATE_FORMAT(CURDATE(), '%Y-%m-01')
and i.last_inbound_time &lt; DATE_FORMAT(DATE_ADD(CURDATE(), INTERVAL 1 MONTH), '%Y-%m-01')
group by m.material_name
order by sum(i.quantity)*i.unit_price desc
order by sum(i.quantity) desc
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论