组织管理调整

This commit is contained in:
fan 2021-04-01 09:59:01 +08:00
parent 0253e6e590
commit f327889bca

View File

@ -1,5 +1,6 @@
<template>
<div>
<el-button type="text" style="position: fixed;right: 20px;top: 70px;" @click="back">返回</el-button>
<el-card style="width: 80%;margin: 20px auto 10px;padding: 10px 10px 20px;">
<div slot="header">
<el-input
@ -13,11 +14,13 @@
ref="tree"
style="width: 500px;margin: 20px 10px 0;"
:data="treeData"
:default-expanded-keys="expandedKeys"
:default-expanded-keys="defaultExpandedKeys"
node-key="keyId"
:props="defaultProps"
:node-expand="nodeExpand"
:auto-expand-parent="false"
:filter-node-method="filterNode"
@node-expand="nodeExpand"
@node-collapse="nodeCollapse"
>
<span slot-scope="{ node, data }" class="custom-tree-node">
<span>{{ node.data.name }}</span>
@ -38,6 +41,7 @@
<script>
import { getOrgTreeById, deleteDepartUserRelation } from '@/api/company';
import localStore from 'storejs';
export default {
name: 'OrgDetail',
@ -49,7 +53,8 @@ export default {
children: 'children',
label: 'data'
},
expandedKeys: []
expandedKeys: [],
defaultExpandedKeys: []
};
},
watch: {
@ -60,13 +65,15 @@ export default {
mounted() {
this.initData();
},
beforeDestroy() {
localStore.set('orgDetail-treeKey-' + this.$route.query.orgId, this.expandedKeys);
},
methods: {
initData() {
getOrgTreeById(this.$route.query.orgId).then(resp => {
this.treeData = [];
this.treeData[0] = { ...(resp.data.data || {}), keyId: (resp.data.data || {}).id, type: resp.data.type, children: resp.data.children || [] };
const temKey1 = (resp.data.data || {}).id;
this.expandedKeys = [temKey1];
this.treeData[0].children.forEach( (item, index1) => {
const tem1 = { ...(item.data || {}), keyId: temKey1 + item.type + (item.data.id || item.data.userId), type: item.type, children: item.children || [] };
const temKey2 = temKey1 + item.type + (item.data.id || item.data.userId);
@ -76,23 +83,42 @@ export default {
this.treeData[0].children[index1].children[index2] = tem2;
});
});
const defaultNode = localStore.get('orgDetail-treeKey-' + this.$route.query.orgId);
if (defaultNode && defaultNode.length) {
this.defaultExpandedKeys = [...defaultNode];
this.expandedKeys = [...defaultNode];
} else {
this.defaultExpandedKeys = [temKey1];
this.expandedKeys = [temKey1];
}
}).catch(error => {
this.$message.error('获取组织结构失败:' + error.message);
});
},
filterNode(value, data, node) {
if (!value) return true;
return data.data.name.indexOf(value) !== -1 || this.checkParent(value, node);
return data.name.indexOf(value) !== -1 || this.checkParent(value, node);
},
checkParent(value, node) {
if (node.parent && node.parent.data && node.parent.data.data) {
return node.parent.data.data.name.indexOf(value) !== -1 || this.checkParent(value, node.parent);
if (node.parent) {
return (node.parent.data && node.parent.data.name && node.parent.data.name.indexOf(value) !== -1) || this.checkParent(value, node.parent);
} else {
return false;
}
},
nodeExpand(obj, node, ele) {
console.log(obj, node, ele);
this.expandedKeys.push(obj.keyId);
console.log(this.expandedKeys, obj);
},
nodeCollapse(obj, node, ele) {
const index = this.expandedKeys.indexOf(obj.keyId);
if (index !== -1) {
this.expandedKeys.splice(index, 1);
}
console.log(this.expandedKeys, index);
},
back() {
this.$router.go(-1);
},
remove(node, data) {
const _that = this;