SelectUser.vue
3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<script>
import { getTree, getList } from '@/api/organization'
import { createUniqueString } from '@/utils'
export default {
name: 'SelectUser',
components: {},
props: {
// 添加标签显隐
visible: {
type: Boolean,
default: false,
},
title: {
type: String,
default: '选择成员',
},
// 是否 只选择叶子节点(人员节点)/禁止选择父节点(部门节点)
isOnlyLeaf: {
type: Boolean,
default: true,
},
},
data() {
let isOnlyLeaf = this.isOnlyLeaf
return {
treeData: [],
userList: [],
defaultProps: {
label: 'name',
children: 'children',
disabled(data, node) {
return isOnlyLeaf && !data.userId
},
isLeaf(data, node) {
return !!data.userId
},
},
}
},
watch: {},
computed: {
Pvisible: {
get() {
// this.getTree();
return this.visible
},
set(val) {
this.$emit('update:visible', val)
},
},
},
created() {},
mounted() {},
methods: {
loadNode(node, resolve) {
if (node.level === 0) {
this.userList = []
getTree().then(({ data }) => {
data.forEach((element) => {
element.key = createUniqueString()
})
let _data = this.handleTree(data)
console.log('d', data)
resolve(_data)
// api.getList({ department: _data[0].id }).then(({ rows, total }) => {
// _data && rows.unshift(..._data);
// resolve(rows);
// });
})
} else {
getList({ department: node.data.id }).then(({ rows }) => {
rows.forEach((element) => {
element.key = createUniqueString()
})
node.data.children && rows.push(...node.data.children)
resolve(rows)
})
}
},
handleCheckChange(data, checked, indeterminate) {
checked
? this.userList.push(data)
: this.userList.splice(this.userList.indexOf(data), 1)
// console.log(data, checked, indeterminate);
},
submit() {
this.Pvisible = false
this.$emit('success', this.userList)
},
cancle(key) {
this.$refs.tree.setChecked(key, false)
},
},
}
</script>
setChecked
<template>
<el-dialog :title="title" :visible.sync="Pvisible">
<el-row :gutter="20">
<!--部门数据-->
<el-col :span="12" :xs="24">
<div class="head-container">
<!-- <div>部门架构</div> -->
<!-- :filter-node-method="filterNode" -->
<el-tree
node-key="key"
ref="tree"
lazy
accordion
show-checkbox
check-on-click-node
:expand-on-click-node="true"
:load="loadNode"
:props="defaultProps"
:check-strictly="!isOnlyLeaf"
@check-change="handleCheckChange"
></el-tree>
</div>
</el-col>
<!--用户数据-->
<el-col :span="12" :xs="24" class="user-list">
<el-row :gutter="10">选择人员列表</el-row>
<el-row v-for="(item, index) in userList" :key="index">
<i class="el-icon-user-solid"></i>
{{ item.name }}
<i
class="el-icon-minus fr cp"
title="取消选择"
@click="cancle(item.key)"
></i>
</el-row>
</el-col>
</el-row>
<div slot="footer">
<el-button @click="Pvisible = false">取 消</el-button>
<el-button type="primary" @click="submit">确 定</el-button>
</div>
</el-dialog>
</template>
<style lang="scss" scoped>
.user-list {
.el-row {
line-height: 26px;
}
}
</style>