|
1
2
3
4
5
6
7
8
9
10
|
<template>
<a-modal
:width="modalWidth"
:visible="visible"
title="部门搜索"
:confirmLoading="confirmLoading"
@ok="handleSubmit"
@cancel="handleCancel"
cancelText="关闭"
wrapClassName="ant-modal-cust-warp"
|
|
11
|
>
|
|
12
13
14
|
<!--部门树-->
<template>
<a-form :form="form">
|
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="上级部门">
<a-tree
multiple
treeCheckable="tree"
checkable
@expand="onExpand"
:expandedKeys="expandedKeysss"
:checkedKeys="checkedKeys"
allowClear="true"
:checkStrictly="true"
@check="onCheck"
:dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
:treeData="departTree"
placeholder="请选择上级部门"
>
</a-tree>
</a-form-item>
|
|
32
33
34
35
36
37
|
</a-form>
</template>
</a-modal>
</template>
<script>
|
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
import pick from 'lodash.pick'
import {getAction} from '@/api/manage'
import {queryIdTree} from '@/api/api'
export default {
name: "DepartWindow",
components: {},
data() {
return {
checkedKeys: [], // 存储选中的部门id
expandedKeysss: [],//展开的节点
userId: "", // 存储用户id
model: {}, // 存储SysUserDepartsVO表
userDepartModel: {userId: '', departIdList: []}, // 存储用户id一对多部门信息的对象
departList: [], // 存储部门信息
modalWidth: 400,
departTree: [],
title: "操作",
visible: false,
labelCol: {
xs: {span: 24},
sm: {span: 5},
|
|
60
|
},
|
|
61
62
63
|
wrapperCol: {
xs: {span: 24},
sm: {span: 16},
|
|
64
|
},
|
|
65
66
67
68
69
|
confirmLoading: false,
headers: {},
form: this.$form.createForm(this),
url: {
userId: "/sys/user/generateUserId", // 引入生成添加用户情况下的url
|
|
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
|
}
},
methods: {
add(checkedDepartKeys, userId) {
this.checkedKeys = checkedDepartKeys;
this.userId = userId;
this.edit({});
},
edit(record) {
this.departList = [];
this.queryDepartTree();
this.form.resetFields();
this.visible = true;
this.model = Object.assign({}, record);
let filedsVal = pick(this.model, 'id', 'userId', 'departIdList');
this.$nextTick(() => {
this.form.setFieldsValue(filedsVal);
});
},
close() {
this.$emit('close');
this.visible = false;
this.departList = [];
this.checkedKeys = [];
},
handleSubmit() {
const that = this;
// 触发表单验证
this.form.validateFields((err) => {
if (!err) {
that.confirmLoading = true;
if (this.userId == null) {
getAction(this.url.userId).then((res) => {
if (res.success) {
let formData = {
userId: res.result,
departIdList: this.departList
|
|
108
|
}
|
|
109
110
111
112
|
console.log(formData)
that.$emit('ok', formData);
}
}).finally(() => {
|
|
113
114
115
|
that.departList = [];
that.confirmLoading = false;
that.close();
|
|
116
117
118
119
120
|
})
} else {
let formData = {
userId: this.userId,
departIdList: this.departList
|
|
121
|
}
|
|
122
123
124
125
126
|
console.log(formData)
that.departList = [];
that.$emit('ok', formData);
that.confirmLoading = false;
that.close();
|
|
127
128
|
}
}
|
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
})
},
handleCancel() {
this.close()
},
// 选择部门时作用的API
onCheck(checkedKeys, info) {
this.departList = [];
this.checkedKeys = checkedKeys.checked;
let checkedNodes = info.checkedNodes;
for (let i = 0; i < checkedNodes.length; i++) {
let de = checkedNodes[i].data.props;
let depart = {key: "", value: "", title: ""};
depart.key = de.value;
depart.value = de.value;
depart.title = de.title;
this.departList.push(depart);
}
console.log('onCheck', checkedKeys, info);
},
queryDepartTree() {
queryIdTree().then((res) => {
if (res.success) {
this.departTree = res.result;
if (this.checkedKeys && this.checkedKeys.length > 0) {
let treekey = [];
let arr = res.result;
if (arr && arr.length > 0) {
arr.forEach(item => {
treekey.push(item.key);
/* if(item.children&&item.children.length>0){
item.children.forEach(item1 => {
treekey.push(item1.key);
})
}*/
})
this.expandedKeysss = treekey
|
|
167
168
|
}
}
|
|
169
170
171
172
173
174
175
|
}
})
},
onExpand(expandedKeys) {
this.expandedKeysss = expandedKeys;
},
modalFormOk() {
|
|
176
|
|
|
177
178
179
|
}
},
}
|
|
180
181
182
|
</script>
<style lang="less" scoped>
|
|
183
184
185
186
187
188
189
190
|
.ant-table-tbody .ant-table-row td {
padding-top: 10px;
padding-bottom: 10px;
}
/deep/ .ant-modal {
height: 700px;
}
|
|
191
|
</style>
|