This commit is contained in:
hayu 2025-11-17 00:14:04 +08:00
parent c6f098474e
commit 6f05db2107
1 changed files with 47 additions and 43 deletions

View File

@ -87,7 +87,7 @@ export default {
typeName: null,
code: null,
},
externalSelectedRows:[],
tableList: [],
// selectedMap key `${id}-${type}`
selectedMap: new Map(),
@ -95,19 +95,9 @@ export default {
},
methods: {
// SelectToolDialog.vue openDialog
openDialog(applyId, externalSelectedRows = []) {
this.applyId = applyId
this.visible = true
// selectedMap
this.selectedMap.clear()
externalSelectedRows.forEach(row => {
if (row.keyId) {
this.selectedMap.set(row.keyId, { ...row })
}
})
this.externalSelectedRows=externalSelectedRows
this.getList()
},
@ -140,31 +130,33 @@ export default {
try {
const res = await getToBeRepairList({ ...this.queryParams })
const rows = res.data || []
const externalMap = new Map(
this.externalSelectedRows.map(item => [item.keyId, item])
)
// selectedMap
this.selectedMap = this.selectedMap || new Map()
this.tableList = rows.map(item => {
const key = item.keyId
const selected = this.selectedMap.get(key)
// res.data selectedMap
rows.forEach(item => {
const external = externalMap.get(item.keyId)
const isCodeManage = item.manageMode === "编码管理"
if (external) {
// externalSelectedRows keyId
// external repairNum row repairNum
item.repairNum = external.repairNum
return {
...item,
keyId: key,
repairNum: selected ? selected.repairNum : (isCodeManage ? 1 : "")
// item selectedMap
this.selectedMap.set(item.keyId, { ...item })
} else {
// external keyId使
item.repairNum = isCodeManage ? 1 : ""
}
})
// selectedMap tableList
const tableKeys = new Set(this.tableList.map(r => r.keyId))
Array.from(this.selectedMap.keys()).forEach(key => {
if (!tableKeys.has(key)) {
this.selectedMap.delete(key)
}
})
console.log(12345,this.selectedMap)
this.tableList = rows
this.$nextTick(() => {
this.restoreSelection()
if (this.restoreSelection) this.restoreSelection()
})
} finally {
this.loading = false
}
@ -174,19 +166,25 @@ export default {
restoreSelection() {
if (!this.$refs.multipleTable) return
//
this.isRestoring = true
this.$refs.multipleTable.clearSelection()
// selectedMap
this.tableList.forEach(row => {
if (this.selectedMap.has(row.keyId)) {
this.$nextTick(() => {
this.$nextTick(() => {
this.tableList.forEach(row => {
if (this.selectedMap.has(row.keyId)) {
this.$refs.multipleTable.toggleRowSelection(row, true)
})
}
}
})
this.$nextTick(() => {
this.isRestoring = false
})
})
},
handleQuery() {
this.getList()
},
@ -197,19 +195,23 @@ export default {
},
handleSelectionChange(selection) {
if (this.isRestoring) return
// 1. selection selectedMap
selection.forEach(row => {
if (row.keyId && !this.selectedMap.has(row.keyId)) {
this.selectedMap.set(row.keyId, { ...row })
}
})
this.tableList.forEach(row => {
if (row.keyId && !selection.some(s => s.keyId === row.keyId)) {
this.selectedMap.delete(row.keyId)
}
})
// 2. selectedMap selection
for (const [keyId] of this.selectedMap) {
if (!selection.some(s => s.keyId === keyId)) {
this.selectedMap.delete(keyId)
}
}
},
handleConfirm() {
if (this.selectedMap.size === 0) return this.$message.warning("请至少选择一条数据")
@ -222,12 +224,14 @@ export default {
}
this.$emit("confirm", [...this.selectedMap.values()])
this.selectedMap.clear()
this.visible = false
},
// handleClose
handleClose() {
// selectedMap便使
this.selectedMap.clear()
this.visible = false
}
}