cnhis-design-vue 2.1.17 → 2.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2219 -2219
- package/es/affix/index.js +8 -8
- package/es/age/index.js +10 -10
- package/es/alert/index.js +8 -8
- package/es/anchor/index.js +8 -8
- package/es/auto-complete/index.js +8 -8
- package/es/avatar/index.js +8 -8
- package/es/back-top/index.js +8 -8
- package/es/badge/index.js +8 -8
- package/es/base/index.js +8 -8
- package/es/big-table/index.js +164 -164
- package/es/breadcrumb/index.js +8 -8
- package/es/button/index.js +32 -32
- package/es/calendar/index.js +8 -8
- package/es/captcha/index.js +3 -3
- package/es/card/index.js +8 -8
- package/es/carousel/index.js +8 -8
- package/es/cascader/index.js +8 -8
- package/es/checkbox/index.js +9 -9
- package/es/col/index.js +8 -8
- package/es/collapse/index.js +8 -8
- package/es/color-picker/index.js +1 -1
- package/es/comment/index.js +8 -8
- package/es/config-provider/index.js +8 -8
- package/es/date-picker/index.js +8 -8
- package/es/descriptions/index.js +8 -8
- package/es/divider/index.js +8 -8
- package/es/drag-layout/index.js +3 -3
- package/es/drawer/index.js +8 -8
- package/es/dropdown/index.js +8 -8
- package/es/editor/index.js +1 -1
- package/es/empty/index.js +8 -8
- package/es/fabric-chart/index.js +34 -34
- package/es/form/index.js +8 -8
- package/es/form-model/index.js +8 -8
- package/es/form-table/index.js +62 -62
- package/es/index/index.js +672 -657
- package/es/index/style.css +1 -1
- package/es/input/index.js +9 -9
- package/es/input-number/index.js +8 -8
- package/es/layout/index.js +8 -8
- package/es/list/index.js +8 -8
- package/es/locale-provider/index.js +8 -8
- package/es/map/index.js +9 -9
- package/es/mentions/index.js +8 -8
- package/es/menu/index.js +8 -8
- package/es/message/index.js +8 -8
- package/es/multi-chat/index.js +92 -92
- package/es/multi-chat-client/index.js +86 -86
- package/es/multi-chat-history/index.js +4 -4
- package/es/multi-chat-record/index.js +14 -14
- package/es/multi-chat-setting/index.js +81 -66
- package/es/multi-chat-setting/style.css +1 -1
- package/es/multi-chat-sip/index.js +1 -1
- package/es/notification/index.js +8 -8
- package/es/page-header/index.js +8 -8
- package/es/pagination/index.js +8 -8
- package/es/popconfirm/index.js +8 -8
- package/es/popover/index.js +8 -8
- package/es/progress/index.js +8 -8
- package/es/radio/index.js +9 -9
- package/es/rate/index.js +8 -8
- package/es/result/index.js +8 -8
- package/es/row/index.js +8 -8
- package/es/scale-view/index.js +33 -33
- package/es/select/index.js +11 -11
- package/es/select-label/index.js +11 -11
- package/es/select-person/index.js +20 -20
- package/es/skeleton/index.js +8 -8
- package/es/slider/index.js +8 -8
- package/es/space/index.js +8 -8
- package/es/spin/index.js +8 -8
- package/es/statistic/index.js +8 -8
- package/es/steps/index.js +8 -8
- package/es/switch/index.js +8 -8
- package/es/table-filter/index.js +118 -118
- package/es/tabs/index.js +8 -8
- package/es/tag/index.js +9 -9
- package/es/time-picker/index.js +8 -8
- package/es/timeline/index.js +8 -8
- package/es/tooltip/index.js +8 -8
- package/es/transfer/index.js +8 -8
- package/es/tree/index.js +8 -8
- package/es/tree-select/index.js +8 -8
- package/es/upload/index.js +8 -8
- package/es/verification-code/index.js +2 -2
- package/lib/cui.common.js +620 -605
- package/lib/cui.umd.js +620 -605
- package/lib/cui.umd.min.js +71 -71
- package/package.json +106 -106
- package/packages/big-table/src/BigTable.vue +3038 -3038
- package/packages/big-table/src/assets/style/table-base.less +370 -370
- package/packages/big-table/src/components/AutoLayoutButton.vue +270 -270
- package/packages/big-table/src/utils/batchEditing.js +610 -610
- package/packages/big-table/src/utils/bigTableProps.js +95 -95
- package/packages/button/src/ButtonPrint/components/IdentityVerification.vue +181 -181
- package/packages/button/src/ButtonPrint/index.vue +728 -728
- package/packages/button/src/ButtonPrint/js/print.es.min.js +1 -1
- package/packages/fabric-chart/src/components/TimeScaleValue.vue +117 -117
- package/packages/fabric-chart/src/const/defaultVaule.js +59 -59
- package/packages/fabric-chart/src/fabric-chart/FabricPolylines.vue +960 -960
- package/packages/fabric-chart/src/fabric-chart/FabricScaleValue.vue +135 -135
- package/packages/fabric-chart/src/fabric-chart/FabricTextGroup.vue +558 -558
- package/packages/fabric-chart/src/fabric-chart2/FabricTop.vue +172 -172
- package/packages/multi-chat/chat/chatFooter.vue +1598 -1598
- package/packages/multi-chat/chat/chatMain.vue +1442 -1442
- package/packages/multi-chat/chat/quickReply.vue +439 -439
- package/packages/multi-chat/chat/scrollList.vue +1232 -1232
- package/packages/multi-chat/setting/baseInfo/index.vue +1316 -1302
- package/packages/multi-chat/store/actions.js +448 -448
- package/packages/multi-chat/store/state.js +112 -112
- package/packages/scale-view/formitem/r-choice.vue +714 -714
- package/packages/scale-view/scaleView.vue +2010 -2010
- package/packages/select-person/select-person.vue +1658 -1658
- package/packages/table-filter/src/base-search-com/BaseSearch.vue +2462 -2462
- package/packages/table-filter/src/components/c-tree-select/tree-select.vue +336 -336
- package/packages/table-filter/src/components/multi-select/multi-select.vue +219 -219
- package/packages/table-filter/src/components/out-quick-search/out-quick-search.vue +340 -340
- package/packages/table-filter/src/const/dataOptions.js +43 -43
- package/packages/table-filter/src/mixins/mixins.js +695 -695
- package/packages/table-filter/src/quick-search/QuickSearch.vue +2083 -2083
- package/src/directive/preventReClick.js +12 -12
|
@@ -1,1658 +1,1658 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="personnel">
|
|
3
|
-
<a-spin :spinning="spinning">
|
|
4
|
-
<div class="people-tree">
|
|
5
|
-
<!-- 树主体与检索 -->
|
|
6
|
-
<div class="people-tree-item people-tree-left">
|
|
7
|
-
<!-- $t('1.1.1.5.1') -->
|
|
8
|
-
<a-input-search style="margin-bottom: 12px" :placeholder="searchPlaceholder" :enter-button="searchButtonText" :allowClear="true" @search="searchClick" v-model="title" class="person-search">
|
|
9
|
-
<!-- <a-icon slot="prefix" type="search" class="search-input-icon" /> -->
|
|
10
|
-
<!-- <svg-icon
|
|
11
|
-
slot="prefix"
|
|
12
|
-
class="search-input-icon"
|
|
13
|
-
iconClass="xitongtubiaosousuo"
|
|
14
|
-
></svg-icon> -->
|
|
15
|
-
</a-input-search>
|
|
16
|
-
<div class="type-wrap" v-if="selectType === 'multiple'">
|
|
17
|
-
<div class="type-btn" :class="{ 'type-active': typeActiveIndex === 0 }" @click="onTypeClick(0)">选人员</div>
|
|
18
|
-
<div class="type-btn" :class="{ 'type-active': typeActiveIndex === 1 }" @click="onTypeClick(1)">选科室</div>
|
|
19
|
-
<div class="type-btn" :class="{ 'type-active': typeActiveIndex === 2 }" @click="onTypeClick(2)">选角色</div>
|
|
20
|
-
</div>
|
|
21
|
-
<template v-if="!isSingleCheck">
|
|
22
|
-
<a-checkbox v-if="searchTreeVisable" v-model="searchChecked" :indeterminate="searchIndeterminate" @change="radioChange">
|
|
23
|
-
<!-- {{ $t("1.10.139") }} -->
|
|
24
|
-
全选
|
|
25
|
-
</a-checkbox>
|
|
26
|
-
|
|
27
|
-
<a-checkbox v-else v-model="singleChecked" :indeterminate="indeterminate" @change="radioChange">
|
|
28
|
-
<!-- {{ $t("1.10.139") }} -->
|
|
29
|
-
全选
|
|
30
|
-
</a-checkbox>
|
|
31
|
-
</template>
|
|
32
|
-
|
|
33
|
-
<div v-show="search.status == 3 || (search.status == 0 && treeData.temp && treeData.temp.length == 0)" class="no-data-tips">
|
|
34
|
-
查无结果
|
|
35
|
-
</div>
|
|
36
|
-
<!-- main tree -->
|
|
37
|
-
<a-tree
|
|
38
|
-
class="main-tree-container"
|
|
39
|
-
v-show="search.status == 0"
|
|
40
|
-
ref="antTree"
|
|
41
|
-
v-model="checkedKeys.temp"
|
|
42
|
-
@expand="onExpand"
|
|
43
|
-
@check="onTreeCheck"
|
|
44
|
-
checkable
|
|
45
|
-
:expandedKeys="expandedKeys"
|
|
46
|
-
:autoExpandParent="autoExpandParent"
|
|
47
|
-
:checkStrictly="false"
|
|
48
|
-
:selectable="false"
|
|
49
|
-
:treeData="treeData.temp"
|
|
50
|
-
:load-data="getLoadChildData"
|
|
51
|
-
:disabled="isDetail"
|
|
52
|
-
>
|
|
53
|
-
<template slot="custom" slot-scope="scope">
|
|
54
|
-
<span v-if="scope.isLeaf">
|
|
55
|
-
<a-tooltip :title="`${scope.title} ${scope.sub_title}`" :mouseEnterDelay="0.3">
|
|
56
|
-
<span class="c-title">{{ scope.title || scope.key }}  </span>
|
|
57
|
-
<span class="c-sub-title">{{ scope.sub_title }}</span>
|
|
58
|
-
</a-tooltip>
|
|
59
|
-
</span>
|
|
60
|
-
<span v-else class="p-title">
|
|
61
|
-
<span v-if="scope.title">{{ scope.title }}</span>
|
|
62
|
-
<span v-else>{{ scope.key }}</span>
|
|
63
|
-
{{ treeCount(scope.count) }}
|
|
64
|
-
</span>
|
|
65
|
-
</template>
|
|
66
|
-
</a-tree>
|
|
67
|
-
<!-- search tree -->
|
|
68
|
-
<searchTree
|
|
69
|
-
v-on="$listeners"
|
|
70
|
-
ref="searchTree"
|
|
71
|
-
:visable="searchTreeVisable"
|
|
72
|
-
:formatTreeData="treeData.search"
|
|
73
|
-
:searchValue="searchValue"
|
|
74
|
-
:allCheckedKeys="checkedKeys"
|
|
75
|
-
:defaultExpandedKeys="search.defaultExpandedKeys"
|
|
76
|
-
:dataListKeys="search.dataListKeys"
|
|
77
|
-
:searchNoMore="searchNoMore"
|
|
78
|
-
:loadMorenLoadinng="loadMorenLoadinng"
|
|
79
|
-
@addCheckedkeysMain="addCheckedkeysMain"
|
|
80
|
-
@removeCheckedkeysMain="removeCheckedkeysMain"
|
|
81
|
-
@addCheckedkeysOther="addCheckedkeysOther"
|
|
82
|
-
@removeCheckedkeysOther="removeCheckedkeysOther"
|
|
83
|
-
@searchOnloadMore="searchOnloadMore"
|
|
84
|
-
></searchTree>
|
|
85
|
-
</div>
|
|
86
|
-
<!-- 树已选的数据 -->
|
|
87
|
-
<div class="select-wrap">
|
|
88
|
-
<div class="select-header" v-if="(defaultShowList && defaultShowList.length) || checkedTreeItem.length">
|
|
89
|
-
<div class="select-count" v-if="showCount">已选择:{{ defaultShowList.length + checkedTreeItem.length }}</div>
|
|
90
|
-
<div class="clear-btn" @click="onClearSelect" v-if="showClear">清空</div>
|
|
91
|
-
</div>
|
|
92
|
-
<div class="select-content">
|
|
93
|
-
<slot v-if="defaultShowList && defaultShowList.length">
|
|
94
|
-
<div class="tag-item def-item" v-for="(tag, i) in defaultShowList" :key="i">
|
|
95
|
-
{{ tag.title || tag[wordbookChild.user_name_obj] }}
|
|
96
|
-
<a-icon v-if="!isDetail" class="tag-close" type="close-circle" theme="filled" @click="closeDefaultTag(tag, i)" />
|
|
97
|
-
<!-- <svg-icon
|
|
98
|
-
v-if="!isDetail"
|
|
99
|
-
class="tag-close"
|
|
100
|
-
:icon-class="'xitongtubiaodaohangtubiaoguanbishixin'"
|
|
101
|
-
@click="closeDefaultTag(tag, i)"
|
|
102
|
-
></svg-icon> -->
|
|
103
|
-
</div>
|
|
104
|
-
</slot>
|
|
105
|
-
|
|
106
|
-
<div class="tag-item" :class="{ isRoot: !tag.isLeaf }" v-for="tag in checkedTreeItem" :key="tag.key">
|
|
107
|
-
{{ tag.title || tag.key }} {{ treeCount(tag.count) }}
|
|
108
|
-
<!-- <svg-icon
|
|
109
|
-
v-if="!isDetail"
|
|
110
|
-
class="tag-close"
|
|
111
|
-
:icon-class="'xitongtubiaodaohangtubiaoguanbishixin'"
|
|
112
|
-
@click="closeTag(tag)"
|
|
113
|
-
></svg-icon> -->
|
|
114
|
-
<a-icon v-if="!isDetail" class="tag-close" type="close-circle" theme="filled" @click="closeTag(tag)" />
|
|
115
|
-
</div>
|
|
116
|
-
</div>
|
|
117
|
-
</div>
|
|
118
|
-
</div>
|
|
119
|
-
</a-spin>
|
|
120
|
-
</div>
|
|
121
|
-
</template>
|
|
122
|
-
<script>
|
|
123
|
-
/* eslint-disable no-async-promise-executor */
|
|
124
|
-
|
|
125
|
-
import { Icon, Checkbox, Tree, Tooltip, Input, Spin } from 'ant-design-vue';
|
|
126
|
-
import searchTree from './search-tree';
|
|
127
|
-
import create from '@/core/create';
|
|
128
|
-
import vexutils from '@/utils/vexutils';
|
|
129
|
-
import { filterTree, deepTraversalFirst, getAllParentId } from '@/utils';
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 查询没有部门的分类时,parent_id_obj 为 undefined a-tree 展示异常。
|
|
133
|
-
* 前端 赋上固定key 标识 该分类 无部门,该key 不能提交接口。
|
|
134
|
-
* */
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* key 唯一key
|
|
138
|
-
* title 展示标题
|
|
139
|
-
* sub_title 副标题
|
|
140
|
-
* count 数量
|
|
141
|
-
*/
|
|
142
|
-
|
|
143
|
-
const FIXEDKEY = '8982eeb4-0439-4100-9805-8cdd12b2256c-front-end-fixed-key';
|
|
144
|
-
export default create({
|
|
145
|
-
name: 'select-person',
|
|
146
|
-
components: {
|
|
147
|
-
searchTree,
|
|
148
|
-
[Icon.name]: Icon,
|
|
149
|
-
[Spin.name]: Spin,
|
|
150
|
-
[Tree.name]: Tree,
|
|
151
|
-
[Input.Search.name]: Input.Search,
|
|
152
|
-
[Checkbox.name]: Checkbox,
|
|
153
|
-
[Tooltip.name]: Tooltip
|
|
154
|
-
},
|
|
155
|
-
props: {
|
|
156
|
-
isDetail: { type: Boolean, isDetail: false },
|
|
157
|
-
defaultList: { type: Array, default: () => [] },
|
|
158
|
-
data: { type: Array, default: () => [] },
|
|
159
|
-
roleData: { type: Array, default: () => [] },
|
|
160
|
-
roleFields: {
|
|
161
|
-
type: Object,
|
|
162
|
-
default: () => ({ title: 'name', key: 'id', children: 'children' })
|
|
163
|
-
},
|
|
164
|
-
searchPlaceholder: {
|
|
165
|
-
type: String,
|
|
166
|
-
default: '输入关键字搜索'
|
|
167
|
-
},
|
|
168
|
-
searchButtonText: {
|
|
169
|
-
type: String,
|
|
170
|
-
default: '搜索'
|
|
171
|
-
},
|
|
172
|
-
// 父级配置
|
|
173
|
-
wordbook: {
|
|
174
|
-
type: Object,
|
|
175
|
-
default: () => ({
|
|
176
|
-
// parent_id_obj: "dept_id", // 父级 id
|
|
177
|
-
// parent_id_obj_key: "dept_id", // 提交的 id 的映射 key
|
|
178
|
-
// parent_name_obj: "dept_name", // 名称
|
|
179
|
-
// parent_name_obj_key: "dept_name", // 名称 的映射key
|
|
180
|
-
// user_count_obj: "count" // 统计 key
|
|
181
|
-
})
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
// 子集配置
|
|
185
|
-
wordbookChild: {
|
|
186
|
-
type: Object,
|
|
187
|
-
default: () => ({})
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
// 检索加载更多
|
|
191
|
-
SearchLoadMore: {
|
|
192
|
-
type: Boolean,
|
|
193
|
-
default: false
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
showClear: {
|
|
197
|
-
type: Boolean,
|
|
198
|
-
default: true
|
|
199
|
-
},
|
|
200
|
-
showCount: {
|
|
201
|
-
type: Boolean,
|
|
202
|
-
default: true
|
|
203
|
-
},
|
|
204
|
-
selectType: {
|
|
205
|
-
type: String,
|
|
206
|
-
default: 'person' // person dept role multiple
|
|
207
|
-
},
|
|
208
|
-
isSingleCheck: {
|
|
209
|
-
type: Boolean,
|
|
210
|
-
default: false
|
|
211
|
-
},
|
|
212
|
-
queryMainTreeData: Function, // 主树请求
|
|
213
|
-
queryLoadChildData: Function, // 懒加载请求
|
|
214
|
-
queryTreeSearch: Function // 检索请求
|
|
215
|
-
},
|
|
216
|
-
data() {
|
|
217
|
-
return {
|
|
218
|
-
treeData: {
|
|
219
|
-
main: [],
|
|
220
|
-
search: [],
|
|
221
|
-
dept: [],
|
|
222
|
-
role: [],
|
|
223
|
-
temp: []
|
|
224
|
-
},
|
|
225
|
-
// 展开的keys
|
|
226
|
-
expandedKeys: [],
|
|
227
|
-
// 展开的部门keys
|
|
228
|
-
expandedDeptKeys: [],
|
|
229
|
-
autoExpandParent: true,
|
|
230
|
-
// 扁平化tree的options Object{Array[Object]}
|
|
231
|
-
dataList: {
|
|
232
|
-
main: [],
|
|
233
|
-
other: [],
|
|
234
|
-
dept: [],
|
|
235
|
-
role: []
|
|
236
|
-
},
|
|
237
|
-
// 当前tree选中的keys Object{Array[Number]}
|
|
238
|
-
checkedKeys: {
|
|
239
|
-
main: [],
|
|
240
|
-
other: [],
|
|
241
|
-
dept: [],
|
|
242
|
-
role: [],
|
|
243
|
-
temp: []
|
|
244
|
-
},
|
|
245
|
-
search: {
|
|
246
|
-
defaultExpandedKeys: [],
|
|
247
|
-
// 0: 未查询,1:查询中,2:有查询结果,3无查询结果
|
|
248
|
-
status: 0,
|
|
249
|
-
dataListKeys: {
|
|
250
|
-
main: [],
|
|
251
|
-
other: []
|
|
252
|
-
},
|
|
253
|
-
records: 0
|
|
254
|
-
},
|
|
255
|
-
searchValue: '',
|
|
256
|
-
searchPage: 1,
|
|
257
|
-
searchNoMore: false,
|
|
258
|
-
title: '',
|
|
259
|
-
// 选中的所有叶节点(Leaf)keys <Array[Number]>,最终提交接口所需格式
|
|
260
|
-
checkedLeafKeys: [],
|
|
261
|
-
spinning: false,
|
|
262
|
-
loadMorenLoadinng: false,
|
|
263
|
-
|
|
264
|
-
errorMsg: '',
|
|
265
|
-
|
|
266
|
-
defaultShowList: [], // 默认选中项
|
|
267
|
-
checkedKeysMain: [],
|
|
268
|
-
|
|
269
|
-
cacheParentIdObj: {},
|
|
270
|
-
singleChecked: false,
|
|
271
|
-
indeterminate: false,
|
|
272
|
-
|
|
273
|
-
searchIndeterminate: false,
|
|
274
|
-
searchChecked: false,
|
|
275
|
-
typeActiveIndex: 0
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
computed: {
|
|
279
|
-
searchTreeVisable() {
|
|
280
|
-
return this.search.status == 2;
|
|
281
|
-
},
|
|
282
|
-
dataListMainKeys() {
|
|
283
|
-
if (!this.dataList.main.length) return [];
|
|
284
|
-
|
|
285
|
-
return this.dataList.main.map(i => {
|
|
286
|
-
return i.key;
|
|
287
|
-
});
|
|
288
|
-
},
|
|
289
|
-
dataListDeptKeys() {
|
|
290
|
-
if (!this.dataList.dept.length) return [];
|
|
291
|
-
|
|
292
|
-
return this.dataList.dept.map(i => {
|
|
293
|
-
return i.key;
|
|
294
|
-
});
|
|
295
|
-
},
|
|
296
|
-
dataListRoleKeys() {
|
|
297
|
-
if (!this.dataList.role.length) return [];
|
|
298
|
-
|
|
299
|
-
return this.dataList.role.map(i => {
|
|
300
|
-
return i.key;
|
|
301
|
-
});
|
|
302
|
-
},
|
|
303
|
-
dataListOtherKeys() {
|
|
304
|
-
if (!this.dataList.other.length) return [];
|
|
305
|
-
|
|
306
|
-
return this.dataList.other.map(i => {
|
|
307
|
-
return i.key;
|
|
308
|
-
});
|
|
309
|
-
},
|
|
310
|
-
// 右侧展示tabs <Array[Object]>
|
|
311
|
-
checkedTreeItem() {
|
|
312
|
-
let otherItems = this.dataList.other.filter(item => {
|
|
313
|
-
return this.checkedKeys.other.includes(item.key);
|
|
314
|
-
});
|
|
315
|
-
let mainItems = this.dataList.main.filter(item => {
|
|
316
|
-
// let f = this.currentKey === 'main';
|
|
317
|
-
// if(!f) return f;
|
|
318
|
-
let { isLeaf, key } = item;
|
|
319
|
-
let parentId = this.getParentId(item);
|
|
320
|
-
let showKeys = [...this.checkedKeys.main, ...otherItems];
|
|
321
|
-
let checked = showKeys.includes(key);
|
|
322
|
-
// 父级全选,子级不展示
|
|
323
|
-
/** String(parentId) 类型不相等 */
|
|
324
|
-
// if (isLeaf && parentId && this.checkedKeys.temp.some(v => v == parentId)) {
|
|
325
|
-
// checked = false;
|
|
326
|
-
// }
|
|
327
|
-
item.itemType = 'person';
|
|
328
|
-
return checked && item.type == 2;
|
|
329
|
-
});
|
|
330
|
-
let deptItems = this.dataList.dept.filter(item => {
|
|
331
|
-
let { key } = item;
|
|
332
|
-
let showKeys = [...this.checkedKeys.dept, ...otherItems];
|
|
333
|
-
let checked = showKeys.includes(key);
|
|
334
|
-
// 只展示最后一级的科室
|
|
335
|
-
item.itemType = 'dept';
|
|
336
|
-
return checked && item.type == 1 && (!item.children || (item.children && !item.children.length));
|
|
337
|
-
});
|
|
338
|
-
let roleItems = this.dataList.role.filter(item => {
|
|
339
|
-
let showKeys = [...this.checkedKeys.role, ...otherItems];
|
|
340
|
-
let checked = showKeys.includes(item.key);
|
|
341
|
-
item.itemType = 'role';
|
|
342
|
-
return checked && item.roleId;
|
|
343
|
-
});
|
|
344
|
-
if (this.selectType === 'multiple') {
|
|
345
|
-
deptItems.forEach(item => {
|
|
346
|
-
if (item.title) {
|
|
347
|
-
item.title = item.title.includes('(科室)') ? item.title : `${item.title}(科室)`;
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
roleItems.map(item => {
|
|
351
|
-
if (item.title) {
|
|
352
|
-
item.title = item.title.includes('(角色)') ? item.title : `${item.title}(角色)`;
|
|
353
|
-
}
|
|
354
|
-
return item;
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
let list = this.uniqArrObj([...mainItems, ...deptItems, ...roleItems, ...otherItems], 'key');
|
|
359
|
-
return list;
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
wordbookConfig() {
|
|
363
|
-
const { parent_id_obj, parent_name_obj } = this.wordbook || {};
|
|
364
|
-
const { user_id_obj, user_name_obj } = this.wordbookChild || {};
|
|
365
|
-
return {
|
|
366
|
-
parent_id_obj,
|
|
367
|
-
parent_name_obj,
|
|
368
|
-
user_id_obj,
|
|
369
|
-
user_name_obj
|
|
370
|
-
};
|
|
371
|
-
},
|
|
372
|
-
|
|
373
|
-
getLoadChildData() {
|
|
374
|
-
if (typeof this.queryLoadChildData == 'function') {
|
|
375
|
-
return this.onLoadData;
|
|
376
|
-
}
|
|
377
|
-
return null;
|
|
378
|
-
},
|
|
379
|
-
|
|
380
|
-
currentKey() {
|
|
381
|
-
return { person: 'main', dept: 'dept', role: 'role', multiple: 'main' }[this.selectType];
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
watch: {
|
|
385
|
-
// defaultList: {
|
|
386
|
-
// immediate: true,
|
|
387
|
-
// handler(val) {
|
|
388
|
-
// if (!val) return;
|
|
389
|
-
// this.initDefault();
|
|
390
|
-
// }
|
|
391
|
-
// },
|
|
392
|
-
selectType: {
|
|
393
|
-
immediate: true,
|
|
394
|
-
handler(val) {
|
|
395
|
-
if (val === 'dept' || val === 'role' || val === 'multiple') {
|
|
396
|
-
this.typeActiveIndex = { multiple: 0, dept: 1, role: 2 }[val];
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
},
|
|
400
|
-
data: {
|
|
401
|
-
immediate: true,
|
|
402
|
-
handler() {
|
|
403
|
-
this.staticDataInit();
|
|
404
|
-
this.staticDeptAndRoleDataInit();
|
|
405
|
-
const key = { person: 'main', dept: 'dept', role: 'role', multiple: 'main' }[this.selectType];
|
|
406
|
-
this.treeData.temp = this.treeData[key];
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
roleData: {
|
|
410
|
-
immediate: true,
|
|
411
|
-
handler() {
|
|
412
|
-
this.staticDeptAndRoleDataInit();
|
|
413
|
-
const key = { person: 'main', dept: 'dept', role: 'role', multiple: 'main' }[this.selectType];
|
|
414
|
-
this.treeData.temp = this.treeData[key];
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
},
|
|
418
|
-
created() {},
|
|
419
|
-
mounted() {
|
|
420
|
-
this.getUsers();
|
|
421
|
-
this.initDefault();
|
|
422
|
-
},
|
|
423
|
-
methods: {
|
|
424
|
-
initDefault() {
|
|
425
|
-
if (this.getLoadChildData) {
|
|
426
|
-
this.getDefaultList();
|
|
427
|
-
} else {
|
|
428
|
-
this.$nextTick(() => {
|
|
429
|
-
const userIds = this.defaultList.filter(item => item.itemType === 'person').map(item => item.id);
|
|
430
|
-
const deptIds = this.defaultList.filter(item => item.itemType === 'dept').map(item => item.id);
|
|
431
|
-
const roleIds = this.defaultList.filter(item => item.itemType === 'role').map(item => item.id);
|
|
432
|
-
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
433
|
-
this.checkedKeys.main = userIds;
|
|
434
|
-
this.checkedKeys.dept = deptIds;
|
|
435
|
-
this.checkedKeys.role = roleIds;
|
|
436
|
-
this.checkedKeys.temp = this.checkedKeys[key];
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
},
|
|
440
|
-
|
|
441
|
-
staticDataInit() {
|
|
442
|
-
if (!Array.isArray(this.data) || this.data.length == 0) return;
|
|
443
|
-
this.treeData.main = this.data;
|
|
444
|
-
this.generateDataList(this.treeData.main, this.dataList.main);
|
|
445
|
-
},
|
|
446
|
-
staticDeptAndRoleDataInit() {
|
|
447
|
-
this.treeData.dept = this.getDeptData(this.data);
|
|
448
|
-
this.generateDataList(this.treeData.dept, this.dataList.dept);
|
|
449
|
-
this.treeData.role = this.handleRoleData(this.roleData);
|
|
450
|
-
this.generateDataList(this.treeData.role, this.dataList.role);
|
|
451
|
-
},
|
|
452
|
-
getDeptData(data) {
|
|
453
|
-
// 把data里面的人员过滤掉
|
|
454
|
-
const copyData = JSON.parse(JSON.stringify(data));
|
|
455
|
-
vexutils.searchTree(copyData, item => {
|
|
456
|
-
if (item.type === 1 && item.children && item.children.length) {
|
|
457
|
-
item.children = item.children.filter(child => child.type === 1);
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
return copyData;
|
|
461
|
-
},
|
|
462
|
-
handleRoleData(data) {
|
|
463
|
-
const copyData = JSON.parse(JSON.stringify(data));
|
|
464
|
-
vexutils.searchTree(copyData, item => {
|
|
465
|
-
const { title, key, children } = this.roleFields;
|
|
466
|
-
item.title = item[title];
|
|
467
|
-
item.children = item[children] ? item[children] : [];
|
|
468
|
-
item.key = item[key];
|
|
469
|
-
});
|
|
470
|
-
return copyData;
|
|
471
|
-
},
|
|
472
|
-
/** --- 默认值 --- */
|
|
473
|
-
getDefaultList() {
|
|
474
|
-
const { defaultList } = this;
|
|
475
|
-
let copy = JSON.parse(JSON.stringify(defaultList));
|
|
476
|
-
if (Array.isArray(copy)) {
|
|
477
|
-
// this.defaultShowObj = {};
|
|
478
|
-
|
|
479
|
-
const { user_id_obj } = this.wordbookChild || {};
|
|
480
|
-
copy.forEach(v => {
|
|
481
|
-
this.handleDefMapping(v);
|
|
482
|
-
let key = this.getuniqKey(v);
|
|
483
|
-
let pId = this.getParentId(v);
|
|
484
|
-
this.cacheParentIdObj[pId] = pId;
|
|
485
|
-
// this.defaultShowObj[key] = v[user_id_obj];
|
|
486
|
-
});
|
|
487
|
-
this.defaultShowList = copy;
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
|
|
491
|
-
getcheckedKeys() {
|
|
492
|
-
const { defaultList } = this;
|
|
493
|
-
let checkedKeysMain = [],
|
|
494
|
-
checkedKeysOther = [];
|
|
495
|
-
let copy = JSON.parse(JSON.stringify(defaultList));
|
|
496
|
-
if (Array.isArray(copy)) {
|
|
497
|
-
copy.forEach(v => {
|
|
498
|
-
this.handleDefMapping(v);
|
|
499
|
-
let key = this.getuniqKey(v);
|
|
500
|
-
checkedKeysMain.push(key);
|
|
501
|
-
// 回填到 检索的选择,防止回填马上检索
|
|
502
|
-
if (String(key).includes(FIXEDKEY)) {
|
|
503
|
-
checkedKeysOther.push(key);
|
|
504
|
-
}
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
checkedKeysMain,
|
|
509
|
-
checkedKeysOther
|
|
510
|
-
};
|
|
511
|
-
},
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* 根据配置映射默认值
|
|
515
|
-
*/
|
|
516
|
-
handleDefMapping(v) {
|
|
517
|
-
const { parent_id_obj, parent_name_obj, user_id_obj, user_name_obj } = this.wordbookConfig || {};
|
|
518
|
-
// 自定义 key 值
|
|
519
|
-
const { parent_id_obj_key, parent_name_obj_key } = this.wordbook;
|
|
520
|
-
const { user_id_obj_key, user_name_obj_key } = this.wordbookChild;
|
|
521
|
-
v[parent_id_obj] = v[parent_id_obj_key] || v.parent_id;
|
|
522
|
-
v[parent_name_obj] = v[parent_name_obj_key] || v.parent_name;
|
|
523
|
-
v[user_id_obj] = v[user_id_obj_key] || v.user_id;
|
|
524
|
-
v[user_name_obj] = v[user_name_obj_key] || v.user_name;
|
|
525
|
-
},
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* 初始化 请求已选的数据
|
|
529
|
-
*/
|
|
530
|
-
async loadSelected() {
|
|
531
|
-
try {
|
|
532
|
-
let list = await Promise.all(
|
|
533
|
-
this.treeData.main.map(async v => {
|
|
534
|
-
const { parent_id_obj } = this.wordbook || {};
|
|
535
|
-
if ([v.key, v[parent_id_obj], String(v[parent_id_obj])].includes(this.cacheParentIdObj[v[parent_id_obj]])) {
|
|
536
|
-
await this.onLoadData({ dataRef: v });
|
|
537
|
-
return v;
|
|
538
|
-
}
|
|
539
|
-
})
|
|
540
|
-
);
|
|
541
|
-
return list;
|
|
542
|
-
} catch (error) {
|
|
543
|
-
return Promise.resolve();
|
|
544
|
-
}
|
|
545
|
-
},
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* 过滤默认值的右边展示
|
|
549
|
-
*/
|
|
550
|
-
hanldeFilterDefaultShowList(list) {
|
|
551
|
-
this.defaultShowList = this.defaultShowList.filter(d => list.findIndex(l => this.getuniqKey(d) == this.getuniqKey(l)) == -1);
|
|
552
|
-
// this.updateDefaultShowObj(this.defaultShowList);
|
|
553
|
-
},
|
|
554
|
-
|
|
555
|
-
updateDefaultShowObj(list) {
|
|
556
|
-
const { user_id_obj } = this.wordbookConfig || {};
|
|
557
|
-
this.defaultShowObj = {};
|
|
558
|
-
list.forEach(v => {
|
|
559
|
-
this.defaultShowObj[this.getuniqKey(v)] = v[user_id_obj];
|
|
560
|
-
});
|
|
561
|
-
},
|
|
562
|
-
|
|
563
|
-
/**
|
|
564
|
-
* 拼接key
|
|
565
|
-
*/
|
|
566
|
-
getuniqKey(v) {
|
|
567
|
-
const { user_id_obj } = this.wordbookConfig || {};
|
|
568
|
-
return `${this.getParentId(v)}_${v[user_id_obj]}`;
|
|
569
|
-
// return v.key;
|
|
570
|
-
},
|
|
571
|
-
|
|
572
|
-
getParentId(v) {
|
|
573
|
-
const { parent_id_obj } = this.wordbookConfig || {};
|
|
574
|
-
// return `${v[parent_id_obj] || FIXEDKEY}`;
|
|
575
|
-
return `${v[parent_id_obj]}`;
|
|
576
|
-
},
|
|
577
|
-
|
|
578
|
-
// 查询树结构数据(一级父类)
|
|
579
|
-
async getUsers() {
|
|
580
|
-
try {
|
|
581
|
-
if (typeof this.queryMainTreeData !== 'function') {
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
this.spinning = true;
|
|
585
|
-
const { parent_id_obj } = this.wordbookConfig || {};
|
|
586
|
-
let rows = await this.queryMainTreeData();
|
|
587
|
-
let list = this.uniqArrObj(rows, parent_id_obj);
|
|
588
|
-
this.treeData.main = list;
|
|
589
|
-
this.generateDataList(this.treeData.main, this.dataList.main);
|
|
590
|
-
// TODO:这里的回填
|
|
591
|
-
await this.loadSelected();
|
|
592
|
-
let { checkedKeysMain, checkedKeysOther } = this.getcheckedKeys();
|
|
593
|
-
this.checkedKeys.main.push(...checkedKeysMain);
|
|
594
|
-
this.checkedKeys.other = [...checkedKeysOther];
|
|
595
|
-
|
|
596
|
-
this.treeData.main.forEach(f => {
|
|
597
|
-
if (f && f.children && f.children.length) {
|
|
598
|
-
let flag = f.children.every(c => checkedKeysMain.includes(c.key));
|
|
599
|
-
if (flag && f.key) {
|
|
600
|
-
this.checkedKeys.main.push(f.key);
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
if (this.currentKey === 'main') {
|
|
605
|
-
this.checkedKeys.temp = this.checkedKeys.main;
|
|
606
|
-
this.treeData.temp = this.treeData.main;
|
|
607
|
-
}
|
|
608
|
-
this.spinning = false;
|
|
609
|
-
} catch (error) {
|
|
610
|
-
this.spinning = false;
|
|
611
|
-
this.$message.error('查询异常');
|
|
612
|
-
console.log(error);
|
|
613
|
-
}
|
|
614
|
-
},
|
|
615
|
-
|
|
616
|
-
// 动态获取子节点
|
|
617
|
-
onLoadData(treeNode) {
|
|
618
|
-
return new Promise(async resolve => {
|
|
619
|
-
if (treeNode.dataRef.children) {
|
|
620
|
-
resolve();
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
treeNode.dataRef.children = await this.handleLoadChildData(treeNode.dataRef.key, treeNode.dataRef);
|
|
624
|
-
|
|
625
|
-
this.hanldeFilterDefaultShowList(treeNode.dataRef.children);
|
|
626
|
-
|
|
627
|
-
this.$nextTick(() => {
|
|
628
|
-
this.treeData.main = [...this.treeData.main];
|
|
629
|
-
this.treeData.temp = [...this.treeData.main];
|
|
630
|
-
});
|
|
631
|
-
|
|
632
|
-
this.addCheckedKeysChildrenMain(treeNode.dataRef);
|
|
633
|
-
|
|
634
|
-
this.generateDataList(treeNode.dataRef.children, this.dataList.main);
|
|
635
|
-
resolve();
|
|
636
|
-
});
|
|
637
|
-
},
|
|
638
|
-
|
|
639
|
-
async handleLoadChildData(key, treeNode) {
|
|
640
|
-
let rows = await this.queryLoadChildData(key, treeNode);
|
|
641
|
-
let list = rows;
|
|
642
|
-
return list;
|
|
643
|
-
},
|
|
644
|
-
|
|
645
|
-
loadMainChildData(searchResultTreeData) {
|
|
646
|
-
return new Promise(async resolve => {
|
|
647
|
-
let promises = searchResultTreeData.map(async item => {
|
|
648
|
-
if (item.users) {
|
|
649
|
-
let mainTreeItem = this.treeData.main.find(mainItem => mainItem.key == item.key);
|
|
650
|
-
if (!mainTreeItem || (mainTreeItem && !mainTreeItem.children)) {
|
|
651
|
-
if (!mainTreeItem) {
|
|
652
|
-
mainTreeItem = { ...item };
|
|
653
|
-
}
|
|
654
|
-
mainTreeItem.children = await this.handleLoadChildData(item.key, mainTreeItem);
|
|
655
|
-
this.generateDataList(mainTreeItem.children, this.dataList.main);
|
|
656
|
-
this.addCheckedKeysChildrenMain(mainTreeItem);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
});
|
|
660
|
-
|
|
661
|
-
await Promise.all(promises);
|
|
662
|
-
|
|
663
|
-
resolve();
|
|
664
|
-
});
|
|
665
|
-
},
|
|
666
|
-
|
|
667
|
-
/**
|
|
668
|
-
* 检索
|
|
669
|
-
*/
|
|
670
|
-
async searchFetch(data = {}, config = {}) {
|
|
671
|
-
if (typeof this.queryTreeSearch !== 'function') {
|
|
672
|
-
this.staticDataSearch();
|
|
673
|
-
this.spinning = false;
|
|
674
|
-
this.isSearchAllCheck();
|
|
675
|
-
return;
|
|
676
|
-
}
|
|
677
|
-
if (!this.searchValue) {
|
|
678
|
-
this.search.status = 0;
|
|
679
|
-
this.search.defaultExpandedKeys = [];
|
|
680
|
-
this.expandedKeys = [];
|
|
681
|
-
this.spinning = false;
|
|
682
|
-
this.searchNoMore = false;
|
|
683
|
-
return false;
|
|
684
|
-
}
|
|
685
|
-
if (!config.loadMoren) {
|
|
686
|
-
this.search.status = 1;
|
|
687
|
-
} else {
|
|
688
|
-
this.loadMorenLoadinng = true;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
let rows = await this.queryTreeSearch(this.searchValue, data);
|
|
692
|
-
let searchResultTreeData = rows;
|
|
693
|
-
this.loadMorenLoadinng = false;
|
|
694
|
-
if (!searchResultTreeData || !searchResultTreeData.length) {
|
|
695
|
-
if (this.searchPage == 1) {
|
|
696
|
-
this.search.defaultExpandedKeys = [];
|
|
697
|
-
this.search.status = 3;
|
|
698
|
-
} else {
|
|
699
|
-
this.search.status = 2;
|
|
700
|
-
this.searchNoMore = true;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
this.spinning = false;
|
|
704
|
-
this.isSearchAllCheck();
|
|
705
|
-
return false;
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
const { parent_id_obj, parent_name_obj, user_count_obj } = this.wordbook || {};
|
|
709
|
-
const { user_name_obj } = this.wordbookChild || {};
|
|
710
|
-
let pObj = {};
|
|
711
|
-
searchResultTreeData.forEach(item => {
|
|
712
|
-
item[parent_id_obj] &&
|
|
713
|
-
(pObj[item[parent_id_obj]] = {
|
|
714
|
-
key: item[parent_id_obj],
|
|
715
|
-
users: []
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
if (item.users) {
|
|
719
|
-
this.insertSearchTreeData(item);
|
|
720
|
-
} else {
|
|
721
|
-
this.insertSearchTreeDataOther(item);
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
let pList = [];
|
|
725
|
-
Object.keys(pObj || {}).forEach(v => {
|
|
726
|
-
if (v) {
|
|
727
|
-
pList.push({ ...pObj[v] });
|
|
728
|
-
}
|
|
729
|
-
});
|
|
730
|
-
let len = this.treeData.search.length || 0;
|
|
731
|
-
// TODO:加载更多
|
|
732
|
-
if (this.SearchLoadMore) {
|
|
733
|
-
this.searchNoMore = false;
|
|
734
|
-
} else {
|
|
735
|
-
this.searchNoMore = true;
|
|
736
|
-
}
|
|
737
|
-
// 防止searchTree选中后切换回mainTree,mainTree checkedKeys状态丢失
|
|
738
|
-
await this.loadMainChildData(pList);
|
|
739
|
-
this.generateSearchDataListKeys(searchResultTreeData);
|
|
740
|
-
|
|
741
|
-
this.hanldeFilterDefaultShowList(searchResultTreeData);
|
|
742
|
-
this.refreshSearchTree();
|
|
743
|
-
this.search.status = 2;
|
|
744
|
-
this.spinning = false;
|
|
745
|
-
|
|
746
|
-
this.isSearchAllCheck();
|
|
747
|
-
},
|
|
748
|
-
|
|
749
|
-
insertSearchTreeData(item) {
|
|
750
|
-
const { user_count_obj } = this.wordbook || {};
|
|
751
|
-
this.search.defaultExpandedKeys.push(item.key);
|
|
752
|
-
|
|
753
|
-
// 默认值处理
|
|
754
|
-
this.hanldeFilterDefaultShowList(item.children || []);
|
|
755
|
-
|
|
756
|
-
if (item[user_count_obj] == item.children.length) {
|
|
757
|
-
item.disableCheckbox = false;
|
|
758
|
-
}
|
|
759
|
-
this.treeData.search.push(item);
|
|
760
|
-
},
|
|
761
|
-
|
|
762
|
-
insertSearchTreeDataOther(item) {
|
|
763
|
-
let formatItem = Object.assign({}, item, { isLeaf: true });
|
|
764
|
-
|
|
765
|
-
this.treeData.search.push(formatItem);
|
|
766
|
-
|
|
767
|
-
if (this.dataListOtherKeys.includes(formatItem.key)) return false;
|
|
768
|
-
this.generateDataList([formatItem], this.dataList.other);
|
|
769
|
-
},
|
|
770
|
-
|
|
771
|
-
generateSearchDataListKeys(searchResultTreeData) {
|
|
772
|
-
// this.search.dataListKeys = {
|
|
773
|
-
// main: [],
|
|
774
|
-
// other: []
|
|
775
|
-
// };
|
|
776
|
-
searchResultTreeData.forEach(item => {
|
|
777
|
-
if (!this.dataListMainKeys.includes(item.key)) {
|
|
778
|
-
this.search.dataListKeys.other.push(item.key);
|
|
779
|
-
item.children &&
|
|
780
|
-
item.children.forEach(childItem => {
|
|
781
|
-
this.search.dataListKeys.other.push(childItem.key);
|
|
782
|
-
});
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
this.search.dataListKeys.main.push(item.key);
|
|
787
|
-
item.children &&
|
|
788
|
-
item.children.forEach(childItem => {
|
|
789
|
-
this.search.dataListKeys.main.push(childItem.key);
|
|
790
|
-
});
|
|
791
|
-
});
|
|
792
|
-
},
|
|
793
|
-
|
|
794
|
-
searchOnloadMore() {
|
|
795
|
-
this.searchPage = this.searchPage + 1;
|
|
796
|
-
this.searchFetch({ page: this.searchPage }, { loadMoren: true });
|
|
797
|
-
},
|
|
798
|
-
|
|
799
|
-
addCheckedKeysChildrenMain(item) {
|
|
800
|
-
if (!item.key) return;
|
|
801
|
-
if (!this.checkedKeys.main.includes(String(item.key))) return false;
|
|
802
|
-
// 新查询到插入已选中的main treeData 的child key,需要手动push到checkedKeys中
|
|
803
|
-
if (!Array.isArray(item.children)) return false;
|
|
804
|
-
item.children.forEach(({ key }) => {
|
|
805
|
-
// 防止重复添加(已处理,不会重复添加,保留代码以防逻辑缺漏)
|
|
806
|
-
if (this.checkedKeys.main.includes(key) || !key) return false;
|
|
807
|
-
this.checkedKeys.main.push(key);
|
|
808
|
-
});
|
|
809
|
-
},
|
|
810
|
-
|
|
811
|
-
// 暂存实际可选节点arr
|
|
812
|
-
generateDataList(data, dataList) {
|
|
813
|
-
for (let i = 0; i < data.length; i++) {
|
|
814
|
-
const node = data[i];
|
|
815
|
-
dataList.push({
|
|
816
|
-
parentId: this.getParentId(node),
|
|
817
|
-
...node
|
|
818
|
-
});
|
|
819
|
-
if (node.children) {
|
|
820
|
-
this.generateDataList(node.children, dataList);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
},
|
|
824
|
-
|
|
825
|
-
// 获取匹配搜索节点arr
|
|
826
|
-
getParentKey(key, tree) {
|
|
827
|
-
let parentKey;
|
|
828
|
-
for (let i = 0; i < tree.length; i++) {
|
|
829
|
-
const node = tree[i];
|
|
830
|
-
if (node.key == key) {
|
|
831
|
-
parentKey = node.key;
|
|
832
|
-
return parentKey;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
if (node.children) {
|
|
836
|
-
if (node.children.some(item => item.key == key)) {
|
|
837
|
-
parentKey = node.key;
|
|
838
|
-
} else if (this.getParentKey(key, node.children)) {
|
|
839
|
-
parentKey = this.getParentKey(key, node.children);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
return parentKey;
|
|
844
|
-
},
|
|
845
|
-
radioChange(e) {
|
|
846
|
-
let { checked } = e.target || {};
|
|
847
|
-
if (this.searchTreeVisable) {
|
|
848
|
-
this.singleChecked = checked;
|
|
849
|
-
} else {
|
|
850
|
-
this.searchChecked = checked;
|
|
851
|
-
}
|
|
852
|
-
this.checkAll(checked ? 1 : 2);
|
|
853
|
-
this.handleOk();
|
|
854
|
-
},
|
|
855
|
-
// type 1 全选 2 反选(清空)
|
|
856
|
-
checkAll(type) {
|
|
857
|
-
if (this.checkAllSearchTree(type)) return false;
|
|
858
|
-
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
859
|
-
if (type == 1) {
|
|
860
|
-
this.expandedKeys = [];
|
|
861
|
-
this.checkedKeys[key] = this[`dataList${key.slice(0, 1).toUpperCase()}${key.slice(1)}Keys`]; // dataListMainKeys dataListDeptKeys dataListRoleKeys;
|
|
862
|
-
this.checkedKeys.temp = this.checkedKeys[key];
|
|
863
|
-
} else if (type == 2) {
|
|
864
|
-
this.checkedKeys[key] = [];
|
|
865
|
-
this.checkedKeys.temp = [];
|
|
866
|
-
this.autoExpandParent = true;
|
|
867
|
-
}
|
|
868
|
-
},
|
|
869
|
-
|
|
870
|
-
checkAllSearchTree(type) {
|
|
871
|
-
if (!this.searchTreeVisable) return false;
|
|
872
|
-
|
|
873
|
-
if (type == 1) {
|
|
874
|
-
// 全选默认不选中父级
|
|
875
|
-
let allSearchkeysMain = this.search.dataListKeys.main.filter(key => {
|
|
876
|
-
return !this.search.defaultExpandedKeys.includes(key);
|
|
877
|
-
});
|
|
878
|
-
|
|
879
|
-
let allSearchkeysOther = this.search.dataListKeys.other;
|
|
880
|
-
|
|
881
|
-
this.checkedKeys.main = vexutils.uniq([...this.checkedKeys.main, ...allSearchkeysMain]);
|
|
882
|
-
this.checkedKeys.other = vexutils.uniq([...this.checkedKeys.other, ...allSearchkeysOther]);
|
|
883
|
-
|
|
884
|
-
// 如果子级全选,父级也需要选中
|
|
885
|
-
this.search.dataListKeys.main.forEach(key => {
|
|
886
|
-
let getParentKey = this.getParentKey(key, this.treeData.main);
|
|
887
|
-
let parent = this.treeData.main.filter(item => {
|
|
888
|
-
return item.key == getParentKey;
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
let allCheck = parent[0].children.every(item => {
|
|
892
|
-
return this.checkedKeys.main.includes(item.key);
|
|
893
|
-
});
|
|
894
|
-
allCheck && this.checkedKeys.main.push(getParentKey);
|
|
895
|
-
});
|
|
896
|
-
this.refreshSearchTree();
|
|
897
|
-
} else if (type == 2) {
|
|
898
|
-
this.$refs['searchTree'].emptyCheckedKeys();
|
|
899
|
-
this.autoExpandParent = true;
|
|
900
|
-
}
|
|
901
|
-
this.isSearchAllCheck();
|
|
902
|
-
return true;
|
|
903
|
-
},
|
|
904
|
-
|
|
905
|
-
refreshSearchTree() {
|
|
906
|
-
if (!this.searchTreeVisable) return false;
|
|
907
|
-
this.$refs['searchTree'].setDefaultCheckedKeys();
|
|
908
|
-
this.$nextTick(() => {
|
|
909
|
-
this.isSearchAllCheck();
|
|
910
|
-
});
|
|
911
|
-
},
|
|
912
|
-
|
|
913
|
-
// 展开数节点
|
|
914
|
-
onExpand(expandedKeys) {
|
|
915
|
-
// const latestOpenKey = expandedKeys.find(key => this.expandedKeys.indexOf(key) == -1);
|
|
916
|
-
// this.expandedKeys = latestOpenKey ? [latestOpenKey] : [];
|
|
917
|
-
// this.autoExpandParent = false;
|
|
918
|
-
this.expandedKeys = expandedKeys;
|
|
919
|
-
this.autoExpandParent = false;
|
|
920
|
-
// this.$emit('expand', expandedKeys, ...arg)
|
|
921
|
-
},
|
|
922
|
-
onExpandDept(expandedKeys) {
|
|
923
|
-
this.expandedDeptKeys = expandedKeys;
|
|
924
|
-
},
|
|
925
|
-
|
|
926
|
-
searchClick() {
|
|
927
|
-
this.searchValue = this.title;
|
|
928
|
-
|
|
929
|
-
this.treeData.search = [];
|
|
930
|
-
this.search.dataListKeys.other = [];
|
|
931
|
-
this.search.dataListKeys.main = [];
|
|
932
|
-
this.search.defaultExpandedKeys = [];
|
|
933
|
-
|
|
934
|
-
this.spinning = true;
|
|
935
|
-
this.searchPage = 1;
|
|
936
|
-
this.searchFetch();
|
|
937
|
-
},
|
|
938
|
-
|
|
939
|
-
isAllCheck(checkedKeys = []) {
|
|
940
|
-
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
941
|
-
if (!checkedKeys || checkedKeys.length == 0) {
|
|
942
|
-
this.indeterminate = false;
|
|
943
|
-
this.singleChecked = false;
|
|
944
|
-
} else {
|
|
945
|
-
let keyArr = this.treeData[key].map(item => item.key);
|
|
946
|
-
let keyArrTemp = keyArr.filter(item => checkedKeys.indexOf(item) !== -1);
|
|
947
|
-
this.indeterminate = !(keyArr.length == keyArrTemp.length);
|
|
948
|
-
this.singleChecked = keyArr.length == keyArrTemp.length;
|
|
949
|
-
}
|
|
950
|
-
},
|
|
951
|
-
|
|
952
|
-
isSearchAllCheck() {
|
|
953
|
-
this.$nextTick(() => {
|
|
954
|
-
let skeyArr = this.treeData.search.map(item => item.key);
|
|
955
|
-
let serchCheckedKeys = this.$refs['searchTree'].checkedKeys;
|
|
956
|
-
this.searchIndeterminate = !!serchCheckedKeys.length && serchCheckedKeys.length < skeyArr.length;
|
|
957
|
-
this.searchChecked = serchCheckedKeys.length === skeyArr.length;
|
|
958
|
-
});
|
|
959
|
-
},
|
|
960
|
-
|
|
961
|
-
/* 子组件emit方法 */
|
|
962
|
-
addCheckedkeysMain(keys) {
|
|
963
|
-
let checkedKeys = this.checkedKeys.main;
|
|
964
|
-
let filterKey = (keys || {}).filter(Boolean);
|
|
965
|
-
filterKey.forEach(key => {
|
|
966
|
-
//
|
|
967
|
-
checkedKeys.push(key);
|
|
968
|
-
// 如果子级全选,父级也需要选中
|
|
969
|
-
let getParentKey = this.getParentKey(key, this.treeData.main);
|
|
970
|
-
if (!getParentKey) return;
|
|
971
|
-
let parent = this.treeData.main.filter(item => {
|
|
972
|
-
return item.key == getParentKey;
|
|
973
|
-
});
|
|
974
|
-
let allCheck = (parent[0]?.children || []).every(item => {
|
|
975
|
-
return checkedKeys.includes(item.key);
|
|
976
|
-
});
|
|
977
|
-
allCheck && checkedKeys.push(getParentKey);
|
|
978
|
-
});
|
|
979
|
-
},
|
|
980
|
-
|
|
981
|
-
removeCheckedkeysMain(keys) {
|
|
982
|
-
let checkedKeysMain = vexutils.clone(this.checkedKeys.main, true);
|
|
983
|
-
keys.forEach(key => {
|
|
984
|
-
//
|
|
985
|
-
let index = checkedKeysMain.findIndex(mainKey => mainKey == key);
|
|
986
|
-
if (index !== -1) {
|
|
987
|
-
checkedKeysMain.splice(index, 1);
|
|
988
|
-
this.checkedKeys.main = [...checkedKeysMain];
|
|
989
|
-
}
|
|
990
|
-
// 删除父级选中
|
|
991
|
-
let getParentKey = this.getParentKey(key, this.treeData.main);
|
|
992
|
-
let parentIndex = checkedKeysMain.findIndex(mainKey => mainKey == getParentKey);
|
|
993
|
-
if (parentIndex !== -1) {
|
|
994
|
-
checkedKeysMain.splice(parentIndex, 1);
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
|
|
998
|
-
this.checkedKeys.main = [...checkedKeysMain];
|
|
999
|
-
},
|
|
1000
|
-
|
|
1001
|
-
addCheckedkeysOther(keys) {
|
|
1002
|
-
this.checkedKeys.other.push(...keys);
|
|
1003
|
-
// this.checkedKeys.main.push(...keys);
|
|
1004
|
-
},
|
|
1005
|
-
|
|
1006
|
-
removeCheckedkeysOther(keys) {
|
|
1007
|
-
let checkedKeys = this.checkedKeys.other;
|
|
1008
|
-
// let mainCheckedKeys = this.checkedKeys.main;
|
|
1009
|
-
keys.forEach(key => {
|
|
1010
|
-
let index = checkedKeys.findIndex(otherKey => otherKey == key);
|
|
1011
|
-
checkedKeys.splice(index, 1);
|
|
1012
|
-
this.handleDeldefaultShowList(key);
|
|
1013
|
-
|
|
1014
|
-
// let mindex = mainCheckedKeys.findIndex(otherKey => otherKey == key);
|
|
1015
|
-
// mainCheckedKeys.splice(mindex, 1);
|
|
1016
|
-
});
|
|
1017
|
-
this.removeCheckedkeysMain(keys);
|
|
1018
|
-
},
|
|
1019
|
-
|
|
1020
|
-
handleDeldefaultShowList(key) {
|
|
1021
|
-
let len = this?.defaultShowList?.length || 0;
|
|
1022
|
-
if (len > 0) {
|
|
1023
|
-
for (let i = len - 1; i >= 0; i--) {
|
|
1024
|
-
let d = this.defaultShowList[i];
|
|
1025
|
-
if (`${d.parent_id}_${d.user_id}` == key) {
|
|
1026
|
-
this.closeDefaultTag(d, i);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
}
|
|
1030
|
-
},
|
|
1031
|
-
|
|
1032
|
-
closeDefaultTag(tag, i) {
|
|
1033
|
-
this.defaultShowList.splice(i, 1);
|
|
1034
|
-
this.closeTag({ parentId: this.getParentId(tag), ...tag });
|
|
1035
|
-
},
|
|
1036
|
-
|
|
1037
|
-
/* 右侧点击item[x]按钮 相关 */
|
|
1038
|
-
closeTag(removedTag) {
|
|
1039
|
-
// let { parentId } = removedTag;
|
|
1040
|
-
|
|
1041
|
-
this.removedCheckedkeysMain(removedTag);
|
|
1042
|
-
this.removedCheckedkeysDept(removedTag);
|
|
1043
|
-
this.removedCheckedkeysRole(removedTag);
|
|
1044
|
-
this.removedCheckedkeysOther(removedTag);
|
|
1045
|
-
const propStr = ['person', 'dept', 'role'][this.typeActiveIndex];
|
|
1046
|
-
const checkedKeys = this.checkedTreeItem.filter(item => item.itemType === propStr).map(item => item.key);
|
|
1047
|
-
this.checkedKeys.temp = checkedKeys;
|
|
1048
|
-
this.handleEmitValue();
|
|
1049
|
-
this.refreshSearchTree();
|
|
1050
|
-
this.isAllCheck(checkedKeys);
|
|
1051
|
-
},
|
|
1052
|
-
|
|
1053
|
-
removeCheckedkeysIncludeChildren(parentKey) {
|
|
1054
|
-
let needRemoveChildKeys = this.dataList.main
|
|
1055
|
-
.filter(i => {
|
|
1056
|
-
let parentId = this.getParentId(i);
|
|
1057
|
-
return parentId == parentKey || i.key == parentKey;
|
|
1058
|
-
})
|
|
1059
|
-
.map(i => {
|
|
1060
|
-
return i.key;
|
|
1061
|
-
});
|
|
1062
|
-
const checkedKeys = this.checkedKeys.main.filter(i => {
|
|
1063
|
-
return !needRemoveChildKeys.includes(i);
|
|
1064
|
-
});
|
|
1065
|
-
this.checkedKeys.main = checkedKeys;
|
|
1066
|
-
},
|
|
1067
|
-
|
|
1068
|
-
removedCheckedkeysMain(tag) {
|
|
1069
|
-
let checkedKeys = this.checkedKeys.main;
|
|
1070
|
-
let parentId = this.getParentId(tag);
|
|
1071
|
-
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1072
|
-
if (tag.key == checkedKeys[i] && tag.key == parentId) {
|
|
1073
|
-
this.removeCheckedkeysIncludeChildren(tag.key);
|
|
1074
|
-
return false;
|
|
1075
|
-
} else if (tag.key == checkedKeys[i]) {
|
|
1076
|
-
checkedKeys.splice(i, 1);
|
|
1077
|
-
return false;
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
},
|
|
1081
|
-
removeCheckedkeysIncludeChildrenDept(parentKey) {
|
|
1082
|
-
let needRemoveChildKeys = this.dataList.dept
|
|
1083
|
-
.filter(i => {
|
|
1084
|
-
let parentId = this.getParentId(i);
|
|
1085
|
-
return parentId == parentKey || i.key == parentKey;
|
|
1086
|
-
})
|
|
1087
|
-
.map(i => {
|
|
1088
|
-
return i.key;
|
|
1089
|
-
});
|
|
1090
|
-
const checkedKeys = this.checkedKeys.dept.filter(i => {
|
|
1091
|
-
return !needRemoveChildKeys.includes(i);
|
|
1092
|
-
});
|
|
1093
|
-
this.checkedKeys.dept = checkedKeys;
|
|
1094
|
-
},
|
|
1095
|
-
removedCheckedkeysDept(tag) {
|
|
1096
|
-
let checkedKeys = this.checkedKeys.dept;
|
|
1097
|
-
let parentId = this.getParentId(tag);
|
|
1098
|
-
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1099
|
-
if (tag.key == checkedKeys[i] && tag.key == parentId) {
|
|
1100
|
-
this.removeCheckedkeysIncludeChildrenDept(tag.key);
|
|
1101
|
-
return false;
|
|
1102
|
-
} else if (tag.key == checkedKeys[i]) {
|
|
1103
|
-
checkedKeys.splice(i, 1);
|
|
1104
|
-
return false;
|
|
1105
|
-
}
|
|
1106
|
-
}
|
|
1107
|
-
},
|
|
1108
|
-
removedCheckedkeysRole(tag) {
|
|
1109
|
-
let checkedKeys = this.checkedKeys.role;
|
|
1110
|
-
let parentId = '';
|
|
1111
|
-
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1112
|
-
if (tag.key == checkedKeys[i] && tag.key == parentId) {
|
|
1113
|
-
// this.removeCheckedkeysIncludeChildren(tag.key);
|
|
1114
|
-
return false;
|
|
1115
|
-
} else if (tag.key == checkedKeys[i]) {
|
|
1116
|
-
checkedKeys.splice(i, 1);
|
|
1117
|
-
return false;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
},
|
|
1121
|
-
|
|
1122
|
-
removedCheckedkeysOther(tag) {
|
|
1123
|
-
let checkedKeys = this.checkedKeys.other;
|
|
1124
|
-
if (checkedKeys.includes(tag.key)) {
|
|
1125
|
-
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1126
|
-
if (tag.key == checkedKeys[i]) {
|
|
1127
|
-
checkedKeys.splice(i, 1);
|
|
1128
|
-
return false;
|
|
1129
|
-
}
|
|
1130
|
-
}
|
|
1131
|
-
} else {
|
|
1132
|
-
// 删除科室,删除
|
|
1133
|
-
this.OtherRemoveCheckedkeysIncludeChildren(tag.key);
|
|
1134
|
-
}
|
|
1135
|
-
},
|
|
1136
|
-
|
|
1137
|
-
OtherRemoveCheckedkeysIncludeChildren(parentKey) {
|
|
1138
|
-
let needRemoveChildKeys = this.dataList.main
|
|
1139
|
-
.filter(i => {
|
|
1140
|
-
let parentId = this.getParentId(i);
|
|
1141
|
-
return parentId == parentKey || i.key == parentKey;
|
|
1142
|
-
})
|
|
1143
|
-
.map(i => {
|
|
1144
|
-
return i.key;
|
|
1145
|
-
});
|
|
1146
|
-
|
|
1147
|
-
this.checkedKeys.other = this.checkedKeys.other.filter(i => {
|
|
1148
|
-
return !needRemoveChildKeys.includes(i);
|
|
1149
|
-
});
|
|
1150
|
-
},
|
|
1151
|
-
|
|
1152
|
-
/* submit 相关 */
|
|
1153
|
-
getCheckedMainChildKeys() {
|
|
1154
|
-
return new Promise(async resolve => {
|
|
1155
|
-
let promises = this.treeData.main.map(async item => {
|
|
1156
|
-
// 获取勾选了父类tree, 但未获取children
|
|
1157
|
-
// 接口传参,需要的是叶节点的keys
|
|
1158
|
-
if (this.checkedKeys.main.includes(item.key) && !item.children) {
|
|
1159
|
-
item.children = await this.handleLoadChildData(item.key, item);
|
|
1160
|
-
this.addCheckedKeysChildrenMain(item);
|
|
1161
|
-
|
|
1162
|
-
this.generateDataList(item.children, this.dataList.main);
|
|
1163
|
-
}
|
|
1164
|
-
});
|
|
1165
|
-
|
|
1166
|
-
await Promise.all(promises);
|
|
1167
|
-
|
|
1168
|
-
resolve();
|
|
1169
|
-
});
|
|
1170
|
-
},
|
|
1171
|
-
|
|
1172
|
-
getCheckedLeafKeys() {
|
|
1173
|
-
let mainLeafKeys = [];
|
|
1174
|
-
let mainLeafDataListKeys = this.dataList.main.filter(item => item.isLeaf).map(item => item.key);
|
|
1175
|
-
|
|
1176
|
-
this.checkedKeys.main.forEach(key => {
|
|
1177
|
-
if (mainLeafDataListKeys.includes(key)) {
|
|
1178
|
-
mainLeafKeys.push(key);
|
|
1179
|
-
}
|
|
1180
|
-
});
|
|
1181
|
-
|
|
1182
|
-
let keyList = [...mainLeafKeys, ...this.checkedKeys.other];
|
|
1183
|
-
let res = [...new Set(keyList)];
|
|
1184
|
-
return [...res];
|
|
1185
|
-
},
|
|
1186
|
-
|
|
1187
|
-
async handleOk(isShowLoading = false) {
|
|
1188
|
-
isShowLoading && (this.spinning = true);
|
|
1189
|
-
this.queryLoadChildData && (await this.getCheckedMainChildKeys());
|
|
1190
|
-
|
|
1191
|
-
this.checkedLeafKeys = this.getCheckedLeafKeys();
|
|
1192
|
-
|
|
1193
|
-
const submitData = this.handleGetSumitData(this.checkedLeafKeys);
|
|
1194
|
-
|
|
1195
|
-
// let subList = [...submitData, ...this.defaultShowList];
|
|
1196
|
-
|
|
1197
|
-
this.$emit('pubCheckedTreeItem', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1198
|
-
this.$emit('check', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1199
|
-
this.$emit('handleOk', this.checkedLeafKeys);
|
|
1200
|
-
this.$emit('change', this.checkedLeafKeys, [...submitData, ...this.defaultShowList]);
|
|
1201
|
-
this.$emit('submitData', [...submitData, ...this.defaultShowList]);
|
|
1202
|
-
|
|
1203
|
-
isShowLoading && (this.spinning = false);
|
|
1204
|
-
},
|
|
1205
|
-
|
|
1206
|
-
handleEmitValue() {
|
|
1207
|
-
clearTimeout(this.emitTimeout);
|
|
1208
|
-
this.emitTimeout = setTimeout(() => {
|
|
1209
|
-
this.handleOk();
|
|
1210
|
-
}, 100);
|
|
1211
|
-
},
|
|
1212
|
-
|
|
1213
|
-
hanldeGetValue(...arg) {
|
|
1214
|
-
this.handleOk(...arg);
|
|
1215
|
-
},
|
|
1216
|
-
|
|
1217
|
-
// 获取表单提交的数据
|
|
1218
|
-
handleGetSumitData(list = []) {
|
|
1219
|
-
if (!Array.isArray(list)) return [];
|
|
1220
|
-
let resList = [];
|
|
1221
|
-
const { parent_id_obj, parent_name_obj, user_id_obj, user_name_obj } = this.wordbookConfig || {};
|
|
1222
|
-
list.forEach(v => {
|
|
1223
|
-
// d.key
|
|
1224
|
-
let f = this.dataList.main.find(d => this.getuniqKey(d) == v);
|
|
1225
|
-
if (!f) {
|
|
1226
|
-
f = this.dataList.other.find(o => this.getuniqKey(o) == v);
|
|
1227
|
-
}
|
|
1228
|
-
// [parent_id_obj]: f[parent_id_obj],
|
|
1229
|
-
// [parent_name_obj]: f[parent_name_obj],
|
|
1230
|
-
// [user_id_obj]: f[user_id_obj],
|
|
1231
|
-
// [user_name_obj]: f[user_name_obj]
|
|
1232
|
-
if (f) {
|
|
1233
|
-
/** 提交映射 */
|
|
1234
|
-
// 自定义 key 值
|
|
1235
|
-
const { parent_id_obj_key, parent_name_obj_key } = this.wordbook;
|
|
1236
|
-
const { user_id_obj_key, user_name_obj_key } = this.wordbookChild;
|
|
1237
|
-
resList.push({
|
|
1238
|
-
[user_id_obj_key || 'user_id']: f[user_id_obj],
|
|
1239
|
-
[user_name_obj_key || 'user_name']: f[user_name_obj],
|
|
1240
|
-
[parent_id_obj_key || 'parent_id']: f[parent_id_obj],
|
|
1241
|
-
[parent_name_obj_key || 'parent_name']: f[parent_name_obj]
|
|
1242
|
-
});
|
|
1243
|
-
}
|
|
1244
|
-
});
|
|
1245
|
-
return resList;
|
|
1246
|
-
},
|
|
1247
|
-
|
|
1248
|
-
cancel() {
|
|
1249
|
-
this.$emit('update:visible', false);
|
|
1250
|
-
this.spinning = false;
|
|
1251
|
-
},
|
|
1252
|
-
/* */
|
|
1253
|
-
treeCount(count) {
|
|
1254
|
-
if (!count) return '';
|
|
1255
|
-
return `(${count})`;
|
|
1256
|
-
},
|
|
1257
|
-
|
|
1258
|
-
staticDataSearch() {
|
|
1259
|
-
// let expandedKeys = new Set();
|
|
1260
|
-
// this.getStaticSearchParentKey(this.treeData.main, expandedKeys);
|
|
1261
|
-
// this.expandedKeys = Array.from(expandedKeys);
|
|
1262
|
-
// this.autoExpandParent = true;
|
|
1263
|
-
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
1264
|
-
if (!this.title) {
|
|
1265
|
-
// 如果为空恢复默认数据
|
|
1266
|
-
this.$set(this.treeData, 'temp', this.treeData[key]);
|
|
1267
|
-
return;
|
|
1268
|
-
}
|
|
1269
|
-
let copyData = JSON.parse(JSON.stringify(this.treeData[key]));
|
|
1270
|
-
// 增加visible属性 true展示 false不展示
|
|
1271
|
-
filterTree({ value: this.title, data: copyData, prop: 'title' });
|
|
1272
|
-
// 过滤visible属性 为true的数据
|
|
1273
|
-
copyData = copyData.filter(item => item.visible);
|
|
1274
|
-
const expandedKeys = [];
|
|
1275
|
-
vexutils.searchTree(copyData, item => {
|
|
1276
|
-
if (item.visible) {
|
|
1277
|
-
expandedKeys.push(item.key);
|
|
1278
|
-
}
|
|
1279
|
-
if (item.children && item.children.length) {
|
|
1280
|
-
item.children = item.children.filter(child => child.visible);
|
|
1281
|
-
}
|
|
1282
|
-
});
|
|
1283
|
-
this.$set(this.treeData, 'temp', copyData);
|
|
1284
|
-
this.expandedKeys = expandedKeys;
|
|
1285
|
-
},
|
|
1286
|
-
getStaticSearchParentKey(treeData, expandedKeys, orgId) {
|
|
1287
|
-
const keyword = this.title;
|
|
1288
|
-
for (let i = 0; i < treeData.length; i++) {
|
|
1289
|
-
const user = treeData[i];
|
|
1290
|
-
let { title = '', key, children } = user;
|
|
1291
|
-
if (keyword.length > 0 && (String(title).indexOf(keyword) !== -1 || String(key).indexOf(keyword) !== -1)) {
|
|
1292
|
-
expandedKeys.add(key);
|
|
1293
|
-
if (orgId) {
|
|
1294
|
-
expandedKeys.add(orgId);
|
|
1295
|
-
}
|
|
1296
|
-
break;
|
|
1297
|
-
}
|
|
1298
|
-
if (children) {
|
|
1299
|
-
this.getStaticSearchParentKey(children, expandedKeys, user.key || orgId);
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
},
|
|
1303
|
-
|
|
1304
|
-
// 数组对象去重
|
|
1305
|
-
uniqArrObj(arr, name) {
|
|
1306
|
-
let obj = {};
|
|
1307
|
-
return arr.reduce((cur, next) => {
|
|
1308
|
-
obj[next[name]] ? '' : (obj[next[name]] = true && cur.push(next));
|
|
1309
|
-
return cur;
|
|
1310
|
-
}, []);
|
|
1311
|
-
},
|
|
1312
|
-
onTypeClick(index) {
|
|
1313
|
-
const key = ['main', 'dept', 'role'][index];
|
|
1314
|
-
const checkedKeys = this.checkedKeys[key];
|
|
1315
|
-
this.treeData.temp = this.treeData[key];
|
|
1316
|
-
this.checkedKeys.temp = checkedKeys;
|
|
1317
|
-
this.typeActiveIndex = index;
|
|
1318
|
-
// 处理全选框
|
|
1319
|
-
this.isAllCheck(checkedKeys);
|
|
1320
|
-
},
|
|
1321
|
-
onTreeCheck(checkedKeys, { checked, node }) {
|
|
1322
|
-
// 断掉了父子关系 要不然当存在一二级科室的时候 搜索二级科室 再选中会把一级也选中 ; 后续与产品沟通 不需要断 只取最后一级科室
|
|
1323
|
-
const propStr = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
1324
|
-
let totalCheckedKeys = [];
|
|
1325
|
-
// const keyData = this.dataList[propStr].find(item => item.key === node.eventKey);
|
|
1326
|
-
// let keyData = {};
|
|
1327
|
-
// vexutils.searchTree(this.treeData[propStr], item => {
|
|
1328
|
-
// if (item.key === node.eventKey) {
|
|
1329
|
-
// keyData = item;
|
|
1330
|
-
// }
|
|
1331
|
-
// });
|
|
1332
|
-
// vexutils.searchTree(keyData.children, item => {
|
|
1333
|
-
// childKeys.push(item.key);
|
|
1334
|
-
// });
|
|
1335
|
-
// if (checked) {
|
|
1336
|
-
// const singleCheckedKeys = this.getSingleCheckedKeys(propStr, this.treeData[propStr], keyData);
|
|
1337
|
-
// totalCheckedKeys = this.isSingleCheck ? singleCheckedKeys : [...new Set(checkedKeys.concat(childKeys))];
|
|
1338
|
-
// } else {
|
|
1339
|
-
// // totalCheckedKeys = checkedKeys;
|
|
1340
|
-
// totalCheckedKeys = this.isSingleCheck ? [] : checkedKeys.filter(key => !childKeys.includes(key));
|
|
1341
|
-
// }
|
|
1342
|
-
// 如果是选中就把之前选中和现在选中的合并做为temp值(兼容搜索的情况),
|
|
1343
|
-
if (checked) {
|
|
1344
|
-
const preChecked = this.checkedKeys[propStr];
|
|
1345
|
-
// 搜索时选中上级也要把它所有下级给选中 如果是选中一个下级但是也把其上级选中了要把上级选中给去掉
|
|
1346
|
-
const childKeys = [];
|
|
1347
|
-
let keyData = {};
|
|
1348
|
-
vexutils.searchTree(this.treeData[propStr], item => {
|
|
1349
|
-
if (item.key === node.eventKey) {
|
|
1350
|
-
keyData = item;
|
|
1351
|
-
}
|
|
1352
|
-
});
|
|
1353
|
-
vexutils.searchTree(keyData.children, item => {
|
|
1354
|
-
childKeys.push(item.key);
|
|
1355
|
-
});
|
|
1356
|
-
const allParentIds = getAllParentId(this.treeData[propStr], node.eventKey).filter(Boolean);
|
|
1357
|
-
totalCheckedKeys = [...new Set(preChecked.concat(checkedKeys, childKeys))].filter(id => !allParentIds.includes(id));
|
|
1358
|
-
} else {
|
|
1359
|
-
// 如果是取消从之前的选择中把当前点击的及其子级去除选中作为temp值(兼容搜索的情况)
|
|
1360
|
-
let keyData = {};
|
|
1361
|
-
const needCancelKeys = [node.eventKey];
|
|
1362
|
-
const preChecked = this.checkedKeys[propStr];
|
|
1363
|
-
vexutils.searchTree(this.treeData[propStr], item => {
|
|
1364
|
-
if (item.key === node.eventKey) {
|
|
1365
|
-
keyData = item;
|
|
1366
|
-
}
|
|
1367
|
-
});
|
|
1368
|
-
vexutils.searchTree(keyData.children, item => {
|
|
1369
|
-
needCancelKeys.push(item.key);
|
|
1370
|
-
});
|
|
1371
|
-
const allParentIds = getAllParentId(this.treeData[propStr], node.eventKey).filter(Boolean);
|
|
1372
|
-
totalCheckedKeys = [...new Set(preChecked.filter(key => !needCancelKeys.includes(key)))].filter(id => !allParentIds.includes(id));
|
|
1373
|
-
}
|
|
1374
|
-
this.checkedKeys.temp = totalCheckedKeys;
|
|
1375
|
-
this.checkedKeys[propStr] = totalCheckedKeys;
|
|
1376
|
-
this.isAllCheck(totalCheckedKeys);
|
|
1377
|
-
this.isSearchAllCheck(totalCheckedKeys);
|
|
1378
|
-
this.$emit('pubCheckedTreeItem', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1379
|
-
this.$emit('check', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1380
|
-
},
|
|
1381
|
-
getSingleCheckedKeys(propStr, treeData, keyData) {
|
|
1382
|
-
const firstTreeData = deepTraversalFirst(keyData) || [];
|
|
1383
|
-
let checkedKeys = [];
|
|
1384
|
-
if (propStr === 'main') {
|
|
1385
|
-
checkedKeys = firstTreeData.map(item => item.key);
|
|
1386
|
-
} else if (propStr === 'dept') {
|
|
1387
|
-
// 如果是dept 找到层级为科室的第一个数据
|
|
1388
|
-
const index = firstTreeData.findIndex(item => item.type === 1);
|
|
1389
|
-
if (index > -1) {
|
|
1390
|
-
checkedKeys = firstTreeData.slice(0, index + 1).map(item => item.key);
|
|
1391
|
-
} else {
|
|
1392
|
-
checkedKeys = firstTreeData.map(item => item.key);
|
|
1393
|
-
}
|
|
1394
|
-
} else if (propStr === 'role') {
|
|
1395
|
-
// 如果是dept 找到层级为角色的第一个数据
|
|
1396
|
-
const index = firstTreeData.findIndex(item => item.roleId);
|
|
1397
|
-
if (index > -1) {
|
|
1398
|
-
checkedKeys = firstTreeData.slice(0, index + 1).map(item => item.key);
|
|
1399
|
-
} else {
|
|
1400
|
-
checkedKeys = firstTreeData.map(item => item.key);
|
|
1401
|
-
}
|
|
1402
|
-
}
|
|
1403
|
-
return checkedKeys;
|
|
1404
|
-
},
|
|
1405
|
-
|
|
1406
|
-
onClearSelect() {
|
|
1407
|
-
this.checkedKeys.temp = [];
|
|
1408
|
-
this.checkedKeys.main = [];
|
|
1409
|
-
this.checkedKeys.dept = [];
|
|
1410
|
-
this.checkedKeys.role = [];
|
|
1411
|
-
this.defaultShowList = [];
|
|
1412
|
-
this.indeterminate = false;
|
|
1413
|
-
this.singleChecked = false;
|
|
1414
|
-
},
|
|
1415
|
-
filterTreeData({ value, data, prop, filter, filterXor, children, visible, filterChildren = true, callback }) {
|
|
1416
|
-
// 默认赋值
|
|
1417
|
-
visible = visible || 'visible';
|
|
1418
|
-
children = children || 'children';
|
|
1419
|
-
prop = prop || 'text';
|
|
1420
|
-
|
|
1421
|
-
const filterNodeMethod = function(value, data) {
|
|
1422
|
-
if (!value) {
|
|
1423
|
-
return true;
|
|
1424
|
-
}
|
|
1425
|
-
let flag = (data[prop] || '').indexOf(value) !== -1;
|
|
1426
|
-
return filterXor ? !flag : flag;
|
|
1427
|
-
};
|
|
1428
|
-
|
|
1429
|
-
const traverse = function(node) {
|
|
1430
|
-
const childNodes = node[children] || [];
|
|
1431
|
-
|
|
1432
|
-
childNodes.forEach(child => {
|
|
1433
|
-
callback && callback(child);
|
|
1434
|
-
child[visible] = (!node.root && !filterChildren && node[visible]) || filterNodeMethod.call(child, value, child, prop);
|
|
1435
|
-
|
|
1436
|
-
traverse(child);
|
|
1437
|
-
});
|
|
1438
|
-
|
|
1439
|
-
if (!node[visible] && childNodes.length) {
|
|
1440
|
-
let allHidden = true;
|
|
1441
|
-
allHidden = !childNodes.some(child => child[visible]);
|
|
1442
|
-
|
|
1443
|
-
node[visible] = allHidden === false;
|
|
1444
|
-
}
|
|
1445
|
-
};
|
|
1446
|
-
let totalData = {
|
|
1447
|
-
root: true
|
|
1448
|
-
};
|
|
1449
|
-
totalData[children] = data;
|
|
1450
|
-
traverse(totalData);
|
|
1451
|
-
|
|
1452
|
-
if (filter) {
|
|
1453
|
-
let copyData = data.slice();
|
|
1454
|
-
let filterHandle = filterData => {
|
|
1455
|
-
return filterData.filter((item, index) => {
|
|
1456
|
-
if (item[visible]) {
|
|
1457
|
-
if (item[children]) {
|
|
1458
|
-
item[children] = filterHandle(item[children]);
|
|
1459
|
-
}
|
|
1460
|
-
return true;
|
|
1461
|
-
}
|
|
1462
|
-
return false;
|
|
1463
|
-
});
|
|
1464
|
-
};
|
|
1465
|
-
return filterHandle(copyData);
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
}
|
|
1469
|
-
});
|
|
1470
|
-
</script>
|
|
1471
|
-
<style lang="less" scoped>
|
|
1472
|
-
@primary-color: #2563f4;
|
|
1473
|
-
.people-tree {
|
|
1474
|
-
display: flex;
|
|
1475
|
-
.people-tree-item {
|
|
1476
|
-
width: 50%;
|
|
1477
|
-
padding: 22px 12px 0;
|
|
1478
|
-
max-height: 376px;
|
|
1479
|
-
height: 376px;
|
|
1480
|
-
overflow-y: auto;
|
|
1481
|
-
&.people-tree-left {
|
|
1482
|
-
display: flex;
|
|
1483
|
-
flex-direction: column;
|
|
1484
|
-
}
|
|
1485
|
-
/deep/ .person-search {
|
|
1486
|
-
// .ant-input-affix-wrapper .ant-input:not(:last-child),
|
|
1487
|
-
// .ant-input-affix-wrapper .ant-input:not(:first-child) {
|
|
1488
|
-
// padding-left: 34px;
|
|
1489
|
-
// }
|
|
1490
|
-
.ant-input-group-addon {
|
|
1491
|
-
padding: 0;
|
|
1492
|
-
border: 0px !important;
|
|
1493
|
-
}
|
|
1494
|
-
.ant-input-search-button {
|
|
1495
|
-
border-top-left-radius: 0;
|
|
1496
|
-
border-bottom-left-radius: 0;
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
/deep/ .main-tree-container {
|
|
1500
|
-
> li {
|
|
1501
|
-
width: 100%;
|
|
1502
|
-
overflow: hidden;
|
|
1503
|
-
}
|
|
1504
|
-
.ant-tree-switcher {
|
|
1505
|
-
flex-shrink: 0;
|
|
1506
|
-
}
|
|
1507
|
-
.ant-tree-node-content-wrapper {
|
|
1508
|
-
width: 90%;
|
|
1509
|
-
text-overflow: ellipsis;
|
|
1510
|
-
overflow: hidden;
|
|
1511
|
-
white-space: nowrap;
|
|
1512
|
-
}
|
|
1513
|
-
}
|
|
1514
|
-
/deep/.ant-tree-title {
|
|
1515
|
-
// width: 250px;
|
|
1516
|
-
width: 100%;
|
|
1517
|
-
text-overflow: ellipsis;
|
|
1518
|
-
overflow: hidden;
|
|
1519
|
-
white-space: nowrap;
|
|
1520
|
-
display: inline-block;
|
|
1521
|
-
}
|
|
1522
|
-
&:first-child {
|
|
1523
|
-
border-right: 1px solid #e8e8e8;
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
.no-data-tips {
|
|
1527
|
-
height: 200px;
|
|
1528
|
-
width: 100%;
|
|
1529
|
-
display: flex;
|
|
1530
|
-
justify-content: center;
|
|
1531
|
-
align-items: center;
|
|
1532
|
-
font-size: 16px;
|
|
1533
|
-
font-weight: 700;
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
.c-title {
|
|
1537
|
-
font-size: 14px;
|
|
1538
|
-
font-family: PingFangSC-Regular, PingFang SC;
|
|
1539
|
-
font-weight: 400;
|
|
1540
|
-
color: #212121;
|
|
1541
|
-
}
|
|
1542
|
-
.c-sub-title {
|
|
1543
|
-
font-size: 12px;
|
|
1544
|
-
font-family: PingFangSC-Regular, PingFang SC;
|
|
1545
|
-
// font-weight: 400;
|
|
1546
|
-
color: #4e4e4e;
|
|
1547
|
-
}
|
|
1548
|
-
.p-title {
|
|
1549
|
-
font-size: 14px;
|
|
1550
|
-
font-family: PingFangSC-Medium, PingFang SC;
|
|
1551
|
-
font-weight: 500;
|
|
1552
|
-
color: #212121;
|
|
1553
|
-
}
|
|
1554
|
-
}
|
|
1555
|
-
/deep/.ant-tree {
|
|
1556
|
-
overflow-y: auto;
|
|
1557
|
-
// height: 450px;
|
|
1558
|
-
flex: 1;
|
|
1559
|
-
position: relative;
|
|
1560
|
-
&::-webkit-scrollbar {
|
|
1561
|
-
width: 6px;
|
|
1562
|
-
height: 6px;
|
|
1563
|
-
background-color: #f5f5f5;
|
|
1564
|
-
}
|
|
1565
|
-
}
|
|
1566
|
-
.select-wrap {
|
|
1567
|
-
flex: 1;
|
|
1568
|
-
padding: 22px 12px 0;
|
|
1569
|
-
height: 376px;
|
|
1570
|
-
display: flex;
|
|
1571
|
-
flex-direction: column;
|
|
1572
|
-
.select-header {
|
|
1573
|
-
display: flex;
|
|
1574
|
-
justify-content: space-between;
|
|
1575
|
-
margin-bottom: 20px;
|
|
1576
|
-
.clear-btn {
|
|
1577
|
-
color: @primary-color;
|
|
1578
|
-
cursor: pointer;
|
|
1579
|
-
}
|
|
1580
|
-
}
|
|
1581
|
-
.select-content {
|
|
1582
|
-
flex: 1;
|
|
1583
|
-
overflow-y: auto;
|
|
1584
|
-
.tag-item {
|
|
1585
|
-
&.isRoot {
|
|
1586
|
-
background: rgba(@primary-color, 0.08);
|
|
1587
|
-
border: 1px solid rgba(@primary-color, 0.5);
|
|
1588
|
-
color: @primary-color;
|
|
1589
|
-
.tag-close {
|
|
1590
|
-
color: @primary-color;
|
|
1591
|
-
&:hover {
|
|
1592
|
-
color: rgba(@primary-color, 0.6);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
}
|
|
1596
|
-
|
|
1597
|
-
box-sizing: border-box;
|
|
1598
|
-
color: #212121;
|
|
1599
|
-
font-size: 14px;
|
|
1600
|
-
list-style: none;
|
|
1601
|
-
display: inline-flex;
|
|
1602
|
-
align-items: center;
|
|
1603
|
-
height: 24px;
|
|
1604
|
-
line-height: 24px;
|
|
1605
|
-
margin-right: 8px;
|
|
1606
|
-
margin-bottom: 4px;
|
|
1607
|
-
padding: 0 6px;
|
|
1608
|
-
white-space: nowrap;
|
|
1609
|
-
background: rgba(#d5d5d5, 0.2);
|
|
1610
|
-
border: 1px solid rgba(#000000, 0.14);
|
|
1611
|
-
border-radius: 4px;
|
|
1612
|
-
transition: all 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
1613
|
-
.tag-close {
|
|
1614
|
-
font-size: 12px;
|
|
1615
|
-
&:hover {
|
|
1616
|
-
color: rgba(@primary-color, 0.6);
|
|
1617
|
-
}
|
|
1618
|
-
&:active {
|
|
1619
|
-
color: #fff;
|
|
1620
|
-
}
|
|
1621
|
-
display: inline-block;
|
|
1622
|
-
font-size: 14px;
|
|
1623
|
-
margin-left: 3px;
|
|
1624
|
-
color: #969696;
|
|
1625
|
-
font-weight: 700;
|
|
1626
|
-
cursor: pointer;
|
|
1627
|
-
transition: all 0.3s;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
}
|
|
1633
|
-
.df {
|
|
1634
|
-
display: flex;
|
|
1635
|
-
}
|
|
1636
|
-
.search-input-icon {
|
|
1637
|
-
color: rgba(0, 0, 0, 0.4);
|
|
1638
|
-
margin-bottom: -2px;
|
|
1639
|
-
}
|
|
1640
|
-
.type-wrap {
|
|
1641
|
-
display: flex;
|
|
1642
|
-
margin-bottom: 10px;
|
|
1643
|
-
.type-btn {
|
|
1644
|
-
margin-right: 10px;
|
|
1645
|
-
padding: 2px 10px;
|
|
1646
|
-
background: #f2f2f2;
|
|
1647
|
-
border-radius: 8px;
|
|
1648
|
-
cursor: pointer;
|
|
1649
|
-
&:last-child {
|
|
1650
|
-
margin-right: 0;
|
|
1651
|
-
}
|
|
1652
|
-
}
|
|
1653
|
-
.type-active {
|
|
1654
|
-
background: @primary-color;
|
|
1655
|
-
color: #ffffff;
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="personnel">
|
|
3
|
+
<a-spin :spinning="spinning">
|
|
4
|
+
<div class="people-tree">
|
|
5
|
+
<!-- 树主体与检索 -->
|
|
6
|
+
<div class="people-tree-item people-tree-left">
|
|
7
|
+
<!-- $t('1.1.1.5.1') -->
|
|
8
|
+
<a-input-search style="margin-bottom: 12px" :placeholder="searchPlaceholder" :enter-button="searchButtonText" :allowClear="true" @search="searchClick" v-model="title" class="person-search">
|
|
9
|
+
<!-- <a-icon slot="prefix" type="search" class="search-input-icon" /> -->
|
|
10
|
+
<!-- <svg-icon
|
|
11
|
+
slot="prefix"
|
|
12
|
+
class="search-input-icon"
|
|
13
|
+
iconClass="xitongtubiaosousuo"
|
|
14
|
+
></svg-icon> -->
|
|
15
|
+
</a-input-search>
|
|
16
|
+
<div class="type-wrap" v-if="selectType === 'multiple'">
|
|
17
|
+
<div class="type-btn" :class="{ 'type-active': typeActiveIndex === 0 }" @click="onTypeClick(0)">选人员</div>
|
|
18
|
+
<div class="type-btn" :class="{ 'type-active': typeActiveIndex === 1 }" @click="onTypeClick(1)">选科室</div>
|
|
19
|
+
<div class="type-btn" :class="{ 'type-active': typeActiveIndex === 2 }" @click="onTypeClick(2)">选角色</div>
|
|
20
|
+
</div>
|
|
21
|
+
<template v-if="!isSingleCheck">
|
|
22
|
+
<a-checkbox v-if="searchTreeVisable" v-model="searchChecked" :indeterminate="searchIndeterminate" @change="radioChange">
|
|
23
|
+
<!-- {{ $t("1.10.139") }} -->
|
|
24
|
+
全选
|
|
25
|
+
</a-checkbox>
|
|
26
|
+
|
|
27
|
+
<a-checkbox v-else v-model="singleChecked" :indeterminate="indeterminate" @change="radioChange">
|
|
28
|
+
<!-- {{ $t("1.10.139") }} -->
|
|
29
|
+
全选
|
|
30
|
+
</a-checkbox>
|
|
31
|
+
</template>
|
|
32
|
+
|
|
33
|
+
<div v-show="search.status == 3 || (search.status == 0 && treeData.temp && treeData.temp.length == 0)" class="no-data-tips">
|
|
34
|
+
查无结果
|
|
35
|
+
</div>
|
|
36
|
+
<!-- main tree -->
|
|
37
|
+
<a-tree
|
|
38
|
+
class="main-tree-container"
|
|
39
|
+
v-show="search.status == 0"
|
|
40
|
+
ref="antTree"
|
|
41
|
+
v-model="checkedKeys.temp"
|
|
42
|
+
@expand="onExpand"
|
|
43
|
+
@check="onTreeCheck"
|
|
44
|
+
checkable
|
|
45
|
+
:expandedKeys="expandedKeys"
|
|
46
|
+
:autoExpandParent="autoExpandParent"
|
|
47
|
+
:checkStrictly="false"
|
|
48
|
+
:selectable="false"
|
|
49
|
+
:treeData="treeData.temp"
|
|
50
|
+
:load-data="getLoadChildData"
|
|
51
|
+
:disabled="isDetail"
|
|
52
|
+
>
|
|
53
|
+
<template slot="custom" slot-scope="scope">
|
|
54
|
+
<span v-if="scope.isLeaf">
|
|
55
|
+
<a-tooltip :title="`${scope.title} ${scope.sub_title}`" :mouseEnterDelay="0.3">
|
|
56
|
+
<span class="c-title">{{ scope.title || scope.key }}  </span>
|
|
57
|
+
<span class="c-sub-title">{{ scope.sub_title }}</span>
|
|
58
|
+
</a-tooltip>
|
|
59
|
+
</span>
|
|
60
|
+
<span v-else class="p-title">
|
|
61
|
+
<span v-if="scope.title">{{ scope.title }}</span>
|
|
62
|
+
<span v-else>{{ scope.key }}</span>
|
|
63
|
+
{{ treeCount(scope.count) }}
|
|
64
|
+
</span>
|
|
65
|
+
</template>
|
|
66
|
+
</a-tree>
|
|
67
|
+
<!-- search tree -->
|
|
68
|
+
<searchTree
|
|
69
|
+
v-on="$listeners"
|
|
70
|
+
ref="searchTree"
|
|
71
|
+
:visable="searchTreeVisable"
|
|
72
|
+
:formatTreeData="treeData.search"
|
|
73
|
+
:searchValue="searchValue"
|
|
74
|
+
:allCheckedKeys="checkedKeys"
|
|
75
|
+
:defaultExpandedKeys="search.defaultExpandedKeys"
|
|
76
|
+
:dataListKeys="search.dataListKeys"
|
|
77
|
+
:searchNoMore="searchNoMore"
|
|
78
|
+
:loadMorenLoadinng="loadMorenLoadinng"
|
|
79
|
+
@addCheckedkeysMain="addCheckedkeysMain"
|
|
80
|
+
@removeCheckedkeysMain="removeCheckedkeysMain"
|
|
81
|
+
@addCheckedkeysOther="addCheckedkeysOther"
|
|
82
|
+
@removeCheckedkeysOther="removeCheckedkeysOther"
|
|
83
|
+
@searchOnloadMore="searchOnloadMore"
|
|
84
|
+
></searchTree>
|
|
85
|
+
</div>
|
|
86
|
+
<!-- 树已选的数据 -->
|
|
87
|
+
<div class="select-wrap">
|
|
88
|
+
<div class="select-header" v-if="(defaultShowList && defaultShowList.length) || checkedTreeItem.length">
|
|
89
|
+
<div class="select-count" v-if="showCount">已选择:{{ defaultShowList.length + checkedTreeItem.length }}</div>
|
|
90
|
+
<div class="clear-btn" @click="onClearSelect" v-if="showClear">清空</div>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="select-content">
|
|
93
|
+
<slot v-if="defaultShowList && defaultShowList.length">
|
|
94
|
+
<div class="tag-item def-item" v-for="(tag, i) in defaultShowList" :key="i">
|
|
95
|
+
{{ tag.title || tag[wordbookChild.user_name_obj] }}
|
|
96
|
+
<a-icon v-if="!isDetail" class="tag-close" type="close-circle" theme="filled" @click="closeDefaultTag(tag, i)" />
|
|
97
|
+
<!-- <svg-icon
|
|
98
|
+
v-if="!isDetail"
|
|
99
|
+
class="tag-close"
|
|
100
|
+
:icon-class="'xitongtubiaodaohangtubiaoguanbishixin'"
|
|
101
|
+
@click="closeDefaultTag(tag, i)"
|
|
102
|
+
></svg-icon> -->
|
|
103
|
+
</div>
|
|
104
|
+
</slot>
|
|
105
|
+
|
|
106
|
+
<div class="tag-item" :class="{ isRoot: !tag.isLeaf }" v-for="tag in checkedTreeItem" :key="tag.key">
|
|
107
|
+
{{ tag.title || tag.key }} {{ treeCount(tag.count) }}
|
|
108
|
+
<!-- <svg-icon
|
|
109
|
+
v-if="!isDetail"
|
|
110
|
+
class="tag-close"
|
|
111
|
+
:icon-class="'xitongtubiaodaohangtubiaoguanbishixin'"
|
|
112
|
+
@click="closeTag(tag)"
|
|
113
|
+
></svg-icon> -->
|
|
114
|
+
<a-icon v-if="!isDetail" class="tag-close" type="close-circle" theme="filled" @click="closeTag(tag)" />
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
</a-spin>
|
|
120
|
+
</div>
|
|
121
|
+
</template>
|
|
122
|
+
<script>
|
|
123
|
+
/* eslint-disable no-async-promise-executor */
|
|
124
|
+
|
|
125
|
+
import { Icon, Checkbox, Tree, Tooltip, Input, Spin } from 'ant-design-vue';
|
|
126
|
+
import searchTree from './search-tree';
|
|
127
|
+
import create from '@/core/create';
|
|
128
|
+
import vexutils from '@/utils/vexutils';
|
|
129
|
+
import { filterTree, deepTraversalFirst, getAllParentId } from '@/utils';
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* 查询没有部门的分类时,parent_id_obj 为 undefined a-tree 展示异常。
|
|
133
|
+
* 前端 赋上固定key 标识 该分类 无部门,该key 不能提交接口。
|
|
134
|
+
* */
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* key 唯一key
|
|
138
|
+
* title 展示标题
|
|
139
|
+
* sub_title 副标题
|
|
140
|
+
* count 数量
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
const FIXEDKEY = '8982eeb4-0439-4100-9805-8cdd12b2256c-front-end-fixed-key';
|
|
144
|
+
export default create({
|
|
145
|
+
name: 'select-person',
|
|
146
|
+
components: {
|
|
147
|
+
searchTree,
|
|
148
|
+
[Icon.name]: Icon,
|
|
149
|
+
[Spin.name]: Spin,
|
|
150
|
+
[Tree.name]: Tree,
|
|
151
|
+
[Input.Search.name]: Input.Search,
|
|
152
|
+
[Checkbox.name]: Checkbox,
|
|
153
|
+
[Tooltip.name]: Tooltip
|
|
154
|
+
},
|
|
155
|
+
props: {
|
|
156
|
+
isDetail: { type: Boolean, isDetail: false },
|
|
157
|
+
defaultList: { type: Array, default: () => [] },
|
|
158
|
+
data: { type: Array, default: () => [] },
|
|
159
|
+
roleData: { type: Array, default: () => [] },
|
|
160
|
+
roleFields: {
|
|
161
|
+
type: Object,
|
|
162
|
+
default: () => ({ title: 'name', key: 'id', children: 'children' })
|
|
163
|
+
},
|
|
164
|
+
searchPlaceholder: {
|
|
165
|
+
type: String,
|
|
166
|
+
default: '输入关键字搜索'
|
|
167
|
+
},
|
|
168
|
+
searchButtonText: {
|
|
169
|
+
type: String,
|
|
170
|
+
default: '搜索'
|
|
171
|
+
},
|
|
172
|
+
// 父级配置
|
|
173
|
+
wordbook: {
|
|
174
|
+
type: Object,
|
|
175
|
+
default: () => ({
|
|
176
|
+
// parent_id_obj: "dept_id", // 父级 id
|
|
177
|
+
// parent_id_obj_key: "dept_id", // 提交的 id 的映射 key
|
|
178
|
+
// parent_name_obj: "dept_name", // 名称
|
|
179
|
+
// parent_name_obj_key: "dept_name", // 名称 的映射key
|
|
180
|
+
// user_count_obj: "count" // 统计 key
|
|
181
|
+
})
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
// 子集配置
|
|
185
|
+
wordbookChild: {
|
|
186
|
+
type: Object,
|
|
187
|
+
default: () => ({})
|
|
188
|
+
},
|
|
189
|
+
|
|
190
|
+
// 检索加载更多
|
|
191
|
+
SearchLoadMore: {
|
|
192
|
+
type: Boolean,
|
|
193
|
+
default: false
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
showClear: {
|
|
197
|
+
type: Boolean,
|
|
198
|
+
default: true
|
|
199
|
+
},
|
|
200
|
+
showCount: {
|
|
201
|
+
type: Boolean,
|
|
202
|
+
default: true
|
|
203
|
+
},
|
|
204
|
+
selectType: {
|
|
205
|
+
type: String,
|
|
206
|
+
default: 'person' // person dept role multiple
|
|
207
|
+
},
|
|
208
|
+
isSingleCheck: {
|
|
209
|
+
type: Boolean,
|
|
210
|
+
default: false
|
|
211
|
+
},
|
|
212
|
+
queryMainTreeData: Function, // 主树请求
|
|
213
|
+
queryLoadChildData: Function, // 懒加载请求
|
|
214
|
+
queryTreeSearch: Function // 检索请求
|
|
215
|
+
},
|
|
216
|
+
data() {
|
|
217
|
+
return {
|
|
218
|
+
treeData: {
|
|
219
|
+
main: [],
|
|
220
|
+
search: [],
|
|
221
|
+
dept: [],
|
|
222
|
+
role: [],
|
|
223
|
+
temp: []
|
|
224
|
+
},
|
|
225
|
+
// 展开的keys
|
|
226
|
+
expandedKeys: [],
|
|
227
|
+
// 展开的部门keys
|
|
228
|
+
expandedDeptKeys: [],
|
|
229
|
+
autoExpandParent: true,
|
|
230
|
+
// 扁平化tree的options Object{Array[Object]}
|
|
231
|
+
dataList: {
|
|
232
|
+
main: [],
|
|
233
|
+
other: [],
|
|
234
|
+
dept: [],
|
|
235
|
+
role: []
|
|
236
|
+
},
|
|
237
|
+
// 当前tree选中的keys Object{Array[Number]}
|
|
238
|
+
checkedKeys: {
|
|
239
|
+
main: [],
|
|
240
|
+
other: [],
|
|
241
|
+
dept: [],
|
|
242
|
+
role: [],
|
|
243
|
+
temp: []
|
|
244
|
+
},
|
|
245
|
+
search: {
|
|
246
|
+
defaultExpandedKeys: [],
|
|
247
|
+
// 0: 未查询,1:查询中,2:有查询结果,3无查询结果
|
|
248
|
+
status: 0,
|
|
249
|
+
dataListKeys: {
|
|
250
|
+
main: [],
|
|
251
|
+
other: []
|
|
252
|
+
},
|
|
253
|
+
records: 0
|
|
254
|
+
},
|
|
255
|
+
searchValue: '',
|
|
256
|
+
searchPage: 1,
|
|
257
|
+
searchNoMore: false,
|
|
258
|
+
title: '',
|
|
259
|
+
// 选中的所有叶节点(Leaf)keys <Array[Number]>,最终提交接口所需格式
|
|
260
|
+
checkedLeafKeys: [],
|
|
261
|
+
spinning: false,
|
|
262
|
+
loadMorenLoadinng: false,
|
|
263
|
+
|
|
264
|
+
errorMsg: '',
|
|
265
|
+
|
|
266
|
+
defaultShowList: [], // 默认选中项
|
|
267
|
+
checkedKeysMain: [],
|
|
268
|
+
|
|
269
|
+
cacheParentIdObj: {},
|
|
270
|
+
singleChecked: false,
|
|
271
|
+
indeterminate: false,
|
|
272
|
+
|
|
273
|
+
searchIndeterminate: false,
|
|
274
|
+
searchChecked: false,
|
|
275
|
+
typeActiveIndex: 0
|
|
276
|
+
};
|
|
277
|
+
},
|
|
278
|
+
computed: {
|
|
279
|
+
searchTreeVisable() {
|
|
280
|
+
return this.search.status == 2;
|
|
281
|
+
},
|
|
282
|
+
dataListMainKeys() {
|
|
283
|
+
if (!this.dataList.main.length) return [];
|
|
284
|
+
|
|
285
|
+
return this.dataList.main.map(i => {
|
|
286
|
+
return i.key;
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
dataListDeptKeys() {
|
|
290
|
+
if (!this.dataList.dept.length) return [];
|
|
291
|
+
|
|
292
|
+
return this.dataList.dept.map(i => {
|
|
293
|
+
return i.key;
|
|
294
|
+
});
|
|
295
|
+
},
|
|
296
|
+
dataListRoleKeys() {
|
|
297
|
+
if (!this.dataList.role.length) return [];
|
|
298
|
+
|
|
299
|
+
return this.dataList.role.map(i => {
|
|
300
|
+
return i.key;
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
dataListOtherKeys() {
|
|
304
|
+
if (!this.dataList.other.length) return [];
|
|
305
|
+
|
|
306
|
+
return this.dataList.other.map(i => {
|
|
307
|
+
return i.key;
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
// 右侧展示tabs <Array[Object]>
|
|
311
|
+
checkedTreeItem() {
|
|
312
|
+
let otherItems = this.dataList.other.filter(item => {
|
|
313
|
+
return this.checkedKeys.other.includes(item.key);
|
|
314
|
+
});
|
|
315
|
+
let mainItems = this.dataList.main.filter(item => {
|
|
316
|
+
// let f = this.currentKey === 'main';
|
|
317
|
+
// if(!f) return f;
|
|
318
|
+
let { isLeaf, key } = item;
|
|
319
|
+
let parentId = this.getParentId(item);
|
|
320
|
+
let showKeys = [...this.checkedKeys.main, ...otherItems];
|
|
321
|
+
let checked = showKeys.includes(key);
|
|
322
|
+
// 父级全选,子级不展示
|
|
323
|
+
/** String(parentId) 类型不相等 */
|
|
324
|
+
// if (isLeaf && parentId && this.checkedKeys.temp.some(v => v == parentId)) {
|
|
325
|
+
// checked = false;
|
|
326
|
+
// }
|
|
327
|
+
item.itemType = 'person';
|
|
328
|
+
return checked && item.type == 2;
|
|
329
|
+
});
|
|
330
|
+
let deptItems = this.dataList.dept.filter(item => {
|
|
331
|
+
let { key } = item;
|
|
332
|
+
let showKeys = [...this.checkedKeys.dept, ...otherItems];
|
|
333
|
+
let checked = showKeys.includes(key);
|
|
334
|
+
// 只展示最后一级的科室
|
|
335
|
+
item.itemType = 'dept';
|
|
336
|
+
return checked && item.type == 1 && (!item.children || (item.children && !item.children.length));
|
|
337
|
+
});
|
|
338
|
+
let roleItems = this.dataList.role.filter(item => {
|
|
339
|
+
let showKeys = [...this.checkedKeys.role, ...otherItems];
|
|
340
|
+
let checked = showKeys.includes(item.key);
|
|
341
|
+
item.itemType = 'role';
|
|
342
|
+
return checked && item.roleId;
|
|
343
|
+
});
|
|
344
|
+
if (this.selectType === 'multiple') {
|
|
345
|
+
deptItems.forEach(item => {
|
|
346
|
+
if (item.title) {
|
|
347
|
+
item.title = item.title.includes('(科室)') ? item.title : `${item.title}(科室)`;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
roleItems.map(item => {
|
|
351
|
+
if (item.title) {
|
|
352
|
+
item.title = item.title.includes('(角色)') ? item.title : `${item.title}(角色)`;
|
|
353
|
+
}
|
|
354
|
+
return item;
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
let list = this.uniqArrObj([...mainItems, ...deptItems, ...roleItems, ...otherItems], 'key');
|
|
359
|
+
return list;
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
wordbookConfig() {
|
|
363
|
+
const { parent_id_obj, parent_name_obj } = this.wordbook || {};
|
|
364
|
+
const { user_id_obj, user_name_obj } = this.wordbookChild || {};
|
|
365
|
+
return {
|
|
366
|
+
parent_id_obj,
|
|
367
|
+
parent_name_obj,
|
|
368
|
+
user_id_obj,
|
|
369
|
+
user_name_obj
|
|
370
|
+
};
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
getLoadChildData() {
|
|
374
|
+
if (typeof this.queryLoadChildData == 'function') {
|
|
375
|
+
return this.onLoadData;
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
currentKey() {
|
|
381
|
+
return { person: 'main', dept: 'dept', role: 'role', multiple: 'main' }[this.selectType];
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
watch: {
|
|
385
|
+
// defaultList: {
|
|
386
|
+
// immediate: true,
|
|
387
|
+
// handler(val) {
|
|
388
|
+
// if (!val) return;
|
|
389
|
+
// this.initDefault();
|
|
390
|
+
// }
|
|
391
|
+
// },
|
|
392
|
+
selectType: {
|
|
393
|
+
immediate: true,
|
|
394
|
+
handler(val) {
|
|
395
|
+
if (val === 'dept' || val === 'role' || val === 'multiple') {
|
|
396
|
+
this.typeActiveIndex = { multiple: 0, dept: 1, role: 2 }[val];
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
data: {
|
|
401
|
+
immediate: true,
|
|
402
|
+
handler() {
|
|
403
|
+
this.staticDataInit();
|
|
404
|
+
this.staticDeptAndRoleDataInit();
|
|
405
|
+
const key = { person: 'main', dept: 'dept', role: 'role', multiple: 'main' }[this.selectType];
|
|
406
|
+
this.treeData.temp = this.treeData[key];
|
|
407
|
+
}
|
|
408
|
+
},
|
|
409
|
+
roleData: {
|
|
410
|
+
immediate: true,
|
|
411
|
+
handler() {
|
|
412
|
+
this.staticDeptAndRoleDataInit();
|
|
413
|
+
const key = { person: 'main', dept: 'dept', role: 'role', multiple: 'main' }[this.selectType];
|
|
414
|
+
this.treeData.temp = this.treeData[key];
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
created() {},
|
|
419
|
+
mounted() {
|
|
420
|
+
this.getUsers();
|
|
421
|
+
this.initDefault();
|
|
422
|
+
},
|
|
423
|
+
methods: {
|
|
424
|
+
initDefault() {
|
|
425
|
+
if (this.getLoadChildData) {
|
|
426
|
+
this.getDefaultList();
|
|
427
|
+
} else {
|
|
428
|
+
this.$nextTick(() => {
|
|
429
|
+
const userIds = this.defaultList.filter(item => item.itemType === 'person').map(item => item.id);
|
|
430
|
+
const deptIds = this.defaultList.filter(item => item.itemType === 'dept').map(item => item.id);
|
|
431
|
+
const roleIds = this.defaultList.filter(item => item.itemType === 'role').map(item => item.id);
|
|
432
|
+
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
433
|
+
this.checkedKeys.main = userIds;
|
|
434
|
+
this.checkedKeys.dept = deptIds;
|
|
435
|
+
this.checkedKeys.role = roleIds;
|
|
436
|
+
this.checkedKeys.temp = this.checkedKeys[key];
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
|
|
441
|
+
staticDataInit() {
|
|
442
|
+
if (!Array.isArray(this.data) || this.data.length == 0) return;
|
|
443
|
+
this.treeData.main = this.data;
|
|
444
|
+
this.generateDataList(this.treeData.main, this.dataList.main);
|
|
445
|
+
},
|
|
446
|
+
staticDeptAndRoleDataInit() {
|
|
447
|
+
this.treeData.dept = this.getDeptData(this.data);
|
|
448
|
+
this.generateDataList(this.treeData.dept, this.dataList.dept);
|
|
449
|
+
this.treeData.role = this.handleRoleData(this.roleData);
|
|
450
|
+
this.generateDataList(this.treeData.role, this.dataList.role);
|
|
451
|
+
},
|
|
452
|
+
getDeptData(data) {
|
|
453
|
+
// 把data里面的人员过滤掉
|
|
454
|
+
const copyData = JSON.parse(JSON.stringify(data));
|
|
455
|
+
vexutils.searchTree(copyData, item => {
|
|
456
|
+
if (item.type === 1 && item.children && item.children.length) {
|
|
457
|
+
item.children = item.children.filter(child => child.type === 1);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
return copyData;
|
|
461
|
+
},
|
|
462
|
+
handleRoleData(data) {
|
|
463
|
+
const copyData = JSON.parse(JSON.stringify(data));
|
|
464
|
+
vexutils.searchTree(copyData, item => {
|
|
465
|
+
const { title, key, children } = this.roleFields;
|
|
466
|
+
item.title = item[title];
|
|
467
|
+
item.children = item[children] ? item[children] : [];
|
|
468
|
+
item.key = item[key];
|
|
469
|
+
});
|
|
470
|
+
return copyData;
|
|
471
|
+
},
|
|
472
|
+
/** --- 默认值 --- */
|
|
473
|
+
getDefaultList() {
|
|
474
|
+
const { defaultList } = this;
|
|
475
|
+
let copy = JSON.parse(JSON.stringify(defaultList));
|
|
476
|
+
if (Array.isArray(copy)) {
|
|
477
|
+
// this.defaultShowObj = {};
|
|
478
|
+
|
|
479
|
+
const { user_id_obj } = this.wordbookChild || {};
|
|
480
|
+
copy.forEach(v => {
|
|
481
|
+
this.handleDefMapping(v);
|
|
482
|
+
let key = this.getuniqKey(v);
|
|
483
|
+
let pId = this.getParentId(v);
|
|
484
|
+
this.cacheParentIdObj[pId] = pId;
|
|
485
|
+
// this.defaultShowObj[key] = v[user_id_obj];
|
|
486
|
+
});
|
|
487
|
+
this.defaultShowList = copy;
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
|
|
491
|
+
getcheckedKeys() {
|
|
492
|
+
const { defaultList } = this;
|
|
493
|
+
let checkedKeysMain = [],
|
|
494
|
+
checkedKeysOther = [];
|
|
495
|
+
let copy = JSON.parse(JSON.stringify(defaultList));
|
|
496
|
+
if (Array.isArray(copy)) {
|
|
497
|
+
copy.forEach(v => {
|
|
498
|
+
this.handleDefMapping(v);
|
|
499
|
+
let key = this.getuniqKey(v);
|
|
500
|
+
checkedKeysMain.push(key);
|
|
501
|
+
// 回填到 检索的选择,防止回填马上检索
|
|
502
|
+
if (String(key).includes(FIXEDKEY)) {
|
|
503
|
+
checkedKeysOther.push(key);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
checkedKeysMain,
|
|
509
|
+
checkedKeysOther
|
|
510
|
+
};
|
|
511
|
+
},
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* 根据配置映射默认值
|
|
515
|
+
*/
|
|
516
|
+
handleDefMapping(v) {
|
|
517
|
+
const { parent_id_obj, parent_name_obj, user_id_obj, user_name_obj } = this.wordbookConfig || {};
|
|
518
|
+
// 自定义 key 值
|
|
519
|
+
const { parent_id_obj_key, parent_name_obj_key } = this.wordbook;
|
|
520
|
+
const { user_id_obj_key, user_name_obj_key } = this.wordbookChild;
|
|
521
|
+
v[parent_id_obj] = v[parent_id_obj_key] || v.parent_id;
|
|
522
|
+
v[parent_name_obj] = v[parent_name_obj_key] || v.parent_name;
|
|
523
|
+
v[user_id_obj] = v[user_id_obj_key] || v.user_id;
|
|
524
|
+
v[user_name_obj] = v[user_name_obj_key] || v.user_name;
|
|
525
|
+
},
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* 初始化 请求已选的数据
|
|
529
|
+
*/
|
|
530
|
+
async loadSelected() {
|
|
531
|
+
try {
|
|
532
|
+
let list = await Promise.all(
|
|
533
|
+
this.treeData.main.map(async v => {
|
|
534
|
+
const { parent_id_obj } = this.wordbook || {};
|
|
535
|
+
if ([v.key, v[parent_id_obj], String(v[parent_id_obj])].includes(this.cacheParentIdObj[v[parent_id_obj]])) {
|
|
536
|
+
await this.onLoadData({ dataRef: v });
|
|
537
|
+
return v;
|
|
538
|
+
}
|
|
539
|
+
})
|
|
540
|
+
);
|
|
541
|
+
return list;
|
|
542
|
+
} catch (error) {
|
|
543
|
+
return Promise.resolve();
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* 过滤默认值的右边展示
|
|
549
|
+
*/
|
|
550
|
+
hanldeFilterDefaultShowList(list) {
|
|
551
|
+
this.defaultShowList = this.defaultShowList.filter(d => list.findIndex(l => this.getuniqKey(d) == this.getuniqKey(l)) == -1);
|
|
552
|
+
// this.updateDefaultShowObj(this.defaultShowList);
|
|
553
|
+
},
|
|
554
|
+
|
|
555
|
+
updateDefaultShowObj(list) {
|
|
556
|
+
const { user_id_obj } = this.wordbookConfig || {};
|
|
557
|
+
this.defaultShowObj = {};
|
|
558
|
+
list.forEach(v => {
|
|
559
|
+
this.defaultShowObj[this.getuniqKey(v)] = v[user_id_obj];
|
|
560
|
+
});
|
|
561
|
+
},
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* 拼接key
|
|
565
|
+
*/
|
|
566
|
+
getuniqKey(v) {
|
|
567
|
+
const { user_id_obj } = this.wordbookConfig || {};
|
|
568
|
+
return `${this.getParentId(v)}_${v[user_id_obj]}`;
|
|
569
|
+
// return v.key;
|
|
570
|
+
},
|
|
571
|
+
|
|
572
|
+
getParentId(v) {
|
|
573
|
+
const { parent_id_obj } = this.wordbookConfig || {};
|
|
574
|
+
// return `${v[parent_id_obj] || FIXEDKEY}`;
|
|
575
|
+
return `${v[parent_id_obj]}`;
|
|
576
|
+
},
|
|
577
|
+
|
|
578
|
+
// 查询树结构数据(一级父类)
|
|
579
|
+
async getUsers() {
|
|
580
|
+
try {
|
|
581
|
+
if (typeof this.queryMainTreeData !== 'function') {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
this.spinning = true;
|
|
585
|
+
const { parent_id_obj } = this.wordbookConfig || {};
|
|
586
|
+
let rows = await this.queryMainTreeData();
|
|
587
|
+
let list = this.uniqArrObj(rows, parent_id_obj);
|
|
588
|
+
this.treeData.main = list;
|
|
589
|
+
this.generateDataList(this.treeData.main, this.dataList.main);
|
|
590
|
+
// TODO:这里的回填
|
|
591
|
+
await this.loadSelected();
|
|
592
|
+
let { checkedKeysMain, checkedKeysOther } = this.getcheckedKeys();
|
|
593
|
+
this.checkedKeys.main.push(...checkedKeysMain);
|
|
594
|
+
this.checkedKeys.other = [...checkedKeysOther];
|
|
595
|
+
|
|
596
|
+
this.treeData.main.forEach(f => {
|
|
597
|
+
if (f && f.children && f.children.length) {
|
|
598
|
+
let flag = f.children.every(c => checkedKeysMain.includes(c.key));
|
|
599
|
+
if (flag && f.key) {
|
|
600
|
+
this.checkedKeys.main.push(f.key);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
if (this.currentKey === 'main') {
|
|
605
|
+
this.checkedKeys.temp = this.checkedKeys.main;
|
|
606
|
+
this.treeData.temp = this.treeData.main;
|
|
607
|
+
}
|
|
608
|
+
this.spinning = false;
|
|
609
|
+
} catch (error) {
|
|
610
|
+
this.spinning = false;
|
|
611
|
+
this.$message.error('查询异常');
|
|
612
|
+
console.log(error);
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
|
|
616
|
+
// 动态获取子节点
|
|
617
|
+
onLoadData(treeNode) {
|
|
618
|
+
return new Promise(async resolve => {
|
|
619
|
+
if (treeNode.dataRef.children) {
|
|
620
|
+
resolve();
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
treeNode.dataRef.children = await this.handleLoadChildData(treeNode.dataRef.key, treeNode.dataRef);
|
|
624
|
+
|
|
625
|
+
this.hanldeFilterDefaultShowList(treeNode.dataRef.children);
|
|
626
|
+
|
|
627
|
+
this.$nextTick(() => {
|
|
628
|
+
this.treeData.main = [...this.treeData.main];
|
|
629
|
+
this.treeData.temp = [...this.treeData.main];
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
this.addCheckedKeysChildrenMain(treeNode.dataRef);
|
|
633
|
+
|
|
634
|
+
this.generateDataList(treeNode.dataRef.children, this.dataList.main);
|
|
635
|
+
resolve();
|
|
636
|
+
});
|
|
637
|
+
},
|
|
638
|
+
|
|
639
|
+
async handleLoadChildData(key, treeNode) {
|
|
640
|
+
let rows = await this.queryLoadChildData(key, treeNode);
|
|
641
|
+
let list = rows;
|
|
642
|
+
return list;
|
|
643
|
+
},
|
|
644
|
+
|
|
645
|
+
loadMainChildData(searchResultTreeData) {
|
|
646
|
+
return new Promise(async resolve => {
|
|
647
|
+
let promises = searchResultTreeData.map(async item => {
|
|
648
|
+
if (item.users) {
|
|
649
|
+
let mainTreeItem = this.treeData.main.find(mainItem => mainItem.key == item.key);
|
|
650
|
+
if (!mainTreeItem || (mainTreeItem && !mainTreeItem.children)) {
|
|
651
|
+
if (!mainTreeItem) {
|
|
652
|
+
mainTreeItem = { ...item };
|
|
653
|
+
}
|
|
654
|
+
mainTreeItem.children = await this.handleLoadChildData(item.key, mainTreeItem);
|
|
655
|
+
this.generateDataList(mainTreeItem.children, this.dataList.main);
|
|
656
|
+
this.addCheckedKeysChildrenMain(mainTreeItem);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
await Promise.all(promises);
|
|
662
|
+
|
|
663
|
+
resolve();
|
|
664
|
+
});
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* 检索
|
|
669
|
+
*/
|
|
670
|
+
async searchFetch(data = {}, config = {}) {
|
|
671
|
+
if (typeof this.queryTreeSearch !== 'function') {
|
|
672
|
+
this.staticDataSearch();
|
|
673
|
+
this.spinning = false;
|
|
674
|
+
this.isSearchAllCheck();
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
if (!this.searchValue) {
|
|
678
|
+
this.search.status = 0;
|
|
679
|
+
this.search.defaultExpandedKeys = [];
|
|
680
|
+
this.expandedKeys = [];
|
|
681
|
+
this.spinning = false;
|
|
682
|
+
this.searchNoMore = false;
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
if (!config.loadMoren) {
|
|
686
|
+
this.search.status = 1;
|
|
687
|
+
} else {
|
|
688
|
+
this.loadMorenLoadinng = true;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
let rows = await this.queryTreeSearch(this.searchValue, data);
|
|
692
|
+
let searchResultTreeData = rows;
|
|
693
|
+
this.loadMorenLoadinng = false;
|
|
694
|
+
if (!searchResultTreeData || !searchResultTreeData.length) {
|
|
695
|
+
if (this.searchPage == 1) {
|
|
696
|
+
this.search.defaultExpandedKeys = [];
|
|
697
|
+
this.search.status = 3;
|
|
698
|
+
} else {
|
|
699
|
+
this.search.status = 2;
|
|
700
|
+
this.searchNoMore = true;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
this.spinning = false;
|
|
704
|
+
this.isSearchAllCheck();
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const { parent_id_obj, parent_name_obj, user_count_obj } = this.wordbook || {};
|
|
709
|
+
const { user_name_obj } = this.wordbookChild || {};
|
|
710
|
+
let pObj = {};
|
|
711
|
+
searchResultTreeData.forEach(item => {
|
|
712
|
+
item[parent_id_obj] &&
|
|
713
|
+
(pObj[item[parent_id_obj]] = {
|
|
714
|
+
key: item[parent_id_obj],
|
|
715
|
+
users: []
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
if (item.users) {
|
|
719
|
+
this.insertSearchTreeData(item);
|
|
720
|
+
} else {
|
|
721
|
+
this.insertSearchTreeDataOther(item);
|
|
722
|
+
}
|
|
723
|
+
});
|
|
724
|
+
let pList = [];
|
|
725
|
+
Object.keys(pObj || {}).forEach(v => {
|
|
726
|
+
if (v) {
|
|
727
|
+
pList.push({ ...pObj[v] });
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
let len = this.treeData.search.length || 0;
|
|
731
|
+
// TODO:加载更多
|
|
732
|
+
if (this.SearchLoadMore) {
|
|
733
|
+
this.searchNoMore = false;
|
|
734
|
+
} else {
|
|
735
|
+
this.searchNoMore = true;
|
|
736
|
+
}
|
|
737
|
+
// 防止searchTree选中后切换回mainTree,mainTree checkedKeys状态丢失
|
|
738
|
+
await this.loadMainChildData(pList);
|
|
739
|
+
this.generateSearchDataListKeys(searchResultTreeData);
|
|
740
|
+
|
|
741
|
+
this.hanldeFilterDefaultShowList(searchResultTreeData);
|
|
742
|
+
this.refreshSearchTree();
|
|
743
|
+
this.search.status = 2;
|
|
744
|
+
this.spinning = false;
|
|
745
|
+
|
|
746
|
+
this.isSearchAllCheck();
|
|
747
|
+
},
|
|
748
|
+
|
|
749
|
+
insertSearchTreeData(item) {
|
|
750
|
+
const { user_count_obj } = this.wordbook || {};
|
|
751
|
+
this.search.defaultExpandedKeys.push(item.key);
|
|
752
|
+
|
|
753
|
+
// 默认值处理
|
|
754
|
+
this.hanldeFilterDefaultShowList(item.children || []);
|
|
755
|
+
|
|
756
|
+
if (item[user_count_obj] == item.children.length) {
|
|
757
|
+
item.disableCheckbox = false;
|
|
758
|
+
}
|
|
759
|
+
this.treeData.search.push(item);
|
|
760
|
+
},
|
|
761
|
+
|
|
762
|
+
insertSearchTreeDataOther(item) {
|
|
763
|
+
let formatItem = Object.assign({}, item, { isLeaf: true });
|
|
764
|
+
|
|
765
|
+
this.treeData.search.push(formatItem);
|
|
766
|
+
|
|
767
|
+
if (this.dataListOtherKeys.includes(formatItem.key)) return false;
|
|
768
|
+
this.generateDataList([formatItem], this.dataList.other);
|
|
769
|
+
},
|
|
770
|
+
|
|
771
|
+
generateSearchDataListKeys(searchResultTreeData) {
|
|
772
|
+
// this.search.dataListKeys = {
|
|
773
|
+
// main: [],
|
|
774
|
+
// other: []
|
|
775
|
+
// };
|
|
776
|
+
searchResultTreeData.forEach(item => {
|
|
777
|
+
if (!this.dataListMainKeys.includes(item.key)) {
|
|
778
|
+
this.search.dataListKeys.other.push(item.key);
|
|
779
|
+
item.children &&
|
|
780
|
+
item.children.forEach(childItem => {
|
|
781
|
+
this.search.dataListKeys.other.push(childItem.key);
|
|
782
|
+
});
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
this.search.dataListKeys.main.push(item.key);
|
|
787
|
+
item.children &&
|
|
788
|
+
item.children.forEach(childItem => {
|
|
789
|
+
this.search.dataListKeys.main.push(childItem.key);
|
|
790
|
+
});
|
|
791
|
+
});
|
|
792
|
+
},
|
|
793
|
+
|
|
794
|
+
searchOnloadMore() {
|
|
795
|
+
this.searchPage = this.searchPage + 1;
|
|
796
|
+
this.searchFetch({ page: this.searchPage }, { loadMoren: true });
|
|
797
|
+
},
|
|
798
|
+
|
|
799
|
+
addCheckedKeysChildrenMain(item) {
|
|
800
|
+
if (!item.key) return;
|
|
801
|
+
if (!this.checkedKeys.main.includes(String(item.key))) return false;
|
|
802
|
+
// 新查询到插入已选中的main treeData 的child key,需要手动push到checkedKeys中
|
|
803
|
+
if (!Array.isArray(item.children)) return false;
|
|
804
|
+
item.children.forEach(({ key }) => {
|
|
805
|
+
// 防止重复添加(已处理,不会重复添加,保留代码以防逻辑缺漏)
|
|
806
|
+
if (this.checkedKeys.main.includes(key) || !key) return false;
|
|
807
|
+
this.checkedKeys.main.push(key);
|
|
808
|
+
});
|
|
809
|
+
},
|
|
810
|
+
|
|
811
|
+
// 暂存实际可选节点arr
|
|
812
|
+
generateDataList(data, dataList) {
|
|
813
|
+
for (let i = 0; i < data.length; i++) {
|
|
814
|
+
const node = data[i];
|
|
815
|
+
dataList.push({
|
|
816
|
+
parentId: this.getParentId(node),
|
|
817
|
+
...node
|
|
818
|
+
});
|
|
819
|
+
if (node.children) {
|
|
820
|
+
this.generateDataList(node.children, dataList);
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
|
|
825
|
+
// 获取匹配搜索节点arr
|
|
826
|
+
getParentKey(key, tree) {
|
|
827
|
+
let parentKey;
|
|
828
|
+
for (let i = 0; i < tree.length; i++) {
|
|
829
|
+
const node = tree[i];
|
|
830
|
+
if (node.key == key) {
|
|
831
|
+
parentKey = node.key;
|
|
832
|
+
return parentKey;
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
if (node.children) {
|
|
836
|
+
if (node.children.some(item => item.key == key)) {
|
|
837
|
+
parentKey = node.key;
|
|
838
|
+
} else if (this.getParentKey(key, node.children)) {
|
|
839
|
+
parentKey = this.getParentKey(key, node.children);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return parentKey;
|
|
844
|
+
},
|
|
845
|
+
radioChange(e) {
|
|
846
|
+
let { checked } = e.target || {};
|
|
847
|
+
if (this.searchTreeVisable) {
|
|
848
|
+
this.singleChecked = checked;
|
|
849
|
+
} else {
|
|
850
|
+
this.searchChecked = checked;
|
|
851
|
+
}
|
|
852
|
+
this.checkAll(checked ? 1 : 2);
|
|
853
|
+
this.handleOk();
|
|
854
|
+
},
|
|
855
|
+
// type 1 全选 2 反选(清空)
|
|
856
|
+
checkAll(type) {
|
|
857
|
+
if (this.checkAllSearchTree(type)) return false;
|
|
858
|
+
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
859
|
+
if (type == 1) {
|
|
860
|
+
this.expandedKeys = [];
|
|
861
|
+
this.checkedKeys[key] = this[`dataList${key.slice(0, 1).toUpperCase()}${key.slice(1)}Keys`]; // dataListMainKeys dataListDeptKeys dataListRoleKeys;
|
|
862
|
+
this.checkedKeys.temp = this.checkedKeys[key];
|
|
863
|
+
} else if (type == 2) {
|
|
864
|
+
this.checkedKeys[key] = [];
|
|
865
|
+
this.checkedKeys.temp = [];
|
|
866
|
+
this.autoExpandParent = true;
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
|
|
870
|
+
checkAllSearchTree(type) {
|
|
871
|
+
if (!this.searchTreeVisable) return false;
|
|
872
|
+
|
|
873
|
+
if (type == 1) {
|
|
874
|
+
// 全选默认不选中父级
|
|
875
|
+
let allSearchkeysMain = this.search.dataListKeys.main.filter(key => {
|
|
876
|
+
return !this.search.defaultExpandedKeys.includes(key);
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
let allSearchkeysOther = this.search.dataListKeys.other;
|
|
880
|
+
|
|
881
|
+
this.checkedKeys.main = vexutils.uniq([...this.checkedKeys.main, ...allSearchkeysMain]);
|
|
882
|
+
this.checkedKeys.other = vexutils.uniq([...this.checkedKeys.other, ...allSearchkeysOther]);
|
|
883
|
+
|
|
884
|
+
// 如果子级全选,父级也需要选中
|
|
885
|
+
this.search.dataListKeys.main.forEach(key => {
|
|
886
|
+
let getParentKey = this.getParentKey(key, this.treeData.main);
|
|
887
|
+
let parent = this.treeData.main.filter(item => {
|
|
888
|
+
return item.key == getParentKey;
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
let allCheck = parent[0].children.every(item => {
|
|
892
|
+
return this.checkedKeys.main.includes(item.key);
|
|
893
|
+
});
|
|
894
|
+
allCheck && this.checkedKeys.main.push(getParentKey);
|
|
895
|
+
});
|
|
896
|
+
this.refreshSearchTree();
|
|
897
|
+
} else if (type == 2) {
|
|
898
|
+
this.$refs['searchTree'].emptyCheckedKeys();
|
|
899
|
+
this.autoExpandParent = true;
|
|
900
|
+
}
|
|
901
|
+
this.isSearchAllCheck();
|
|
902
|
+
return true;
|
|
903
|
+
},
|
|
904
|
+
|
|
905
|
+
refreshSearchTree() {
|
|
906
|
+
if (!this.searchTreeVisable) return false;
|
|
907
|
+
this.$refs['searchTree'].setDefaultCheckedKeys();
|
|
908
|
+
this.$nextTick(() => {
|
|
909
|
+
this.isSearchAllCheck();
|
|
910
|
+
});
|
|
911
|
+
},
|
|
912
|
+
|
|
913
|
+
// 展开数节点
|
|
914
|
+
onExpand(expandedKeys) {
|
|
915
|
+
// const latestOpenKey = expandedKeys.find(key => this.expandedKeys.indexOf(key) == -1);
|
|
916
|
+
// this.expandedKeys = latestOpenKey ? [latestOpenKey] : [];
|
|
917
|
+
// this.autoExpandParent = false;
|
|
918
|
+
this.expandedKeys = expandedKeys;
|
|
919
|
+
this.autoExpandParent = false;
|
|
920
|
+
// this.$emit('expand', expandedKeys, ...arg)
|
|
921
|
+
},
|
|
922
|
+
onExpandDept(expandedKeys) {
|
|
923
|
+
this.expandedDeptKeys = expandedKeys;
|
|
924
|
+
},
|
|
925
|
+
|
|
926
|
+
searchClick() {
|
|
927
|
+
this.searchValue = this.title;
|
|
928
|
+
|
|
929
|
+
this.treeData.search = [];
|
|
930
|
+
this.search.dataListKeys.other = [];
|
|
931
|
+
this.search.dataListKeys.main = [];
|
|
932
|
+
this.search.defaultExpandedKeys = [];
|
|
933
|
+
|
|
934
|
+
this.spinning = true;
|
|
935
|
+
this.searchPage = 1;
|
|
936
|
+
this.searchFetch();
|
|
937
|
+
},
|
|
938
|
+
|
|
939
|
+
isAllCheck(checkedKeys = []) {
|
|
940
|
+
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
941
|
+
if (!checkedKeys || checkedKeys.length == 0) {
|
|
942
|
+
this.indeterminate = false;
|
|
943
|
+
this.singleChecked = false;
|
|
944
|
+
} else {
|
|
945
|
+
let keyArr = this.treeData[key].map(item => item.key);
|
|
946
|
+
let keyArrTemp = keyArr.filter(item => checkedKeys.indexOf(item) !== -1);
|
|
947
|
+
this.indeterminate = !(keyArr.length == keyArrTemp.length);
|
|
948
|
+
this.singleChecked = keyArr.length == keyArrTemp.length;
|
|
949
|
+
}
|
|
950
|
+
},
|
|
951
|
+
|
|
952
|
+
isSearchAllCheck() {
|
|
953
|
+
this.$nextTick(() => {
|
|
954
|
+
let skeyArr = this.treeData.search.map(item => item.key);
|
|
955
|
+
let serchCheckedKeys = this.$refs['searchTree'].checkedKeys;
|
|
956
|
+
this.searchIndeterminate = !!serchCheckedKeys.length && serchCheckedKeys.length < skeyArr.length;
|
|
957
|
+
this.searchChecked = serchCheckedKeys.length === skeyArr.length;
|
|
958
|
+
});
|
|
959
|
+
},
|
|
960
|
+
|
|
961
|
+
/* 子组件emit方法 */
|
|
962
|
+
addCheckedkeysMain(keys) {
|
|
963
|
+
let checkedKeys = this.checkedKeys.main;
|
|
964
|
+
let filterKey = (keys || {}).filter(Boolean);
|
|
965
|
+
filterKey.forEach(key => {
|
|
966
|
+
//
|
|
967
|
+
checkedKeys.push(key);
|
|
968
|
+
// 如果子级全选,父级也需要选中
|
|
969
|
+
let getParentKey = this.getParentKey(key, this.treeData.main);
|
|
970
|
+
if (!getParentKey) return;
|
|
971
|
+
let parent = this.treeData.main.filter(item => {
|
|
972
|
+
return item.key == getParentKey;
|
|
973
|
+
});
|
|
974
|
+
let allCheck = (parent[0]?.children || []).every(item => {
|
|
975
|
+
return checkedKeys.includes(item.key);
|
|
976
|
+
});
|
|
977
|
+
allCheck && checkedKeys.push(getParentKey);
|
|
978
|
+
});
|
|
979
|
+
},
|
|
980
|
+
|
|
981
|
+
removeCheckedkeysMain(keys) {
|
|
982
|
+
let checkedKeysMain = vexutils.clone(this.checkedKeys.main, true);
|
|
983
|
+
keys.forEach(key => {
|
|
984
|
+
//
|
|
985
|
+
let index = checkedKeysMain.findIndex(mainKey => mainKey == key);
|
|
986
|
+
if (index !== -1) {
|
|
987
|
+
checkedKeysMain.splice(index, 1);
|
|
988
|
+
this.checkedKeys.main = [...checkedKeysMain];
|
|
989
|
+
}
|
|
990
|
+
// 删除父级选中
|
|
991
|
+
let getParentKey = this.getParentKey(key, this.treeData.main);
|
|
992
|
+
let parentIndex = checkedKeysMain.findIndex(mainKey => mainKey == getParentKey);
|
|
993
|
+
if (parentIndex !== -1) {
|
|
994
|
+
checkedKeysMain.splice(parentIndex, 1);
|
|
995
|
+
}
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
this.checkedKeys.main = [...checkedKeysMain];
|
|
999
|
+
},
|
|
1000
|
+
|
|
1001
|
+
addCheckedkeysOther(keys) {
|
|
1002
|
+
this.checkedKeys.other.push(...keys);
|
|
1003
|
+
// this.checkedKeys.main.push(...keys);
|
|
1004
|
+
},
|
|
1005
|
+
|
|
1006
|
+
removeCheckedkeysOther(keys) {
|
|
1007
|
+
let checkedKeys = this.checkedKeys.other;
|
|
1008
|
+
// let mainCheckedKeys = this.checkedKeys.main;
|
|
1009
|
+
keys.forEach(key => {
|
|
1010
|
+
let index = checkedKeys.findIndex(otherKey => otherKey == key);
|
|
1011
|
+
checkedKeys.splice(index, 1);
|
|
1012
|
+
this.handleDeldefaultShowList(key);
|
|
1013
|
+
|
|
1014
|
+
// let mindex = mainCheckedKeys.findIndex(otherKey => otherKey == key);
|
|
1015
|
+
// mainCheckedKeys.splice(mindex, 1);
|
|
1016
|
+
});
|
|
1017
|
+
this.removeCheckedkeysMain(keys);
|
|
1018
|
+
},
|
|
1019
|
+
|
|
1020
|
+
handleDeldefaultShowList(key) {
|
|
1021
|
+
let len = this?.defaultShowList?.length || 0;
|
|
1022
|
+
if (len > 0) {
|
|
1023
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
1024
|
+
let d = this.defaultShowList[i];
|
|
1025
|
+
if (`${d.parent_id}_${d.user_id}` == key) {
|
|
1026
|
+
this.closeDefaultTag(d, i);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
|
|
1032
|
+
closeDefaultTag(tag, i) {
|
|
1033
|
+
this.defaultShowList.splice(i, 1);
|
|
1034
|
+
this.closeTag({ parentId: this.getParentId(tag), ...tag });
|
|
1035
|
+
},
|
|
1036
|
+
|
|
1037
|
+
/* 右侧点击item[x]按钮 相关 */
|
|
1038
|
+
closeTag(removedTag) {
|
|
1039
|
+
// let { parentId } = removedTag;
|
|
1040
|
+
|
|
1041
|
+
this.removedCheckedkeysMain(removedTag);
|
|
1042
|
+
this.removedCheckedkeysDept(removedTag);
|
|
1043
|
+
this.removedCheckedkeysRole(removedTag);
|
|
1044
|
+
this.removedCheckedkeysOther(removedTag);
|
|
1045
|
+
const propStr = ['person', 'dept', 'role'][this.typeActiveIndex];
|
|
1046
|
+
const checkedKeys = this.checkedTreeItem.filter(item => item.itemType === propStr).map(item => item.key);
|
|
1047
|
+
this.checkedKeys.temp = checkedKeys;
|
|
1048
|
+
this.handleEmitValue();
|
|
1049
|
+
this.refreshSearchTree();
|
|
1050
|
+
this.isAllCheck(checkedKeys);
|
|
1051
|
+
},
|
|
1052
|
+
|
|
1053
|
+
removeCheckedkeysIncludeChildren(parentKey) {
|
|
1054
|
+
let needRemoveChildKeys = this.dataList.main
|
|
1055
|
+
.filter(i => {
|
|
1056
|
+
let parentId = this.getParentId(i);
|
|
1057
|
+
return parentId == parentKey || i.key == parentKey;
|
|
1058
|
+
})
|
|
1059
|
+
.map(i => {
|
|
1060
|
+
return i.key;
|
|
1061
|
+
});
|
|
1062
|
+
const checkedKeys = this.checkedKeys.main.filter(i => {
|
|
1063
|
+
return !needRemoveChildKeys.includes(i);
|
|
1064
|
+
});
|
|
1065
|
+
this.checkedKeys.main = checkedKeys;
|
|
1066
|
+
},
|
|
1067
|
+
|
|
1068
|
+
removedCheckedkeysMain(tag) {
|
|
1069
|
+
let checkedKeys = this.checkedKeys.main;
|
|
1070
|
+
let parentId = this.getParentId(tag);
|
|
1071
|
+
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1072
|
+
if (tag.key == checkedKeys[i] && tag.key == parentId) {
|
|
1073
|
+
this.removeCheckedkeysIncludeChildren(tag.key);
|
|
1074
|
+
return false;
|
|
1075
|
+
} else if (tag.key == checkedKeys[i]) {
|
|
1076
|
+
checkedKeys.splice(i, 1);
|
|
1077
|
+
return false;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
},
|
|
1081
|
+
removeCheckedkeysIncludeChildrenDept(parentKey) {
|
|
1082
|
+
let needRemoveChildKeys = this.dataList.dept
|
|
1083
|
+
.filter(i => {
|
|
1084
|
+
let parentId = this.getParentId(i);
|
|
1085
|
+
return parentId == parentKey || i.key == parentKey;
|
|
1086
|
+
})
|
|
1087
|
+
.map(i => {
|
|
1088
|
+
return i.key;
|
|
1089
|
+
});
|
|
1090
|
+
const checkedKeys = this.checkedKeys.dept.filter(i => {
|
|
1091
|
+
return !needRemoveChildKeys.includes(i);
|
|
1092
|
+
});
|
|
1093
|
+
this.checkedKeys.dept = checkedKeys;
|
|
1094
|
+
},
|
|
1095
|
+
removedCheckedkeysDept(tag) {
|
|
1096
|
+
let checkedKeys = this.checkedKeys.dept;
|
|
1097
|
+
let parentId = this.getParentId(tag);
|
|
1098
|
+
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1099
|
+
if (tag.key == checkedKeys[i] && tag.key == parentId) {
|
|
1100
|
+
this.removeCheckedkeysIncludeChildrenDept(tag.key);
|
|
1101
|
+
return false;
|
|
1102
|
+
} else if (tag.key == checkedKeys[i]) {
|
|
1103
|
+
checkedKeys.splice(i, 1);
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
},
|
|
1108
|
+
removedCheckedkeysRole(tag) {
|
|
1109
|
+
let checkedKeys = this.checkedKeys.role;
|
|
1110
|
+
let parentId = '';
|
|
1111
|
+
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1112
|
+
if (tag.key == checkedKeys[i] && tag.key == parentId) {
|
|
1113
|
+
// this.removeCheckedkeysIncludeChildren(tag.key);
|
|
1114
|
+
return false;
|
|
1115
|
+
} else if (tag.key == checkedKeys[i]) {
|
|
1116
|
+
checkedKeys.splice(i, 1);
|
|
1117
|
+
return false;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
},
|
|
1121
|
+
|
|
1122
|
+
removedCheckedkeysOther(tag) {
|
|
1123
|
+
let checkedKeys = this.checkedKeys.other;
|
|
1124
|
+
if (checkedKeys.includes(tag.key)) {
|
|
1125
|
+
for (let i = 0; i < checkedKeys.length; i++) {
|
|
1126
|
+
if (tag.key == checkedKeys[i]) {
|
|
1127
|
+
checkedKeys.splice(i, 1);
|
|
1128
|
+
return false;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
} else {
|
|
1132
|
+
// 删除科室,删除
|
|
1133
|
+
this.OtherRemoveCheckedkeysIncludeChildren(tag.key);
|
|
1134
|
+
}
|
|
1135
|
+
},
|
|
1136
|
+
|
|
1137
|
+
OtherRemoveCheckedkeysIncludeChildren(parentKey) {
|
|
1138
|
+
let needRemoveChildKeys = this.dataList.main
|
|
1139
|
+
.filter(i => {
|
|
1140
|
+
let parentId = this.getParentId(i);
|
|
1141
|
+
return parentId == parentKey || i.key == parentKey;
|
|
1142
|
+
})
|
|
1143
|
+
.map(i => {
|
|
1144
|
+
return i.key;
|
|
1145
|
+
});
|
|
1146
|
+
|
|
1147
|
+
this.checkedKeys.other = this.checkedKeys.other.filter(i => {
|
|
1148
|
+
return !needRemoveChildKeys.includes(i);
|
|
1149
|
+
});
|
|
1150
|
+
},
|
|
1151
|
+
|
|
1152
|
+
/* submit 相关 */
|
|
1153
|
+
getCheckedMainChildKeys() {
|
|
1154
|
+
return new Promise(async resolve => {
|
|
1155
|
+
let promises = this.treeData.main.map(async item => {
|
|
1156
|
+
// 获取勾选了父类tree, 但未获取children
|
|
1157
|
+
// 接口传参,需要的是叶节点的keys
|
|
1158
|
+
if (this.checkedKeys.main.includes(item.key) && !item.children) {
|
|
1159
|
+
item.children = await this.handleLoadChildData(item.key, item);
|
|
1160
|
+
this.addCheckedKeysChildrenMain(item);
|
|
1161
|
+
|
|
1162
|
+
this.generateDataList(item.children, this.dataList.main);
|
|
1163
|
+
}
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1166
|
+
await Promise.all(promises);
|
|
1167
|
+
|
|
1168
|
+
resolve();
|
|
1169
|
+
});
|
|
1170
|
+
},
|
|
1171
|
+
|
|
1172
|
+
getCheckedLeafKeys() {
|
|
1173
|
+
let mainLeafKeys = [];
|
|
1174
|
+
let mainLeafDataListKeys = this.dataList.main.filter(item => item.isLeaf).map(item => item.key);
|
|
1175
|
+
|
|
1176
|
+
this.checkedKeys.main.forEach(key => {
|
|
1177
|
+
if (mainLeafDataListKeys.includes(key)) {
|
|
1178
|
+
mainLeafKeys.push(key);
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
|
|
1182
|
+
let keyList = [...mainLeafKeys, ...this.checkedKeys.other];
|
|
1183
|
+
let res = [...new Set(keyList)];
|
|
1184
|
+
return [...res];
|
|
1185
|
+
},
|
|
1186
|
+
|
|
1187
|
+
async handleOk(isShowLoading = false) {
|
|
1188
|
+
isShowLoading && (this.spinning = true);
|
|
1189
|
+
this.queryLoadChildData && (await this.getCheckedMainChildKeys());
|
|
1190
|
+
|
|
1191
|
+
this.checkedLeafKeys = this.getCheckedLeafKeys();
|
|
1192
|
+
|
|
1193
|
+
const submitData = this.handleGetSumitData(this.checkedLeafKeys);
|
|
1194
|
+
|
|
1195
|
+
// let subList = [...submitData, ...this.defaultShowList];
|
|
1196
|
+
|
|
1197
|
+
this.$emit('pubCheckedTreeItem', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1198
|
+
this.$emit('check', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1199
|
+
this.$emit('handleOk', this.checkedLeafKeys);
|
|
1200
|
+
this.$emit('change', this.checkedLeafKeys, [...submitData, ...this.defaultShowList]);
|
|
1201
|
+
this.$emit('submitData', [...submitData, ...this.defaultShowList]);
|
|
1202
|
+
|
|
1203
|
+
isShowLoading && (this.spinning = false);
|
|
1204
|
+
},
|
|
1205
|
+
|
|
1206
|
+
handleEmitValue() {
|
|
1207
|
+
clearTimeout(this.emitTimeout);
|
|
1208
|
+
this.emitTimeout = setTimeout(() => {
|
|
1209
|
+
this.handleOk();
|
|
1210
|
+
}, 100);
|
|
1211
|
+
},
|
|
1212
|
+
|
|
1213
|
+
hanldeGetValue(...arg) {
|
|
1214
|
+
this.handleOk(...arg);
|
|
1215
|
+
},
|
|
1216
|
+
|
|
1217
|
+
// 获取表单提交的数据
|
|
1218
|
+
handleGetSumitData(list = []) {
|
|
1219
|
+
if (!Array.isArray(list)) return [];
|
|
1220
|
+
let resList = [];
|
|
1221
|
+
const { parent_id_obj, parent_name_obj, user_id_obj, user_name_obj } = this.wordbookConfig || {};
|
|
1222
|
+
list.forEach(v => {
|
|
1223
|
+
// d.key
|
|
1224
|
+
let f = this.dataList.main.find(d => this.getuniqKey(d) == v);
|
|
1225
|
+
if (!f) {
|
|
1226
|
+
f = this.dataList.other.find(o => this.getuniqKey(o) == v);
|
|
1227
|
+
}
|
|
1228
|
+
// [parent_id_obj]: f[parent_id_obj],
|
|
1229
|
+
// [parent_name_obj]: f[parent_name_obj],
|
|
1230
|
+
// [user_id_obj]: f[user_id_obj],
|
|
1231
|
+
// [user_name_obj]: f[user_name_obj]
|
|
1232
|
+
if (f) {
|
|
1233
|
+
/** 提交映射 */
|
|
1234
|
+
// 自定义 key 值
|
|
1235
|
+
const { parent_id_obj_key, parent_name_obj_key } = this.wordbook;
|
|
1236
|
+
const { user_id_obj_key, user_name_obj_key } = this.wordbookChild;
|
|
1237
|
+
resList.push({
|
|
1238
|
+
[user_id_obj_key || 'user_id']: f[user_id_obj],
|
|
1239
|
+
[user_name_obj_key || 'user_name']: f[user_name_obj],
|
|
1240
|
+
[parent_id_obj_key || 'parent_id']: f[parent_id_obj],
|
|
1241
|
+
[parent_name_obj_key || 'parent_name']: f[parent_name_obj]
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
});
|
|
1245
|
+
return resList;
|
|
1246
|
+
},
|
|
1247
|
+
|
|
1248
|
+
cancel() {
|
|
1249
|
+
this.$emit('update:visible', false);
|
|
1250
|
+
this.spinning = false;
|
|
1251
|
+
},
|
|
1252
|
+
/* */
|
|
1253
|
+
treeCount(count) {
|
|
1254
|
+
if (!count) return '';
|
|
1255
|
+
return `(${count})`;
|
|
1256
|
+
},
|
|
1257
|
+
|
|
1258
|
+
staticDataSearch() {
|
|
1259
|
+
// let expandedKeys = new Set();
|
|
1260
|
+
// this.getStaticSearchParentKey(this.treeData.main, expandedKeys);
|
|
1261
|
+
// this.expandedKeys = Array.from(expandedKeys);
|
|
1262
|
+
// this.autoExpandParent = true;
|
|
1263
|
+
const key = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
1264
|
+
if (!this.title) {
|
|
1265
|
+
// 如果为空恢复默认数据
|
|
1266
|
+
this.$set(this.treeData, 'temp', this.treeData[key]);
|
|
1267
|
+
return;
|
|
1268
|
+
}
|
|
1269
|
+
let copyData = JSON.parse(JSON.stringify(this.treeData[key]));
|
|
1270
|
+
// 增加visible属性 true展示 false不展示
|
|
1271
|
+
filterTree({ value: this.title, data: copyData, prop: 'title' });
|
|
1272
|
+
// 过滤visible属性 为true的数据
|
|
1273
|
+
copyData = copyData.filter(item => item.visible);
|
|
1274
|
+
const expandedKeys = [];
|
|
1275
|
+
vexutils.searchTree(copyData, item => {
|
|
1276
|
+
if (item.visible) {
|
|
1277
|
+
expandedKeys.push(item.key);
|
|
1278
|
+
}
|
|
1279
|
+
if (item.children && item.children.length) {
|
|
1280
|
+
item.children = item.children.filter(child => child.visible);
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
this.$set(this.treeData, 'temp', copyData);
|
|
1284
|
+
this.expandedKeys = expandedKeys;
|
|
1285
|
+
},
|
|
1286
|
+
getStaticSearchParentKey(treeData, expandedKeys, orgId) {
|
|
1287
|
+
const keyword = this.title;
|
|
1288
|
+
for (let i = 0; i < treeData.length; i++) {
|
|
1289
|
+
const user = treeData[i];
|
|
1290
|
+
let { title = '', key, children } = user;
|
|
1291
|
+
if (keyword.length > 0 && (String(title).indexOf(keyword) !== -1 || String(key).indexOf(keyword) !== -1)) {
|
|
1292
|
+
expandedKeys.add(key);
|
|
1293
|
+
if (orgId) {
|
|
1294
|
+
expandedKeys.add(orgId);
|
|
1295
|
+
}
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
if (children) {
|
|
1299
|
+
this.getStaticSearchParentKey(children, expandedKeys, user.key || orgId);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
},
|
|
1303
|
+
|
|
1304
|
+
// 数组对象去重
|
|
1305
|
+
uniqArrObj(arr, name) {
|
|
1306
|
+
let obj = {};
|
|
1307
|
+
return arr.reduce((cur, next) => {
|
|
1308
|
+
obj[next[name]] ? '' : (obj[next[name]] = true && cur.push(next));
|
|
1309
|
+
return cur;
|
|
1310
|
+
}, []);
|
|
1311
|
+
},
|
|
1312
|
+
onTypeClick(index) {
|
|
1313
|
+
const key = ['main', 'dept', 'role'][index];
|
|
1314
|
+
const checkedKeys = this.checkedKeys[key];
|
|
1315
|
+
this.treeData.temp = this.treeData[key];
|
|
1316
|
+
this.checkedKeys.temp = checkedKeys;
|
|
1317
|
+
this.typeActiveIndex = index;
|
|
1318
|
+
// 处理全选框
|
|
1319
|
+
this.isAllCheck(checkedKeys);
|
|
1320
|
+
},
|
|
1321
|
+
onTreeCheck(checkedKeys, { checked, node }) {
|
|
1322
|
+
// 断掉了父子关系 要不然当存在一二级科室的时候 搜索二级科室 再选中会把一级也选中 ; 后续与产品沟通 不需要断 只取最后一级科室
|
|
1323
|
+
const propStr = ['main', 'dept', 'role'][this.typeActiveIndex];
|
|
1324
|
+
let totalCheckedKeys = [];
|
|
1325
|
+
// const keyData = this.dataList[propStr].find(item => item.key === node.eventKey);
|
|
1326
|
+
// let keyData = {};
|
|
1327
|
+
// vexutils.searchTree(this.treeData[propStr], item => {
|
|
1328
|
+
// if (item.key === node.eventKey) {
|
|
1329
|
+
// keyData = item;
|
|
1330
|
+
// }
|
|
1331
|
+
// });
|
|
1332
|
+
// vexutils.searchTree(keyData.children, item => {
|
|
1333
|
+
// childKeys.push(item.key);
|
|
1334
|
+
// });
|
|
1335
|
+
// if (checked) {
|
|
1336
|
+
// const singleCheckedKeys = this.getSingleCheckedKeys(propStr, this.treeData[propStr], keyData);
|
|
1337
|
+
// totalCheckedKeys = this.isSingleCheck ? singleCheckedKeys : [...new Set(checkedKeys.concat(childKeys))];
|
|
1338
|
+
// } else {
|
|
1339
|
+
// // totalCheckedKeys = checkedKeys;
|
|
1340
|
+
// totalCheckedKeys = this.isSingleCheck ? [] : checkedKeys.filter(key => !childKeys.includes(key));
|
|
1341
|
+
// }
|
|
1342
|
+
// 如果是选中就把之前选中和现在选中的合并做为temp值(兼容搜索的情况),
|
|
1343
|
+
if (checked) {
|
|
1344
|
+
const preChecked = this.checkedKeys[propStr];
|
|
1345
|
+
// 搜索时选中上级也要把它所有下级给选中 如果是选中一个下级但是也把其上级选中了要把上级选中给去掉
|
|
1346
|
+
const childKeys = [];
|
|
1347
|
+
let keyData = {};
|
|
1348
|
+
vexutils.searchTree(this.treeData[propStr], item => {
|
|
1349
|
+
if (item.key === node.eventKey) {
|
|
1350
|
+
keyData = item;
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
vexutils.searchTree(keyData.children, item => {
|
|
1354
|
+
childKeys.push(item.key);
|
|
1355
|
+
});
|
|
1356
|
+
const allParentIds = getAllParentId(this.treeData[propStr], node.eventKey).filter(Boolean);
|
|
1357
|
+
totalCheckedKeys = [...new Set(preChecked.concat(checkedKeys, childKeys))].filter(id => !allParentIds.includes(id));
|
|
1358
|
+
} else {
|
|
1359
|
+
// 如果是取消从之前的选择中把当前点击的及其子级去除选中作为temp值(兼容搜索的情况)
|
|
1360
|
+
let keyData = {};
|
|
1361
|
+
const needCancelKeys = [node.eventKey];
|
|
1362
|
+
const preChecked = this.checkedKeys[propStr];
|
|
1363
|
+
vexutils.searchTree(this.treeData[propStr], item => {
|
|
1364
|
+
if (item.key === node.eventKey) {
|
|
1365
|
+
keyData = item;
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
vexutils.searchTree(keyData.children, item => {
|
|
1369
|
+
needCancelKeys.push(item.key);
|
|
1370
|
+
});
|
|
1371
|
+
const allParentIds = getAllParentId(this.treeData[propStr], node.eventKey).filter(Boolean);
|
|
1372
|
+
totalCheckedKeys = [...new Set(preChecked.filter(key => !needCancelKeys.includes(key)))].filter(id => !allParentIds.includes(id));
|
|
1373
|
+
}
|
|
1374
|
+
this.checkedKeys.temp = totalCheckedKeys;
|
|
1375
|
+
this.checkedKeys[propStr] = totalCheckedKeys;
|
|
1376
|
+
this.isAllCheck(totalCheckedKeys);
|
|
1377
|
+
this.isSearchAllCheck(totalCheckedKeys);
|
|
1378
|
+
this.$emit('pubCheckedTreeItem', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1379
|
+
this.$emit('check', [...this.checkedTreeItem, ...this.defaultShowList]);
|
|
1380
|
+
},
|
|
1381
|
+
getSingleCheckedKeys(propStr, treeData, keyData) {
|
|
1382
|
+
const firstTreeData = deepTraversalFirst(keyData) || [];
|
|
1383
|
+
let checkedKeys = [];
|
|
1384
|
+
if (propStr === 'main') {
|
|
1385
|
+
checkedKeys = firstTreeData.map(item => item.key);
|
|
1386
|
+
} else if (propStr === 'dept') {
|
|
1387
|
+
// 如果是dept 找到层级为科室的第一个数据
|
|
1388
|
+
const index = firstTreeData.findIndex(item => item.type === 1);
|
|
1389
|
+
if (index > -1) {
|
|
1390
|
+
checkedKeys = firstTreeData.slice(0, index + 1).map(item => item.key);
|
|
1391
|
+
} else {
|
|
1392
|
+
checkedKeys = firstTreeData.map(item => item.key);
|
|
1393
|
+
}
|
|
1394
|
+
} else if (propStr === 'role') {
|
|
1395
|
+
// 如果是dept 找到层级为角色的第一个数据
|
|
1396
|
+
const index = firstTreeData.findIndex(item => item.roleId);
|
|
1397
|
+
if (index > -1) {
|
|
1398
|
+
checkedKeys = firstTreeData.slice(0, index + 1).map(item => item.key);
|
|
1399
|
+
} else {
|
|
1400
|
+
checkedKeys = firstTreeData.map(item => item.key);
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
return checkedKeys;
|
|
1404
|
+
},
|
|
1405
|
+
|
|
1406
|
+
onClearSelect() {
|
|
1407
|
+
this.checkedKeys.temp = [];
|
|
1408
|
+
this.checkedKeys.main = [];
|
|
1409
|
+
this.checkedKeys.dept = [];
|
|
1410
|
+
this.checkedKeys.role = [];
|
|
1411
|
+
this.defaultShowList = [];
|
|
1412
|
+
this.indeterminate = false;
|
|
1413
|
+
this.singleChecked = false;
|
|
1414
|
+
},
|
|
1415
|
+
filterTreeData({ value, data, prop, filter, filterXor, children, visible, filterChildren = true, callback }) {
|
|
1416
|
+
// 默认赋值
|
|
1417
|
+
visible = visible || 'visible';
|
|
1418
|
+
children = children || 'children';
|
|
1419
|
+
prop = prop || 'text';
|
|
1420
|
+
|
|
1421
|
+
const filterNodeMethod = function(value, data) {
|
|
1422
|
+
if (!value) {
|
|
1423
|
+
return true;
|
|
1424
|
+
}
|
|
1425
|
+
let flag = (data[prop] || '').indexOf(value) !== -1;
|
|
1426
|
+
return filterXor ? !flag : flag;
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
const traverse = function(node) {
|
|
1430
|
+
const childNodes = node[children] || [];
|
|
1431
|
+
|
|
1432
|
+
childNodes.forEach(child => {
|
|
1433
|
+
callback && callback(child);
|
|
1434
|
+
child[visible] = (!node.root && !filterChildren && node[visible]) || filterNodeMethod.call(child, value, child, prop);
|
|
1435
|
+
|
|
1436
|
+
traverse(child);
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
if (!node[visible] && childNodes.length) {
|
|
1440
|
+
let allHidden = true;
|
|
1441
|
+
allHidden = !childNodes.some(child => child[visible]);
|
|
1442
|
+
|
|
1443
|
+
node[visible] = allHidden === false;
|
|
1444
|
+
}
|
|
1445
|
+
};
|
|
1446
|
+
let totalData = {
|
|
1447
|
+
root: true
|
|
1448
|
+
};
|
|
1449
|
+
totalData[children] = data;
|
|
1450
|
+
traverse(totalData);
|
|
1451
|
+
|
|
1452
|
+
if (filter) {
|
|
1453
|
+
let copyData = data.slice();
|
|
1454
|
+
let filterHandle = filterData => {
|
|
1455
|
+
return filterData.filter((item, index) => {
|
|
1456
|
+
if (item[visible]) {
|
|
1457
|
+
if (item[children]) {
|
|
1458
|
+
item[children] = filterHandle(item[children]);
|
|
1459
|
+
}
|
|
1460
|
+
return true;
|
|
1461
|
+
}
|
|
1462
|
+
return false;
|
|
1463
|
+
});
|
|
1464
|
+
};
|
|
1465
|
+
return filterHandle(copyData);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1470
|
+
</script>
|
|
1471
|
+
<style lang="less" scoped>
|
|
1472
|
+
@primary-color: #2563f4;
|
|
1473
|
+
.people-tree {
|
|
1474
|
+
display: flex;
|
|
1475
|
+
.people-tree-item {
|
|
1476
|
+
width: 50%;
|
|
1477
|
+
padding: 22px 12px 0;
|
|
1478
|
+
max-height: 376px;
|
|
1479
|
+
height: 376px;
|
|
1480
|
+
overflow-y: auto;
|
|
1481
|
+
&.people-tree-left {
|
|
1482
|
+
display: flex;
|
|
1483
|
+
flex-direction: column;
|
|
1484
|
+
}
|
|
1485
|
+
/deep/ .person-search {
|
|
1486
|
+
// .ant-input-affix-wrapper .ant-input:not(:last-child),
|
|
1487
|
+
// .ant-input-affix-wrapper .ant-input:not(:first-child) {
|
|
1488
|
+
// padding-left: 34px;
|
|
1489
|
+
// }
|
|
1490
|
+
.ant-input-group-addon {
|
|
1491
|
+
padding: 0;
|
|
1492
|
+
border: 0px !important;
|
|
1493
|
+
}
|
|
1494
|
+
.ant-input-search-button {
|
|
1495
|
+
border-top-left-radius: 0;
|
|
1496
|
+
border-bottom-left-radius: 0;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
/deep/ .main-tree-container {
|
|
1500
|
+
> li {
|
|
1501
|
+
width: 100%;
|
|
1502
|
+
overflow: hidden;
|
|
1503
|
+
}
|
|
1504
|
+
.ant-tree-switcher {
|
|
1505
|
+
flex-shrink: 0;
|
|
1506
|
+
}
|
|
1507
|
+
.ant-tree-node-content-wrapper {
|
|
1508
|
+
width: 90%;
|
|
1509
|
+
text-overflow: ellipsis;
|
|
1510
|
+
overflow: hidden;
|
|
1511
|
+
white-space: nowrap;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
/deep/.ant-tree-title {
|
|
1515
|
+
// width: 250px;
|
|
1516
|
+
width: 100%;
|
|
1517
|
+
text-overflow: ellipsis;
|
|
1518
|
+
overflow: hidden;
|
|
1519
|
+
white-space: nowrap;
|
|
1520
|
+
display: inline-block;
|
|
1521
|
+
}
|
|
1522
|
+
&:first-child {
|
|
1523
|
+
border-right: 1px solid #e8e8e8;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
.no-data-tips {
|
|
1527
|
+
height: 200px;
|
|
1528
|
+
width: 100%;
|
|
1529
|
+
display: flex;
|
|
1530
|
+
justify-content: center;
|
|
1531
|
+
align-items: center;
|
|
1532
|
+
font-size: 16px;
|
|
1533
|
+
font-weight: 700;
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
.c-title {
|
|
1537
|
+
font-size: 14px;
|
|
1538
|
+
font-family: PingFangSC-Regular, PingFang SC;
|
|
1539
|
+
font-weight: 400;
|
|
1540
|
+
color: #212121;
|
|
1541
|
+
}
|
|
1542
|
+
.c-sub-title {
|
|
1543
|
+
font-size: 12px;
|
|
1544
|
+
font-family: PingFangSC-Regular, PingFang SC;
|
|
1545
|
+
// font-weight: 400;
|
|
1546
|
+
color: #4e4e4e;
|
|
1547
|
+
}
|
|
1548
|
+
.p-title {
|
|
1549
|
+
font-size: 14px;
|
|
1550
|
+
font-family: PingFangSC-Medium, PingFang SC;
|
|
1551
|
+
font-weight: 500;
|
|
1552
|
+
color: #212121;
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
/deep/.ant-tree {
|
|
1556
|
+
overflow-y: auto;
|
|
1557
|
+
// height: 450px;
|
|
1558
|
+
flex: 1;
|
|
1559
|
+
position: relative;
|
|
1560
|
+
&::-webkit-scrollbar {
|
|
1561
|
+
width: 6px;
|
|
1562
|
+
height: 6px;
|
|
1563
|
+
background-color: #f5f5f5;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
.select-wrap {
|
|
1567
|
+
flex: 1;
|
|
1568
|
+
padding: 22px 12px 0;
|
|
1569
|
+
height: 376px;
|
|
1570
|
+
display: flex;
|
|
1571
|
+
flex-direction: column;
|
|
1572
|
+
.select-header {
|
|
1573
|
+
display: flex;
|
|
1574
|
+
justify-content: space-between;
|
|
1575
|
+
margin-bottom: 20px;
|
|
1576
|
+
.clear-btn {
|
|
1577
|
+
color: @primary-color;
|
|
1578
|
+
cursor: pointer;
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
.select-content {
|
|
1582
|
+
flex: 1;
|
|
1583
|
+
overflow-y: auto;
|
|
1584
|
+
.tag-item {
|
|
1585
|
+
&.isRoot {
|
|
1586
|
+
background: rgba(@primary-color, 0.08);
|
|
1587
|
+
border: 1px solid rgba(@primary-color, 0.5);
|
|
1588
|
+
color: @primary-color;
|
|
1589
|
+
.tag-close {
|
|
1590
|
+
color: @primary-color;
|
|
1591
|
+
&:hover {
|
|
1592
|
+
color: rgba(@primary-color, 0.6);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
box-sizing: border-box;
|
|
1598
|
+
color: #212121;
|
|
1599
|
+
font-size: 14px;
|
|
1600
|
+
list-style: none;
|
|
1601
|
+
display: inline-flex;
|
|
1602
|
+
align-items: center;
|
|
1603
|
+
height: 24px;
|
|
1604
|
+
line-height: 24px;
|
|
1605
|
+
margin-right: 8px;
|
|
1606
|
+
margin-bottom: 4px;
|
|
1607
|
+
padding: 0 6px;
|
|
1608
|
+
white-space: nowrap;
|
|
1609
|
+
background: rgba(#d5d5d5, 0.2);
|
|
1610
|
+
border: 1px solid rgba(#000000, 0.14);
|
|
1611
|
+
border-radius: 4px;
|
|
1612
|
+
transition: all 0.3s cubic-bezier(0.215, 0.61, 0.355, 1);
|
|
1613
|
+
.tag-close {
|
|
1614
|
+
font-size: 12px;
|
|
1615
|
+
&:hover {
|
|
1616
|
+
color: rgba(@primary-color, 0.6);
|
|
1617
|
+
}
|
|
1618
|
+
&:active {
|
|
1619
|
+
color: #fff;
|
|
1620
|
+
}
|
|
1621
|
+
display: inline-block;
|
|
1622
|
+
font-size: 14px;
|
|
1623
|
+
margin-left: 3px;
|
|
1624
|
+
color: #969696;
|
|
1625
|
+
font-weight: 700;
|
|
1626
|
+
cursor: pointer;
|
|
1627
|
+
transition: all 0.3s;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
.df {
|
|
1634
|
+
display: flex;
|
|
1635
|
+
}
|
|
1636
|
+
.search-input-icon {
|
|
1637
|
+
color: rgba(0, 0, 0, 0.4);
|
|
1638
|
+
margin-bottom: -2px;
|
|
1639
|
+
}
|
|
1640
|
+
.type-wrap {
|
|
1641
|
+
display: flex;
|
|
1642
|
+
margin-bottom: 10px;
|
|
1643
|
+
.type-btn {
|
|
1644
|
+
margin-right: 10px;
|
|
1645
|
+
padding: 2px 10px;
|
|
1646
|
+
background: #f2f2f2;
|
|
1647
|
+
border-radius: 8px;
|
|
1648
|
+
cursor: pointer;
|
|
1649
|
+
&:last-child {
|
|
1650
|
+
margin-right: 0;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
.type-active {
|
|
1654
|
+
background: @primary-color;
|
|
1655
|
+
color: #ffffff;
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
</style>
|