|
@ -143,12 +143,56 @@ export default { |
|
|
// } |
|
|
// } |
|
|
// return true |
|
|
// return true |
|
|
// }, |
|
|
// }, |
|
|
|
|
|
// 逆归实现 获取指定元素 |
|
|
|
|
|
findNode(tree, func) { |
|
|
|
|
|
for (const node of tree) { |
|
|
|
|
|
if (func(node)) return node |
|
|
|
|
|
if (node.children) { |
|
|
|
|
|
const res = this.findNode(node.children, func) |
|
|
|
|
|
if (res) return res |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null |
|
|
|
|
|
}, |
|
|
|
|
|
// 展开选中的父级 |
|
|
|
|
|
expandParents(node) { |
|
|
|
|
|
node.expanded = true |
|
|
|
|
|
if (node.parent) { |
|
|
|
|
|
this.expandParents(node.parent) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
[CRUD.HOOK.afterRefresh]() { |
|
|
|
|
|
let currentKey |
|
|
|
|
|
if (localStorage.getItem('currentCategoryKey')) { |
|
|
|
|
|
currentKey = JSON.parse(localStorage.getItem('currentCategoryKey')) |
|
|
|
|
|
} else { |
|
|
|
|
|
if (this.crud.data[0].isType === 1) { |
|
|
|
|
|
currentKey = this.findNode(this.crud.data[0].children, (node) => { |
|
|
|
|
|
return node.isType !== 1 |
|
|
|
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
currentKey = this.crud.data[0] |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
// 设置某个节点的当前选中状态 |
|
|
|
|
|
this.$refs.tree.setCurrentKey(currentKey.id) |
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
|
// 设置某个节点的父级展开 |
|
|
|
|
|
const selectedKey = this.$refs.tree.getCurrentNode() |
|
|
|
|
|
if (this.$refs.tree.getNode(selectedKey) && this.$refs.tree.getNode(selectedKey).parent) { |
|
|
|
|
|
this.expandParents(this.$refs.tree.getNode(selectedKey).parent) |
|
|
|
|
|
} |
|
|
|
|
|
// 选中节点的门类详情 |
|
|
|
|
|
this.handleNodeClick(selectedKey) |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
// 选中门类后,设置门类详情数据 |
|
|
// 选中门类后,设置门类详情数据 |
|
|
handleNodeClick(val) { |
|
|
handleNodeClick(val) { |
|
|
if (val) { |
|
|
if (val) { |
|
|
this.crud.selectionChangeHandler([val]) |
|
|
this.crud.selectionChangeHandler([val]) |
|
|
this.$refs.eform.pid = val.id |
|
|
this.$refs.eform.pid = val.id |
|
|
this.selectedCategory = val |
|
|
this.selectedCategory = val |
|
|
|
|
|
localStorage.setItem('currentCategoryKey', JSON.stringify(val)) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
updateKeyChildren(data) { |
|
|
updateKeyChildren(data) { |
|
|