优化添加至入库的逻辑
This commit is contained in:
@@ -321,10 +321,10 @@
|
|||||||
<span>删除</span>
|
<span>删除</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<el-table :data="planList" height="400" style="width: 100%" show-overflow-tooltip
|
<el-table :data="planList" height="400" style="width: 100%" show-overflow-tooltip border
|
||||||
:row-class-name="tableRowClassName" @selection-change="handleSelectionChange">
|
:row-class-name="tableRowClassName" @selection-change="handleSelectionChange">
|
||||||
<el-table-column type="selection" width="30" align="center" />
|
<el-table-column type="selection" width="30" align="center" />
|
||||||
<el-table-column label="序号" align="center" type="index" width="50" />
|
<el-table-column label="序号" align="center" type="index" width="70" />
|
||||||
<el-table-column label="状态" align="center" prop="status" width="100" v-if="idEdit == 0">
|
<el-table-column label="状态" align="center" prop="status" width="100" v-if="idEdit == 0">
|
||||||
<template #default="scoped">
|
<template #default="scoped">
|
||||||
<el-tag :type="scoped.row.status == 1
|
<el-tag :type="scoped.row.status == 1
|
||||||
@@ -896,7 +896,7 @@ const statusList = ref([
|
|||||||
]);
|
]);
|
||||||
const checkPlanList = ref([]); //已选中的要入库的数据
|
const checkPlanList = ref([]); //已选中的要入库的数据
|
||||||
|
|
||||||
// 点击添加至出库
|
// 点击添加至入库
|
||||||
const outTempData = ref([]);
|
const outTempData = ref([]);
|
||||||
function addData() {
|
function addData() {
|
||||||
if (checkPlanList.value.length == 0) {
|
if (checkPlanList.value.length == 0) {
|
||||||
@@ -904,21 +904,53 @@ function addData() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = outTempData.value.concat(checkPlanList.value);
|
let data = outTempData.value.concat(checkPlanList.value);
|
||||||
let arr = []
|
let arr = []; // 去重后的最终数组
|
||||||
let spaNoTotal = ''
|
let duplicateSapNos = ''; // 存储重复数据的sapNo
|
||||||
const idList = []; // 用于统计每个id出现的次数
|
let invalidQtySapNos = ''; // 存储入库数量有误的sapNo
|
||||||
// 第一步:遍历数组,统计id出现次数
|
const uniqueKeys = new Set(); // 用于存储唯一的组合键 (id+pcode+realQty)
|
||||||
|
|
||||||
|
// 遍历数组,先校验数量合法性,再判断唯一性
|
||||||
data.forEach(item => {
|
data.forEach(item => {
|
||||||
if (idList.includes(item.id)) {
|
// 1. 校验realQty是否大于0(处理空值/非数字情况)
|
||||||
spaNoTotal += item.sapNo + ','
|
const realQty = Number(item.realQty);
|
||||||
} else {
|
if (isNaN(realQty) || realQty <= 0) {
|
||||||
arr.push(item)
|
// 避免同一个sapNo重复添加到提示中
|
||||||
idList.push(item.id);
|
if (!invalidQtySapNos.includes(item.sapNo)) {
|
||||||
|
invalidQtySapNos += item.sapNo + ',';
|
||||||
|
}
|
||||||
|
return; // 数量不合法,直接跳过后续唯一性判断
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. 生成唯一标识组合键
|
||||||
|
const uniqueKey = `${item.id}_${item.pcode}_${realQty}`;
|
||||||
|
|
||||||
|
// 3. 检查组合键是否已存在
|
||||||
|
if (uniqueKeys.has(uniqueKey)) {
|
||||||
|
// 存在重复,拼接sapNo(去重避免重复拼接)
|
||||||
|
if (!duplicateSapNos.includes(item.sapNo)) {
|
||||||
|
duplicateSapNos += item.sapNo + ',';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不存在重复,加入结果数组并记录组合键
|
||||||
|
arr.push(item);
|
||||||
|
uniqueKeys.add(uniqueKey);
|
||||||
|
}
|
||||||
|
console.log(uniqueKeys)
|
||||||
});
|
});
|
||||||
if (spaNoTotal) {
|
|
||||||
proxy.$modal.msgError("存在重复数据:" + spaNoTotal);
|
// 处理入库数量有误的提示
|
||||||
|
if (invalidQtySapNos) {
|
||||||
|
invalidQtySapNos = invalidQtySapNos.slice(0, -1); // 去掉最后一个逗号
|
||||||
|
proxy.$modal.msgError(`入库数量有误:${invalidQtySapNos}(入库数量需大于0)`);
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理重复数据的提示
|
||||||
|
if (duplicateSapNos) {
|
||||||
|
duplicateSapNos = duplicateSapNos.slice(0, -1); // 去掉最后一个逗号
|
||||||
|
proxy.$modal.msgError(`存在重复数据:${duplicateSapNos}`);
|
||||||
|
}
|
||||||
|
|
||||||
outTempData.value = arr
|
outTempData.value = arr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -963,6 +995,7 @@ function searchPlan() {
|
|||||||
for (let i = 0; i < planData.length; i++) {
|
for (let i = 0; i < planData.length; i++) {
|
||||||
planData[i].realQty = planData[i].waitQty;
|
planData[i].realQty = planData[i].waitQty;
|
||||||
planData[i].gysJhId = planData[i].id;
|
planData[i].gysJhId = planData[i].id;
|
||||||
|
planData[i].pcode = "";
|
||||||
if (autoFill.value && kzms.value != "") {
|
if (autoFill.value && kzms.value != "") {
|
||||||
planData[i].remark = kzms.value;
|
planData[i].remark = kzms.value;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user