|
@@ -18,13 +18,15 @@
|
|
|
:data="data"
|
|
|
show-checkbox
|
|
|
accordion
|
|
|
- @node-expand="getChildrenNode"
|
|
|
+ :props="props"
|
|
|
+ :load="loadNode"
|
|
|
+ lazy
|
|
|
@check-change="allSelectNode"
|
|
|
:indent="50"
|
|
|
ref="tree"
|
|
|
node-key="id">
|
|
|
- <span class="custom-tree-node" slot-scope="{ node,data }">
|
|
|
- <span>{{ node.label }}</span>
|
|
|
+ <span class="custom-tree-node" slot-scope="{ data }">
|
|
|
+ <span>{{ data.label }}</span>
|
|
|
<span>{{ data.aname || "--" }}</span><span>{{ data.user_count }}</span><span @click.stop="addDepart('edit',data)">编辑</span>
|
|
|
</span>
|
|
|
</el-tree>
|
|
@@ -72,7 +74,7 @@
|
|
|
|
|
|
<label>
|
|
|
<span>设置管理员:</span>
|
|
|
- <el-input v-model="userMsg.name" placeholder="请选择管理员"></el-input>
|
|
|
+ <el-input v-model="userMsg.name" placeholder="请选择管理员" readonly @focus="chooseUserFc"></el-input>
|
|
|
</label>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -83,7 +85,17 @@
|
|
|
</template>
|
|
|
</add-drawer>
|
|
|
<!-- 删除弹窗 -->
|
|
|
- <del-popup></del-popup>
|
|
|
+ <del-popup ref="childDel" title="删除部门">
|
|
|
+ <template slot="content">
|
|
|
+ <p v-if="delDepartObj.status === 'all'">
|
|
|
+ <span v-for="(item) in deal_selectDepart" :key="item.id">{{item.bname}}</span>
|
|
|
+ </p>
|
|
|
+ <p v-else> {{currentVal.label}} </p>
|
|
|
+ </template>
|
|
|
+ <template slot="del">
|
|
|
+ <button @click="del_Btn" class="del">删除</button>
|
|
|
+ </template>
|
|
|
+ </del-popup>
|
|
|
|
|
|
<!-- //选择人员 -->
|
|
|
<choose-user ref="selectUser"></choose-user>
|
|
@@ -92,7 +104,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { entinfo,componyList,addDepartInter,departDetail,departUpdata , delDepartInter} from '@/api/api';
|
|
|
+import { componyMsg,componyList,addDepartInter,departDetail,departUpdata , delDepartInter} from '@/api/api';
|
|
|
import addDrawer from "./addDrawer";
|
|
|
import delPopup from "./del"
|
|
|
import chooseUser from "./chooseUser"
|
|
@@ -103,20 +115,48 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
data: [],
|
|
|
+ props: {
|
|
|
+ label: 'name',
|
|
|
+ children: 'zones',
|
|
|
+ isLeaf: 'leaf'
|
|
|
+ },
|
|
|
ruleForm: {
|
|
|
name: '',
|
|
|
},
|
|
|
- companyData:{},
|
|
|
+ companyData:{departments:[]},
|
|
|
whichPart:'add',//add: 添加 edit: 编辑
|
|
|
- currentId:'',
|
|
|
+ currentVal:'',
|
|
|
selectDepart:[],
|
|
|
+ companyId:'',
|
|
|
+ delDepartObj:{
|
|
|
+ id:'',
|
|
|
+ status,
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
|
- entinfo().then(res => {});
|
|
|
- this.getOutData();
|
|
|
+ componyMsg().then(function(res){
|
|
|
+ return res
|
|
|
+ }).then(val =>{
|
|
|
+ this.$store.commit("entIdFun",val.data.dept_id)
|
|
|
+ this.companyId = val.data.dept_id;
|
|
|
+ this.getOutData();
|
|
|
+ })
|
|
|
},
|
|
|
computed:{
|
|
|
+ deal_selectDepart:function(index){
|
|
|
+ let [...arr] = this.selectDepart
|
|
|
+
|
|
|
+ arr.forEach((v,i) =>{
|
|
|
+ if(i !== 0){
|
|
|
+ v.bname = `,${v.label}`
|
|
|
+ }else{
|
|
|
+ v.bname = `${v.label}`
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log(arr,this.selectDepart)
|
|
|
+ return arr;
|
|
|
+ },
|
|
|
companyMsg:function(){
|
|
|
let newObj ={role:'',num:''};
|
|
|
this.companyData.persons && this.companyData.persons.forEach((v,i) =>{
|
|
@@ -145,7 +185,7 @@ export default {
|
|
|
methods: {
|
|
|
//dom tree 外层部门数据
|
|
|
getOutData(){
|
|
|
- componyList({id:2608}).then(res =>{
|
|
|
+ componyList({id:this.companyId}).then(res =>{
|
|
|
this.companyData = res.data;
|
|
|
let arr = this.dataHandling(this.companyData.departments)
|
|
|
this.data = JSON.parse(JSON.stringify(arr));
|
|
@@ -156,15 +196,15 @@ export default {
|
|
|
dataHandling(list){
|
|
|
let arr = [];
|
|
|
list.map((el,i) =>{
|
|
|
+ let leaf;
|
|
|
+ el.dept_count > 0 ? leaf = false : leaf = true;
|
|
|
arr.push({
|
|
|
id:el.id,
|
|
|
label:el.name,
|
|
|
+ leaf,
|
|
|
user_count:el.user_count ,
|
|
|
aname:el.aname,
|
|
|
})
|
|
|
- if(el.dept_count>0){
|
|
|
- arr[i] = Object.assign({children:[{}]},arr[i])
|
|
|
- }
|
|
|
})
|
|
|
return arr;
|
|
|
},
|
|
@@ -172,12 +212,20 @@ export default {
|
|
|
allSelectNode(){
|
|
|
this.selectDepart = this.$refs.tree.getCheckedNodes();
|
|
|
},
|
|
|
+ //初始化部门添加
|
|
|
+ initDepart(){
|
|
|
+ this.ruleForm.name = '';
|
|
|
+ this.departMsg.name = '';
|
|
|
+ this.departMsg.id = '';
|
|
|
+ this.userMsg.name = '';
|
|
|
+ this.userMsg.id = '';
|
|
|
+ },
|
|
|
//添加、编辑部门
|
|
|
addDepart(status,val){
|
|
|
this.whichPart = status;
|
|
|
this.$refs.addDrewer.openDrawer();
|
|
|
if(status === 'edit'){
|
|
|
- this.currentId = val.id;
|
|
|
+ this.currentVal = val;
|
|
|
departDetail({id:val.id}).then(res =>{
|
|
|
this.ruleForm.name = res.data.name;
|
|
|
this.departMsg.name = res.data.pname;
|
|
@@ -192,17 +240,25 @@ export default {
|
|
|
console.log(this.departMsg)
|
|
|
if(this.whichPart === "add"){
|
|
|
addDepartInter({name:this.ruleForm.name,pid:this.departMsg.id,aid:this.userMsg.id}).then(res =>{
|
|
|
- if(res.error_code == 0){
|
|
|
- this.$refs.addDrewer.drawer = false;
|
|
|
+ this.initDepart();
|
|
|
+ if(res.data.status == 1){
|
|
|
+ this.$message({message: '添加成功',type: 'success'});
|
|
|
this.getOutData();
|
|
|
+ }else{
|
|
|
+ this.$message({message: '添加失败',type: 'success'});
|
|
|
}
|
|
|
+ this.$refs.addDrewer.drawer = false;
|
|
|
})
|
|
|
}else{
|
|
|
- departUpdata({name:this.ruleForm.name,pid:this.departMsg.id,aid:this.userMsg.id,id:this.currentId}).then(res =>{
|
|
|
- if(res.error_code == 0){
|
|
|
- this.$refs.addDrewer.drawer = false;
|
|
|
+ departUpdata({name:this.ruleForm.name,pid:this.departMsg.id,aid:this.userMsg.id,id:this.currentVal.id}).then(res =>{
|
|
|
+ this.initDepart();
|
|
|
+ if(res.data.status == 1){
|
|
|
+ this.$message({message: '修改成功',type: 'success'});
|
|
|
this.getOutData();
|
|
|
+ }else{
|
|
|
+ this.$message({message: '修改失败',type: 'success'});
|
|
|
}
|
|
|
+ this.$refs.addDrewer.drawer = false;
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -214,17 +270,20 @@ export default {
|
|
|
if(status === 'all'){
|
|
|
this.selectDepart.forEach((v,i) =>{
|
|
|
if(v.id){
|
|
|
- if(i === 0){
|
|
|
- delId += `${v.id}`
|
|
|
- }else{
|
|
|
- delId += `,${v.id}`
|
|
|
- }
|
|
|
+ i === 0 ? delId += `${v.id}` : delId += `,${v.id}`
|
|
|
}
|
|
|
})
|
|
|
}else{
|
|
|
- delId = this.currentId;
|
|
|
+ delId = this.currentVal.id;
|
|
|
}
|
|
|
- delDepartInter({id:delId}).then(res =>{
|
|
|
+ this.delDepartObj.id = delId;
|
|
|
+ this.delDepartObj.status = status;
|
|
|
+ this.$refs.childDel.dialogTableVisible = true;
|
|
|
+ },
|
|
|
+ //确认删除部门
|
|
|
+ del_Btn(){
|
|
|
+ delDepartInter({id:this.delDepartObj.id}).then(res =>{
|
|
|
+ this.$refs.childDel.dialogTableVisible = false;
|
|
|
if(res.data.status == 1){
|
|
|
this.getOutData();
|
|
|
this.$message({ message: '删除成功',type: 'success'});
|
|
@@ -240,15 +299,17 @@ export default {
|
|
|
},
|
|
|
//选择管理员
|
|
|
chooseUserFc(){
|
|
|
- this.$refs.selectUser.centerDialogVisible = true;
|
|
|
+ this.$refs.selectUser.centerDialogVisible = true;
|
|
|
+ this.$refs.selectUser.choosePersonInit();
|
|
|
},
|
|
|
- //获取子级部门
|
|
|
- getChildrenNode(data) {
|
|
|
- componyList({id:data.id}).then(res =>{
|
|
|
+ // Tree懒加载
|
|
|
+ loadNode(node,resolve){
|
|
|
+ if(!node.data.id) return;
|
|
|
+ componyList({id:node.data.id}).then(res =>{
|
|
|
let arr = this.dataHandling(res.data.departments);
|
|
|
- this.$set(data, 'children', arr);
|
|
|
+ resolve(arr);
|
|
|
})
|
|
|
- },
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
@@ -384,7 +445,12 @@ export default {
|
|
|
.custom-tree-node{
|
|
|
flex: 1;
|
|
|
display: flex;
|
|
|
+ align-items: center;
|
|
|
+ height: 100%;
|
|
|
>span{
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ height: 100%;
|
|
|
font-size: 14px;
|
|
|
color: $normal_color;
|
|
|
&:first-child{
|
|
@@ -396,6 +462,7 @@ export default {
|
|
|
&:nth-child(4){
|
|
|
width: 120px;
|
|
|
color: $light_color;
|
|
|
+ cursor: pointer;
|
|
|
}
|
|
|
}
|
|
|
}
|