|
|
@@ -217,15 +217,13 @@
|
|
|
try {
|
|
|
this.treeLoading = true;
|
|
|
|
|
|
- const res = null;
|
|
|
- if (this.code) {
|
|
|
- res = await getProduceTreeByCode(this.code);
|
|
|
- } else {
|
|
|
- res = await getTreeByPid(this.type);
|
|
|
- }
|
|
|
+ const res = await getTreeByPid(this.type);
|
|
|
|
|
|
this.treeLoading = false;
|
|
|
this.treeList = res.data;
|
|
|
+ if (this.code) {
|
|
|
+ this.treeList = this.filterTreeByCode(this.treeList, this.code);
|
|
|
+ }
|
|
|
this.$nextTick(() => {
|
|
|
// 默认高亮第一级树节点
|
|
|
if (this.treeList[0]) {
|
|
|
@@ -238,6 +236,21 @@
|
|
|
} catch (error) {}
|
|
|
this.treeLoading = false;
|
|
|
},
|
|
|
+ /* 递归过滤树节点 */
|
|
|
+ filterTreeByCode(list, code) {
|
|
|
+ return list.reduce((acc, node) => {
|
|
|
+ if (node.code === code) {
|
|
|
+ acc.push(node);
|
|
|
+ } else if (node.children && node.children.length) {
|
|
|
+ const filteredChildren = this.filterTreeByCode(node.children, code);
|
|
|
+ if (filteredChildren.length) {
|
|
|
+ acc.push({ ...node, children: filteredChildren });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return acc;
|
|
|
+ }, []);
|
|
|
+ },
|
|
|
+
|
|
|
/* 刷新表格 */
|
|
|
reload(where) {
|
|
|
this.$refs.table.reload({ page: 1, where });
|