index.vue
3.96 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
<template>
<div class="transfer__body" v-loading="allLoading"
:element-loading-text="$t('common.loadingText')" :style="{height}">
<div class="transfer-pane">
<div class="transfer-pane__tools">
<el-input placeholder="输入关键词进行搜索" v-model="keyword">
<el-button slot="append" icon="el-icon-search" @click="getList"></el-button>
</el-input>
</div>
<div class="transfer-pane__body">
<el-tree :data="treeData" :props="props" highlight-current :expand-on-click-node="false"
check-on-click-node @node-click="handleNodeClick" class="NCC-common-el-tree"
node-key="id" v-loading="loading" lazy :load="loadNode">
<span class="custom-tree-node" slot-scope="{ node, data }">
<i :class="data.icon"></i>
<span class="text">{{node.label}}</span>
</span>
</el-tree>
</div>
</div>
<div class="transfer-pane">
<div class="transfer-pane__tools">
<span>已选</span>
<el-button @click="removeAll" type="text">清空列表</el-button>
</div>
<div class="transfer-pane__body shadow right-pane">
<template>
<div v-for="(item, index) in selectedData" :key=" index" class="selected-item">
<span>{{ item.fullName}}</span>
<i class="el-icon-delete" @click="removeData(index)"></i>
</div>
</template>
</div>
</div>
</div>
</template>
<script>
import { getImUserSelector, getUserInfoList } from '@/api/permission/user'
export default {
name: 'NCC-userTransfer',
data() {
return {
allLoading: false,
loading: false,
treeData: [],
selectedData: [],
props: {
children: 'children',
label: 'fullName',
isLeaf: 'isLeaf'
},
keyword: '',
nodeId: '0',
ids: []
}
},
props: {
height: {
type: String,
default: "380px"
},
// allLoading: {
// type: Boolean,
// default: false
// },
value: {
type: Array,
default: () => []
},
multiple: {
type: Boolean,
default: false
},
},
methods: {
init() {
this.selectedData = []
this.ids = []
this.keyword = ''
this.nodeId = '0'
this.$nextTick(() => {
this.getList()
this.getSelectList()
})
},
getSelectList() {
this.allLoading = true
if (!this.value.length) return this.allLoading = false
getUserInfoList(this.value).then(res => {
this.selectedData = res.data.list
this.ids = this.selectedData.map(o => o.id)
this.allLoading = false
})
},
getList() {
this.loading = true
if (this.keyword) this.nodeId = '0'
getImUserSelector(this.nodeId, this.keyword).then(res => {
this.treeData = res.data.list
this.loading = false
})
},
loadNode(node, resolve) {
if (node.level === 0) {
this.nodeId = '0'
return resolve(this.treeData)
}
this.nodeId = node.data.id
getImUserSelector(this.nodeId).then(res => {
resolve(res.data.list)
})
},
handleNodeClick(data) {
if (data.type !== 'user') return
const boo = this.selectedData.some(o => o.id === data.id)
if (boo) return
const item = {
id: data.id,
fullName: data.fullName
}
this.multiple ? this.selectedData.push(item) : this.selectedData = [item]
this.multiple ? this.ids.push(item.id) : this.ids = [item.id]
this.$emit('input', this.ids)
this.$emit('getValue', this.ids, this.selectedData)
},
removeAll() {
this.selectedData = []
this.ids = []
this.$emit('input', this.ids)
this.$emit('getValue', this.ids, this.selectedData)
},
removeData(index) {
this.selectedData.splice(index, 1)
this.ids.splice(index, 1)
this.$emit('input', this.ids)
this.$emit('getValue', this.ids, this.selectedData)
},
}
};
</script>