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