|
1
|
<template>
|
|
2
|
<j-modal
|
|
3
4
5
|
:width="modalWidth"
:visible="visible"
:title="title"
|
|
6
|
switchFullscreen
|
|
7
8
|
@ok="handleSubmit"
@cancel="close"
|
|
9
|
style="top:50px"
|
|
10
11
12
13
14
15
16
17
|
cancelText="关闭"
>
<a-row :gutter="10" style="background-color: #ececec; padding: 10px; margin: -10px">
<a-col :md="6" :sm="24">
<a-card :bordered="false">
<!--组织机构-->
<a-directory-tree
selectable
|
|
18
|
:selectedKeys="selectedDepIds"
|
|
19
20
21
|
:checkStrictly="true"
:dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
:treeData="departTree"
|
|
22
23
24
|
:expandAction="false"
:expandedKeys.sync="expandedKeys"
@select="onDepSelect"
|
|
25
26
27
28
29
30
31
32
|
/>
</a-card>
</a-col>
<a-col :md="18" :sm="24">
<a-card :bordered="false">
用户账号:
<a-input-search
:style="{width:'150px',marginBottom:'15px'}"
|
|
33
|
placeholder="请输入账号"
|
|
34
35
|
v-model="queryParam.username"
@search="onSearch"
|
|
36
37
|
></a-input-search>
<a-button @click="searchReset(1)" style="margin-left: 20px" icon="redo">重置</a-button>
|
|
38
39
40
41
42
43
44
45
46
|
<!--用户列表-->
<a-table
ref="table"
:scroll="scrollTrigger"
size="middle"
rowKey="id"
:columns="columns"
:dataSource="dataSource"
:pagination="ipagination"
|
|
47
|
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type: getType}"
|
|
48
|
:loading="loading"
|
|
49
50
51
52
53
|
@change="handleTableChange">
</a-table>
</a-card>
</a-col>
</a-row>
|
|
54
|
</j-modal>
|
|
55
56
57
|
</template>
<script>
|
|
58
59
60
|
import {filterObj} from '@/utils/util'
import {queryDepartTreeList, getUserList, queryUserByDepId} from '@/api/api'
|
|
61
|
export default {
|
|
62
|
name: 'JSelectUserByDepModal',
|
|
63
|
components: {},
|
|
64
|
props: ['modalWidth', 'multi', 'userIds'],
|
|
65
66
|
data() {
return {
|
|
67
|
queryParam: {
|
|
68
|
username: "",
|
|
69
|
},
|
|
70
71
72
73
74
75
76
|
columns: [
{
title: '用户账号',
align: 'center',
dataIndex: 'username'
},
{
|
|
77
|
title: '用户姓名',
|
|
78
79
80
81
82
83
84
|
align: 'center',
dataIndex: 'realname'
},
{
title: '性别',
align: 'center',
dataIndex: 'sex',
|
|
85
|
customRender: function (text) {
|
|
86
87
88
89
90
91
92
93
94
95
|
if (text === 1) {
return '男'
} else if (text === 2) {
return '女'
} else {
return text
}
}
},
{
|
|
96
|
title: '手机',
|
|
97
98
99
100
|
align: 'center',
dataIndex: 'phone'
},
{
|
|
101
|
title: '部门',
|
|
102
|
align: 'center',
|
|
103
|
dataIndex: 'orgCode'
|
|
104
105
106
107
|
}
],
scrollTrigger: {},
dataSource: [],
|
|
108
109
110
|
selectedRowKeys: [],
selectUserRows: [],
selectUserIds: [],
|
|
111
|
title: '根据部门选择用户',
|
|
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
ipagination: {
current: 1,
pageSize: 10,
pageSizeOptions: ['10', '20', '30'],
showTotal: (total, range) => {
return range[0] + '-' + range[1] + ' 共' + total + '条'
},
showQuickJumper: true,
showSizeChanger: true,
total: 0
},
isorter: {
column: 'createTime',
order: 'desc'
},
|
|
127
|
selectedDepIds: [],
|
|
128
129
|
departTree: [],
visible: false,
|
|
130
131
132
|
form: this.$form.createForm(this),
loading: false,
expandedKeys: [],
|
|
133
134
|
}
},
|
|
135
136
137
138
139
140
141
|
computed: {
// 计算属性的 getter
getType: function () {
return this.multi == true ? 'checkbox' : 'radio';
}
},
watch: {
|
|
142
143
144
145
146
147
|
userIds: {
immediate: true,
handler() {
this.initUserNames()
}
},
|
|
148
|
},
|
|
149
150
151
|
created() {
// 该方法触发屏幕自适应
this.resetScreenSize();
|
|
152
|
this.loadData()
|
|
153
154
|
},
methods: {
|
|
155
156
|
initUserNames() {
if (this.userIds) {
|
|
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
// 这里最后加一个 , 的原因是因为无论如何都要使用 in 查询,防止后台进行了模糊匹配,导致查询结果不准确
let values = this.userIds.split(',') + ','
getUserList({
username: values,
pageNo: 1,
pageSize: values.length
}).then((res) => {
if (res.success) {
let selectedRowKeys = []
let realNames = []
res.result.records.forEach(user => {
realNames.push(user['realname'])
selectedRowKeys.push(user['id'])
})
this.selectedRowKeys = selectedRowKeys
this.$emit('initComp', realNames.join(','))
|
|
173
|
}
|
|
174
175
|
})
} else {
|
|
176
|
// JSelectUserByDep组件bug issues/I16634
|
|
177
|
this.$emit('initComp', '')
|
|
178
179
180
|
}
},
async loadData(arg) {
|
|
181
182
183
|
if (arg === 1) {
this.ipagination.current = 1;
}
|
|
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
if (this.selectedDepIds && this.selectedDepIds.length > 0) {
await this.initQueryUserByDepId(this.selectedDepIds)
} else {
this.loading = true
let params = this.getQueryParams()//查询条件
await getUserList(params).then((res) => {
if (res.success) {
this.dataSource = res.result.records
this.ipagination.total = res.result.total
}
}).finally(() => {
this.loading = false
})
}
|
|
198
199
200
201
202
|
},
// 触发屏幕自适应
resetScreenSize() {
let screenWidth = document.body.clientWidth;
if (screenWidth < 500) {
|
|
203
|
this.scrollTrigger = {x: 800};
|
|
204
205
206
207
208
209
210
|
} else {
this.scrollTrigger = {};
}
},
showModal() {
this.visible = true;
this.queryDepartTree();
|
|
211
|
this.initUserNames()
|
|
212
|
this.loadData();
|
|
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
this.form.resetFields();
},
getQueryParams() {
let param = Object.assign({}, this.queryParam, this.isorter);
param.field = this.getQueryField();
param.pageNo = this.ipagination.current;
param.pageSize = this.ipagination.pageSize;
return filterObj(param);
},
getQueryField() {
let str = 'id,';
for (let a = 0; a < this.columns.length; a++) {
str += ',' + this.columns[a].dataIndex;
}
return str;
},
searchReset(num) {
let that = this;
|
|
231
|
if (num !== 0) {
|
|
232
233
|
that.queryParam = {};
that.loadData(1);
|
|
234
235
|
}
that.selectedRowKeys = [];
|
|
236
237
|
that.selectUserIds = [];
that.selectedDepIds = [];
|
|
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
},
close() {
this.searchReset(0);
this.visible = false;
},
handleTableChange(pagination, filters, sorter) {
//TODO 筛选
if (Object.keys(sorter).length > 0) {
this.isorter.column = sorter.field;
this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc';
}
this.ipagination = pagination;
this.loadData();
},
handleSubmit() {
let that = this;
|
|
254
255
256
|
this.getSelectUserRows();
that.$emit('ok', that.selectUserRows, that.selectUserIds);
that.searchReset(0)
|
|
257
258
|
that.close();
},
|
|
259
260
|
//获取选择用户信息
getSelectUserRows(rowId) {
|
|
261
|
let dataSource = this.dataSource;
|
|
262
263
|
let userIds = "";
this.selectUserRows = [];
|
|
264
|
for (let i = 0, len = dataSource.length; i < len; i++) {
|
|
265
266
267
|
if (this.selectedRowKeys.includes(dataSource[i].id)) {
this.selectUserRows.push(dataSource[i]);
userIds = userIds + "," + dataSource[i].username
|
|
268
269
|
}
}
|
|
270
|
this.selectUserIds = userIds.substring(1);
|
|
271
272
|
},
// 点击树节点,筛选出对应的用户
|
|
273
274
275
276
277
|
onDepSelect(selectedDepIds) {
if (selectedDepIds[0] != null) {
this.initQueryUserByDepId(selectedDepIds); // 调用方法根据选选择的id查询用户信息
if (this.selectedDepIds[0] !== selectedDepIds[0]) {
this.selectedDepIds = [selectedDepIds[0]];
|
|
278
279
280
281
282
283
284
285
286
287
288
|
}
}
},
onSelectChange(selectedRowKeys, selectionRows) {
this.selectedRowKeys = selectedRowKeys;
this.selectionRows = selectionRows;
},
onSearch() {
this.loadData(1);
},
// 根据选择的id来查询用户信息
|
|
289
|
initQueryUserByDepId(selectedDepIds) {
|
|
290
291
|
this.loading = true
return queryUserByDepId({id: selectedDepIds.toString()}).then((res) => {
|
|
292
293
294
295
|
if (res.success) {
this.dataSource = res.result;
this.ipagination.total = res.result.length;
}
|
|
296
297
|
}).finally(() => {
this.loading = false
|
|
298
299
300
301
302
303
|
})
},
queryDepartTree() {
queryDepartTreeList().then((res) => {
if (res.success) {
this.departTree = res.result;
|
|
304
305
|
// 默认展开父节点
this.expandedKeys = this.departTree.map(item => item.id)
|
|
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
}
})
},
modalFormOk() {
this.loadData();
}
}
}
</script>
<style scoped>
.ant-table-tbody .ant-table-row td {
padding-top: 10px;
padding-bottom: 10px;
}
#components-layout-demo-custom-trigger .trigger {
font-size: 18px;
line-height: 64px;
padding: 0 24px;
cursor: pointer;
transition: color .3s;
}
</style>
|