forked from github/dataease
feat: 解决组织机构树懒加载回显问题
This commit is contained in:
parent
6d8158ffbe
commit
638ecb9bb2
@ -87,7 +87,7 @@
|
|||||||
:load-options="loadDepts"
|
:load-options="loadDepts"
|
||||||
:options="depts"
|
:options="depts"
|
||||||
style="width: 370px;"
|
style="width: 370px;"
|
||||||
placeholder="选择上级类目"
|
placeholder="选择上级类目"
|
||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
@ -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,17 +183,51 @@ 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;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
initTableData(row, treeNode, resolve) {
|
initTableData(row, treeNode, resolve) {
|
||||||
let _self = this;
|
let _self = this;
|
||||||
@ -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 {
|
|||||||
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 {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user