This commit is contained in:
parent
58a2fb721b
commit
d6a44fbb08
|
|
@ -95,10 +95,20 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
openDialog(applyId) {
|
// 在 SelectToolDialog.vue 中修改 openDialog 方法
|
||||||
|
openDialog(applyId, externalSelectedRows = []) {
|
||||||
this.applyId = applyId
|
this.applyId = applyId
|
||||||
this.visible = true
|
this.visible = true
|
||||||
this.getList() // 弹窗内部拉取完整数据并恢复勾选
|
|
||||||
|
// 接收外部传入的已选数据,同步 selectedMap
|
||||||
|
this.selectedMap.clear()
|
||||||
|
externalSelectedRows.forEach(row => {
|
||||||
|
if (row.keyId) {
|
||||||
|
this.selectedMap.set(row.keyId, { ...row })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
this.getList()
|
||||||
},
|
},
|
||||||
|
|
||||||
setFixNumToTableList(row, val) {
|
setFixNumToTableList(row, val) {
|
||||||
|
|
@ -133,23 +143,26 @@ export default {
|
||||||
|
|
||||||
this.tableList = rows.map(item => {
|
this.tableList = rows.map(item => {
|
||||||
const key = item.keyId
|
const key = item.keyId
|
||||||
|
|
||||||
const selected = this.selectedMap.get(key)
|
const selected = this.selectedMap.get(key)
|
||||||
const isCodeManage = item.manageMode === "编码管理"
|
const isCodeManage = item.manageMode === "编码管理"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...item,
|
...item,
|
||||||
keyId: key, // ⭐ 统一 row-key 与 selectedMap key
|
keyId: key,
|
||||||
repairNum: selected ? selected.repairNum : isCodeManage ? 1 : ""
|
repairNum: selected ? selected.repairNum : (isCodeManage ? 1 : "")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 过滤 selectedMap,只保留 tableList 中存在的 keyId
|
|
||||||
|
// 清理 selectedMap 中不存在于当前 tableList 的数据
|
||||||
const tableKeys = new Set(this.tableList.map(r => r.keyId))
|
const tableKeys = new Set(this.tableList.map(r => r.keyId))
|
||||||
Array.from(this.selectedMap.keys()).forEach(key => {
|
Array.from(this.selectedMap.keys()).forEach(key => {
|
||||||
if (!tableKeys.has(key)) this.selectedMap.delete(key)
|
if (!tableKeys.has(key)) {
|
||||||
|
this.selectedMap.delete(key)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
if (this.restoreSelection) this.restoreSelection()
|
this.restoreSelection()
|
||||||
})
|
})
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -157,11 +170,19 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 在弹窗组件中添加
|
||||||
restoreSelection() {
|
restoreSelection() {
|
||||||
if (!this.$refs.multipleTable) return
|
if (!this.$refs.multipleTable) return
|
||||||
|
|
||||||
|
// 先清除所有选择
|
||||||
|
this.$refs.multipleTable.clearSelection()
|
||||||
|
|
||||||
|
// 然后重新选择 selectedMap 中的行
|
||||||
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
@ -204,8 +225,10 @@ export default {
|
||||||
this.visible = false
|
this.visible = false
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 在弹窗组件中修改 handleClose 方法
|
||||||
handleClose() {
|
handleClose() {
|
||||||
this.selectedMap.clear()
|
// 不要清空 selectedMap,保留选中状态以便下次打开时使用
|
||||||
|
this.visible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -348,20 +348,34 @@ export default {
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
// 在主页面中修改 handleDelete 方法
|
||||||
handleDelete(row) {
|
handleDelete(row) {
|
||||||
this.$confirm('确定删除该条数据?', '提示', { type: 'warning' }).then(() => {
|
this.$confirm('确定删除该条数据?', '提示', { type: 'warning' }).then(() => {
|
||||||
this.tableList = this.tableList.filter(item => item.keyId !== row.keyId)
|
this.tableList = this.tableList.filter(item => item.keyId !== row.keyId)
|
||||||
|
|
||||||
|
// 强制同步到弹窗的 selectedMap
|
||||||
if (this.$refs.addNum) {
|
if (this.$refs.addNum) {
|
||||||
const dialog = this.$refs.addNum
|
const dialog = this.$refs.addNum
|
||||||
dialog.selectedMap.delete(row.keyId)
|
dialog.selectedMap.delete(row.keyId)
|
||||||
|
|
||||||
|
// 如果弹窗可见,也需要更新弹窗的表格显示
|
||||||
|
if (dialog.visible) {
|
||||||
dialog.tableList = dialog.tableList.filter(item => item.keyId !== row.keyId)
|
dialog.tableList = dialog.tableList.filter(item => item.keyId !== row.keyId)
|
||||||
dialog.$nextTick(() => dialog.restoreSelection())
|
dialog.$nextTick(() => dialog.restoreSelection())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.total = this.tableList.length
|
this.total = this.tableList.length
|
||||||
this.$message.success('删除成功')
|
this.$message.success('删除成功')
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleNumDialog() { if (this.$refs.addNum) this.$refs.addNum.openDialog(this.queryParams.applyId) },
|
// 在主页面中修改
|
||||||
|
handleNumDialog() {
|
||||||
|
if (this.$refs.addNum) {
|
||||||
|
// 将当前表格数据传递给弹窗,确保选中状态一致
|
||||||
|
this.$refs.addNum.openDialog(this.queryParams.applyId, this.tableList)
|
||||||
|
}
|
||||||
|
},
|
||||||
handleAddFromDialog(rows) {
|
handleAddFromDialog(rows) {
|
||||||
if (!rows || rows.length === 0) return
|
if (!rows || rows.length === 0) return
|
||||||
const existingKeys = new Set(this.tableList.map(item => item.keyId))
|
const existingKeys = new Set(this.tableList.map(item => item.keyId))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue