Browse Source

BOM复制后,临时表tree结构问题

java8
han\hanst 1 year ago
parent
commit
d52258f8df
  1. 2
      src/views/modules/part/bomSearch3.vue
  2. 36
      src/views/modules/part/copy_bom_modal.vue

2
src/views/modules/part/bomSearch3.vue

@ -50,7 +50,7 @@
<el-table
:height="height"
:data="dataList"
border
border highlight-current-row
ref="bomHeaderTable"
@row-click="headerClickRow"
@current-change="changeCurrentRow"

36
src/views/modules/part/copy_bom_modal.vue

@ -1660,6 +1660,9 @@ export default {
// 刷新树结构
refreshTreeData () {
// 保存当前选中的节点ID,刷新后恢复选中状态
const currentNodeId = this.currentRow ? this.currentRow.id : null
let tempData = {
bomId: this.modalData.bomId,
createBy: this.$store.state.user.name
@ -1670,8 +1673,37 @@ export default {
this.treeData = data.rows
if (this.treeData.length > 0) {
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(this.treeData[0].id)
this.handleNodeClick(this.treeData[0])
// 如果有保存的节点ID,尝试恢复选中该节点
if (currentNodeId) {
// 在新树中查找相同ID的节点
const findNodeById = (nodes, targetId) => {
for (let node of nodes) {
if (node.id === targetId) {
return node
}
if (node.list && node.list.length > 0) {
const found = findNodeById(node.list, targetId)
if (found) return found
}
}
return null
}
const targetNode = findNodeById(this.treeData, currentNodeId)
if (targetNode) {
// 找到了原来的节点,恢复选中
this.$refs.tree.setCurrentKey(targetNode.id)
this.handleNodeClick(targetNode)
} else {
// 没找到,默认选中第一个
this.$refs.tree.setCurrentKey(this.treeData[0].id)
this.handleNodeClick(this.treeData[0])
}
} else {
// 没有保存的节点ID,默认选中第一个
this.$refs.tree.setCurrentKey(this.treeData[0].id)
this.handleNodeClick(this.treeData[0])
}
})
}
this.queryTreeLoading = false

Loading…
Cancel
Save