提交 638ecb9b authored 作者: fit2cloud-chenyw's avatar fit2cloud-chenyw

feat: 解决组织机构树懒加载回显问题

上级 6d8158ff
...@@ -139,9 +139,8 @@ export default { ...@@ -139,9 +139,8 @@ export default {
data() { data() {
return { return {
rootNodeLoaded: false, rootNodeLoaded: false,
depts:null, depts: null,
formType:"add", formType: "add",
queryPath: '/api/dept/childNodes', queryPath: '/api/dept/childNodes',
deletePath: '/api/dept/delete', deletePath: '/api/dept/delete',
createPath: '/api/dept/create', createPath: '/api/dept/create',
...@@ -184,15 +183,49 @@ export default { ...@@ -184,15 +183,49 @@ export default {
this.formType = "modify"; this.formType = "modify";
this.oldPid = row.pid; this.oldPid = row.pid;
this.form = Object.assign({}, row); this.form = Object.assign({}, row);
// this.treeByRow(row); this.treeByRow(row);
listenGoBack(this.closeFunc); listenGoBack(this.closeFunc);
}, },
treeByRow(row){ treeByRow(row){
!this.depts && (this.depts = []) !this.depts && (this.depts = [])
if (!this.depts.some(node => node.id==row.deptId)) { if (!this.depts.some(node => node.id==row.pid) && row.pid!=0) {
this.depts.push(this.normalizer(row)); const arr = this.mapToArray();
const ids = arr.map(item => item.id);
const tempTreeNodes = this.treeByArr(arr);
const pnodes = this.tableData.filter(node => (node.pid==0) && (ids.indexOf(node.deptId)==-1)).map(node => this.normalizer(node))
const showNodes = tempTreeNodes.concat(pnodes)
this.depts = this.depts.concat(showNodes);
}
},
mapToArray() {
const result = new Array();
this.maps.forEach((value, key) => {
if(value.hasOwnProperty('row')){
result.push(this.editNormalizer(value.row))
} }
})
return result;
},
treeByArr(arr){
if(!Array.isArray(arr) || !arr.length) return;
let map = {};
arr.forEach(item => map[item.id] = item);
let roots = [];
arr.forEach(item => {
const parent = map[item.pid];
if(parent){
(parent.children || (parent.children=[])).push(item);
}
else{
roots.push(item);
}
})
return roots;
}, },
...@@ -222,6 +255,7 @@ export default { ...@@ -222,6 +255,7 @@ export default {
this.initTableData(); this.initTableData();
this.form = {}; this.form = {};
this.oldPid = null; this.oldPid = null;
this.depts = null;
removeGoBackListener(this.closeFunc); removeGoBackListener(this.closeFunc);
this.dialogOrgAddVisible = false; this.dialogOrgAddVisible = false;
...@@ -258,6 +292,14 @@ export default { ...@@ -258,6 +292,14 @@ export default {
children:node.children children:node.children
} }
}, },
editNormalizer(node) {
return {
id: node.deptId,
pid: node.pid,
label: node.name,
children: node.children
}
},
// 改变状态 // 改变状态
changeEnabled(data, val) { changeEnabled(data, val) {
this.$confirm('此操作将 "停用" ' + data.name + '部门, 是否继续?', '提示', { this.$confirm('此操作将 "停用" ' + data.name + '部门, 是否继续?', '提示', {
...@@ -324,7 +366,25 @@ export default { ...@@ -324,7 +366,25 @@ export default {
this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, []); this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, []);
this.initTableData(row, treeNode, resolve); this.initTableData(row, treeNode, resolve);
} }
},
array2Tree(arr){
if(!Array.isArray(arr) || !arr.length) return;
let map = {};
arr.forEach(item => map[item.id] = item);
let roots = [];
arr.forEach(item => {
const parent = map[item.pid];
if(parent){
(parent.children || (parent.children=[])).push(item);
}
else{
roots.push(item);
} }
})
return roots;
}
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论