|
|
@@ -4,10 +4,10 @@
|
|
|
<ele-pro-table
|
|
|
ref="table"
|
|
|
:columns="columns"
|
|
|
- :datasource="poList.filter((item) => item.disposalStatus != 2)"
|
|
|
+ :datasource="displayPoList"
|
|
|
:selection.sync="selection"
|
|
|
:needPage="false"
|
|
|
- row-key="id"
|
|
|
+ row-key="uniqueKey"
|
|
|
max-height="500px"
|
|
|
>
|
|
|
<!-- 操作列 -->
|
|
|
@@ -305,8 +305,10 @@
|
|
|
width="60%"
|
|
|
append-to-body
|
|
|
title="选择"
|
|
|
+ @close="closeAdd"
|
|
|
>
|
|
|
<el-table
|
|
|
+ ref="addTable"
|
|
|
:data="inventoryList"
|
|
|
@selection-change="handleAddSelectionChange"
|
|
|
row-key="id"
|
|
|
@@ -761,6 +763,18 @@
|
|
|
},
|
|
|
disposalStatustList() {
|
|
|
return { 0: '待处置', 1: '处置中', 2: '处置完成' };
|
|
|
+ },
|
|
|
+ // 兜底去重,防止 uniqueKey 极端情况下仍重复
|
|
|
+ displayPoList() {
|
|
|
+ const seen = new Set();
|
|
|
+ return this.poList
|
|
|
+ .filter((item) => item.disposalStatus != 2)
|
|
|
+ .filter((item) => {
|
|
|
+ const key = item.uniqueKey || item.id;
|
|
|
+ if (!key || seen.has(key)) return false;
|
|
|
+ seen.add(key);
|
|
|
+ return true;
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
@@ -769,6 +783,16 @@
|
|
|
this.getReasonTypeList();
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 为每行生成前端唯一 key:已保存的使用 's_'+id,新增/拆分的生成 'n_'+时间戳+随机数
|
|
|
+ ensureUniqueKey(item) {
|
|
|
+ if (item.uniqueKey) return item.uniqueKey;
|
|
|
+ if (item.id) {
|
|
|
+ item.uniqueKey = `s_${item.id}`;
|
|
|
+ } else {
|
|
|
+ item.uniqueKey = `n_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
|
+ }
|
|
|
+ return item.uniqueKey;
|
|
|
+ },
|
|
|
disposalStatusFilter(value, row, column) {
|
|
|
if (value == row.disposalStatus) {
|
|
|
return row;
|
|
|
@@ -836,6 +860,7 @@
|
|
|
if (qualityResults == 1) {
|
|
|
this.poList = JSON.parse(JSON.stringify(this.oldList));
|
|
|
this.poList = this.poList.map((item) => {
|
|
|
+ this.ensureUniqueKey(item);
|
|
|
if (item.disposalStatus != 2) {
|
|
|
item.disposalStatus = 1;
|
|
|
item.disposeType = 5;
|
|
|
@@ -853,6 +878,7 @@
|
|
|
)
|
|
|
];
|
|
|
this.poList = this.poList.map((item) => {
|
|
|
+ this.ensureUniqueKey(item);
|
|
|
if (item.disposalStatus != 2) {
|
|
|
item.disposalStatus = 1;
|
|
|
item.disposeType = 5;
|
|
|
@@ -869,9 +895,16 @@
|
|
|
)
|
|
|
)
|
|
|
];
|
|
|
+ this.poList = this.poList.map((item) => {
|
|
|
+ this.ensureUniqueKey(item);
|
|
|
+ return item;
|
|
|
+ });
|
|
|
}
|
|
|
if (qualityResults == 3) {
|
|
|
this.poList = JSON.parse(JSON.stringify(this.oldList));
|
|
|
+ this.poList.forEach((item) => {
|
|
|
+ this.ensureUniqueKey(item);
|
|
|
+ });
|
|
|
}
|
|
|
this.qualityResults = qualityResults;
|
|
|
this.setQualifiedNumber();
|
|
|
@@ -890,7 +923,9 @@
|
|
|
this.$message.warning('请选择数据');
|
|
|
return;
|
|
|
}
|
|
|
- const poListTotal = this.poList.reduce(
|
|
|
+ const poListTotal = this.poList
|
|
|
+ .filter((item) => ![5, 6, 7].includes(item.disposeType))
|
|
|
+ .reduce(
|
|
|
(sum, item) => sum + Number(item.measureQuantity || 0),
|
|
|
0
|
|
|
);
|
|
|
@@ -910,6 +945,10 @@
|
|
|
}
|
|
|
this.addSelection.forEach((item) => {
|
|
|
const newItem = JSON.parse(JSON.stringify(item));
|
|
|
+ // 拆分行:始终生成新的 uniqueKey(基于时间戳+随机数)
|
|
|
+ newItem.uniqueKey = `n_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
|
+ // 拆分行不带后端 id,清掉避免误传
|
|
|
+ delete newItem.id;
|
|
|
if (this.inventoryList.length === 1) {
|
|
|
newItem.measureQuantity = Number(this.singleQuantity);
|
|
|
}
|
|
|
@@ -920,17 +959,28 @@
|
|
|
},
|
|
|
add() {
|
|
|
this.addDialogVisible = true;
|
|
|
- this.addSelection = [];
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.addTable?.clearSelection();
|
|
|
+ });
|
|
|
if (this.inventoryList.length === 1) {
|
|
|
this.singleQuantity = this.inventoryList[0].measureQuantity || 0;
|
|
|
}
|
|
|
},
|
|
|
+ closeAdd() {
|
|
|
+ this.addSelection = [];
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.addTable?.clearSelection();
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
// /* 表格数据源 */
|
|
|
async datasource() {
|
|
|
const arr = await getById(this.id);
|
|
|
this.oldList = JSON.parse(JSON.stringify(arr.poList));
|
|
|
- this.poList = arr.poList;
|
|
|
+ this.poList = arr.poList.map((item) => {
|
|
|
+ this.ensureUniqueKey(item);
|
|
|
+ return item;
|
|
|
+ });
|
|
|
this.setQualifiedNumber();
|
|
|
},
|
|
|
|