From d6a44fbb088016ad62485297886a5b4e5c407ec3 Mon Sep 17 00:00:00 2001 From: hayu <1604366271@qq.com> Date: Sun, 16 Nov 2025 22:01:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E4=BF=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repairApply/SelectToolDialog.vue | 43 ++++++++++++++----- .../equipmentRepair/repairApply/addRepair.vue | 20 +++++++-- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/views/equipmentRepair/repairApply/SelectToolDialog.vue b/src/views/equipmentRepair/repairApply/SelectToolDialog.vue index bec770c4..e47cbd2d 100644 --- a/src/views/equipmentRepair/repairApply/SelectToolDialog.vue +++ b/src/views/equipmentRepair/repairApply/SelectToolDialog.vue @@ -95,10 +95,20 @@ export default { }, methods: { - openDialog(applyId) { + // 在 SelectToolDialog.vue 中修改 openDialog 方法 + openDialog(applyId, externalSelectedRows = []) { this.applyId = applyId 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) { @@ -133,23 +143,26 @@ export default { this.tableList = rows.map(item => { const key = item.keyId - const selected = this.selectedMap.get(key) const isCodeManage = item.manageMode === "编码管理" return { ...item, - keyId: key, // ⭐ 统一 row-key 与 selectedMap key - repairNum: selected ? selected.repairNum : isCodeManage ? 1 : "" + keyId: key, + repairNum: selected ? selected.repairNum : (isCodeManage ? 1 : "") } }) - // 过滤 selectedMap,只保留 tableList 中存在的 keyId + + // 清理 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) + if (!tableKeys.has(key)) { + this.selectedMap.delete(key) + } }) + this.$nextTick(() => { - if (this.restoreSelection) this.restoreSelection() + this.restoreSelection() }) } finally { @@ -157,11 +170,19 @@ export default { } }, + // 在弹窗组件中添加 restoreSelection() { if (!this.$refs.multipleTable) return + + // 先清除所有选择 + this.$refs.multipleTable.clearSelection() + + // 然后重新选择 selectedMap 中的行 this.tableList.forEach(row => { if (this.selectedMap.has(row.keyId)) { - this.$refs.multipleTable.toggleRowSelection(row, true) + this.$nextTick(() => { + this.$refs.multipleTable.toggleRowSelection(row, true) + }) } }) }, @@ -204,8 +225,10 @@ export default { this.visible = false }, + // 在弹窗组件中修改 handleClose 方法 handleClose() { - this.selectedMap.clear() + // 不要清空 selectedMap,保留选中状态以便下次打开时使用 + this.visible = false } } } diff --git a/src/views/equipmentRepair/repairApply/addRepair.vue b/src/views/equipmentRepair/repairApply/addRepair.vue index 4fdfad36..e60bcc2a 100644 --- a/src/views/equipmentRepair/repairApply/addRepair.vue +++ b/src/views/equipmentRepair/repairApply/addRepair.vue @@ -348,20 +348,34 @@ export default { this.isLoading = false } }, +// 在主页面中修改 handleDelete 方法 handleDelete(row) { this.$confirm('确定删除该条数据?', '提示', { type: 'warning' }).then(() => { this.tableList = this.tableList.filter(item => item.keyId !== row.keyId) + + // 强制同步到弹窗的 selectedMap if (this.$refs.addNum) { const dialog = this.$refs.addNum dialog.selectedMap.delete(row.keyId) - dialog.tableList = dialog.tableList.filter(item => item.keyId !== row.keyId) - dialog.$nextTick(() => dialog.restoreSelection()) + + // 如果弹窗可见,也需要更新弹窗的表格显示 + if (dialog.visible) { + dialog.tableList = dialog.tableList.filter(item => item.keyId !== row.keyId) + dialog.$nextTick(() => dialog.restoreSelection()) + } } + this.total = this.tableList.length 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) { if (!rows || rows.length === 0) return const existingKeys = new Set(this.tableList.map(item => item.keyId))