agilebuilder-ui 1.0.92 → 1.0.93-temp2

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.
@@ -2,81 +2,79 @@
2
2
  <span style="width: 100%">
3
3
  <template v-if="disabled">
4
4
  <el-input
5
- :disabled="true"
6
- :model-value="value"
7
- :readonly="true"
8
- :size="size"
9
- type="text"
10
- :placeholder="$t('imatrixUIMessage.pleaseSelect')"
5
+ :disabled="true"
6
+ :model-value="value"
7
+ :readonly="true"
8
+ :size="size"
9
+ type="text"
10
+ :placeholder="$t('imatrixUIMessage.pleaseSelect')"
11
11
  >
12
12
  <template v-slot:append>
13
- <el-icon v-slot:suffix class="el-input__icon"><el-icon-search/></el-icon>
14
- <el-icon v-slot:suffix class="el-input__icon"><el-icon-delete/></el-icon>
13
+ <el-icon v-slot:suffix class="el-input__icon"><el-icon-search /></el-icon>
14
+ <el-icon v-slot:suffix class="el-input__icon"><el-icon-delete /></el-icon>
15
15
  </template>
16
16
  </el-input>
17
17
  </template>
18
18
  <template v-else>
19
19
  <el-input
20
- :model-value="value"
21
- :readonly="true"
22
- :size="size"
23
- type="text"
24
- :placeholder="$t('imatrixUIMessage.pleaseSelect')"
25
- @click="showOrganizationTree(false)"
26
- @change="changeEvent"
20
+ :model-value="value"
21
+ :readonly="true"
22
+ :size="size"
23
+ type="text"
24
+ :placeholder="$t('imatrixUIMessage.pleaseSelect')"
25
+ @click="showOrganizationTree(false)"
26
+ @change="changeEvent"
27
27
  >
28
28
  <template v-slot:append>
29
- <el-icon class="el-input__icon" @click="showOrganizationTree(false)"><el-icon-search/></el-icon>
30
- <el-icon class="el-input__icon" @click="emptyOrganizationResult()"><el-icon-delete/></el-icon>
29
+ <el-icon class="el-input__icon" @click="showOrganizationTree(false)"><el-icon-search /></el-icon>
30
+ <el-icon class="el-input__icon" @click="emptyOrganizationResult()"><el-icon-delete /></el-icon>
31
31
  </template>
32
32
  </el-input>
33
33
  </template>
34
- <!-- 部门人员树 -->
34
+ <!-- 部门人员树 -->
35
35
  <department-user-tree
36
- v-if="treeType && treeType === 'DeptUserTree' && showOrganizationTreeFlag"
37
- :department-info="departmentInfo"
38
- :multiple="typeof multiple === 'undefined' ? false : multiple"
39
- :search-field="searchField"
40
- :select-user-info="selectOrganizationInfo"
41
- :separator="separator"
42
- @close="closeOrganizationTree"
36
+ v-if="treeType && treeType === 'DeptUserTree' && showOrganizationTreeFlag"
37
+ :department-info="departmentInfo"
38
+ :multiple="typeof multiple === 'undefined' ? false : multiple"
39
+ :search-field="searchField"
40
+ :select-user-info="selectOrganizationInfo"
41
+ :separator="separator"
42
+ @close="closeOrganizationTree"
43
43
  />
44
- <!-- 部门树 -->
44
+ <!-- 部门树 -->
45
45
  <department-tree
46
- v-if="treeType && treeType === 'DeptTree' && showOrganizationTreeFlag"
47
- :check-strictly="
48
- typeof checkStrictly === 'undefined' ? false : checkStrictly
49
- "
50
- :multiple="typeof multiple === 'undefined' ? false : multiple"
51
- :search-field="searchField"
52
- :select-department-info="selectOrganizationInfo"
53
- :separator="separator"
54
- width="30%"
55
- @close="closeOrganizationTree"
46
+ v-if="treeType && treeType === 'DeptTree' && showOrganizationTreeFlag"
47
+ :check-strictly="typeof checkStrictly === 'undefined' ? false : checkStrictly"
48
+ :multiple="typeof multiple === 'undefined' ? false : multiple"
49
+ :search-field="searchField"
50
+ :select-department-info="selectOrganizationInfo"
51
+ :separator="separator"
52
+ width="30%"
53
+ @close="closeOrganizationTree"
56
54
  />
57
- <!-- 工作组树 -->
55
+ <!-- 工作组树 -->
58
56
  <workgroup-tree
59
- v-if="treeType && treeType === 'WgTree' && showOrganizationTreeFlag"
60
- :multiple="typeof multiple === 'undefined' ? false : multiple"
61
- :branch-info="departmentInfo"
62
- :search-field="searchField"
63
- :select-workgroup-info="selectOrganizationInfo"
64
- :separator="separator"
65
- width="30%"
66
- @close="closeOrganizationTree"
57
+ v-if="treeType && treeType === 'WgTree' && showOrganizationTreeFlag"
58
+ :multiple="typeof multiple === 'undefined' ? false : multiple"
59
+ :branch-info="departmentInfo"
60
+ :search-field="searchField"
61
+ :select-workgroup-info="selectOrganizationInfo"
62
+ :separator="separator"
63
+ width="30%"
64
+ @close="closeOrganizationTree"
67
65
  />
68
- <!-- 工作组人员树 -->
66
+ <!-- 工作组人员树 -->
69
67
  <workgroup-user-tree
70
- v-if="treeType && treeType === 'WgUserTree' && showOrganizationTreeFlag"
71
- :branch-info="departmentInfo"
72
- :multiple="typeof multiple === 'undefined' ? false : multiple"
73
- :search-field="searchField"
74
- :select-user-info="selectOrganizationInfo"
75
- :separator="separator"
76
- width="30%"
77
- @close="closeOrganizationTree"
68
+ v-if="treeType && treeType === 'WgUserTree' && showOrganizationTreeFlag"
69
+ :branch-info="departmentInfo"
70
+ :multiple="typeof multiple === 'undefined' ? false : multiple"
71
+ :search-field="searchField"
72
+ :select-user-info="selectOrganizationInfo"
73
+ :separator="separator"
74
+ width="30%"
75
+ @close="closeOrganizationTree"
78
76
  />
79
- <!-- <remove-user
77
+ <!-- <remove-user
80
78
  v-if="treeType && (treeType === 'DeptUserTree' || treeType === 'WgUserTree') && showRemoveComponent"
81
79
  :select-user-info="selectOrganizationInfo"
82
80
  :search-field="searchField"
@@ -90,7 +88,7 @@
90
88
  :separator="separator"
91
89
  @close="closeRemoveComponent"
92
90
  /> -->
93
- <!-- <remove-workgroup
91
+ <!-- <remove-workgroup
94
92
  v-if="treeType && treeType === 'WgTree' && showRemoveComponent"
95
93
  :select-workgroup-info="selectOrganizationInfo"
96
94
  :search-field="searchField"
@@ -101,494 +99,447 @@
101
99
  </template>
102
100
 
103
101
  <script>
104
- import {Delete as ElIconDelete, Search as ElIconSearch,} from '@element-plus/icons-vue'
102
+ import { Delete as ElIconDelete, Search as ElIconSearch } from '@element-plus/icons-vue'
105
103
  // import Vue from 'vue'
106
- import {getPropNameWhenJoinTable, setEntityFieldValue,} from '../../../src/utils/util'
104
+ import { getPropNameWhenJoinTable, setEntityFieldValue } from '../../../src/utils/util'
107
105
 
108
106
  export default {
109
- components: {
110
- ElIconSearch,
111
- ElIconDelete,
112
- },
113
- name: 'OrganizationInput',
114
- model: {
115
- prop: 'value',
116
- event: 'input',
117
- },
118
- props: {
119
- value: {
120
- type: String,
121
- default: '',
122
- },
123
- // 是否多选
124
- multiple: {
125
- type: Boolean,
126
- default: false,
127
- },
128
- // 是否 “不选中” 子部门
129
- checkStrictly: {
130
- type: Boolean,
131
- default: false,
132
- },
133
- // 树类型 部门人员树DeptUserTree、部门树DeptTree、工作组树WgTree、工作组人员树WgUserTree
134
- treeType: {
135
- type: String,
136
- default: 'DeptUserTree',
137
- },
138
- // 是否禁用
139
- disabled: {
140
- type: Boolean,
141
- default: false,
142
- },
143
- // 字段与组织结构对应信息集合,格式为:[{type:'loginName',model:'字段名'}]
144
- // 人员树时,type的可选值有:id、name、loginName、email、telephone、mainDeptName、mainDeptId、subCompanyName、subCompanyId
145
- // 部门/工作组树时:type的可选值有:id、name、code
146
- fields: {
147
- type: Array,
148
- default: null,
149
- },
150
- // 当前表单数据信息
151
- models: {
152
- type: Object,
153
- default: null,
154
- },
155
- // 文本框大小large/medium/small/mini
156
- size: {
157
- type: String,
158
- default: '',
159
- },
160
- // 列表组件行编辑使用,sql查询时数据表名称,用于自定义系统中列表组件中字段多表查询带有别名时,将点"."改成两个下划线"__"时使用
161
- tableName: {
162
- type: String,
163
- default: null,
164
- },
165
- // 列表组件行编辑使用,是否是关联表,用于确定属性名是否需要拼接tableName
166
- isJoinTable: {
167
- type: Boolean,
168
- default: false,
169
- },
170
- // 指定部门或者工作组
171
- departmentInfo: {
172
- type: Array,
173
- default: null,
174
- },
175
- // 多选树时结果之间的分隔符,默认是逗号分隔
176
- separator: {
177
- type: String,
178
- default: ',',
179
- },
180
- // 是否打开树
181
- openTree:{
182
- type: Boolean,
183
- default: true,
184
- }
185
- },
186
- data() {
187
- return {
188
- showOrganizationTreeFlag: false, // 选择组织树所用
189
- isAppendResult: false, // 是否添加用户、部门、工作组,默认是替换,false表示替换选择的结果,true表示追加选择的结果
190
- showRemoveComponent: false, // 实现显示移除用户、部门、工作组组件
191
- selectOrganizationInfo: null, // 已选择集合,多个信息之间以逗号隔开
192
- searchField: null, // 已选的集合是什么内容,id、loginName(登录名)、name(用户名称/部门名称/工作组名称)、code(部门编码/工作组编码)、email(邮箱)、telephone(电话)等等
193
- selectOrganizationAllInfo: {}, // 选择的所有信息,{id:'xx',name:'xx',loginName:'xx',code:'xx',email:'xx',telephone:'xx'}
194
- }
195
- },
196
- created() {
197
- },
198
- methods: {
199
- // change事件
200
- changeEvent(value) {
201
- this.$emit('change', value)
202
- },
203
- // 打开组织树
204
- showOrganizationTree() {
205
- if (this.openTree){
206
- let isMulti = this.multiple
207
- if (typeof isMulti === 'undefined') {
208
- isMulti = false
209
- }
210
- if (isMulti === true) {
211
- // 多选时才需要显示结果集合
212
- this.getSelectInfo()
213
- }
214
- this.$emit('focus')
215
- this.showOrganizationTreeFlag = true
216
- this.$emit('show-tree')
217
- }
218
- },
219
- getPropName(prop, isJoinTable, tableName) {
220
- return getPropNameWhenJoinTable(prop, isJoinTable, tableName)
221
- },
222
- // 清空已选的结果
223
- emptyOrganizationResult() {
224
- const orgFields = this.fields
225
- if (orgFields && orgFields.length > 0) {
226
- orgFields.forEach((orgField) => {
227
- // orgDataType的值:
228
- // 人员时:id、name、loginName、email、telephone
229
- // 部门或工作组时:id、name
230
- const model = this.getPropName(orgField.model)
231
- this.setValue(model, null)
232
- })
233
- this.selectOrganizationAllInfo = {}
234
- this.selectOrganizationInfo = null
235
- this.searchField = null
236
- }
237
- },
238
- // 关闭组织树
239
- closeOrganizationTree(selectNodeInfo) {
240
- if (selectNodeInfo) {
241
- // 是否是多选树
242
- this.setOrganizationData(selectNodeInfo)
243
- }
244
- this.showOrganizationTreeFlag = false
245
- },
246
- setOrganizationData(orgData, isRemove, removeItems) {
247
- let isMulti = this.multiple
248
- if (typeof isMulti === 'undefined') {
249
- isMulti = false
250
- }
251
- const treeType = this.treeType
252
- const orgFields = this.fields
253
- if (orgFields && orgFields.length > 0) {
254
- orgFields.forEach((orgField) => {
255
- // orgDataType的值:
256
- // 人员时:id、name、loginName、email、telephone
257
- // 部门或工作组时:id、name、code
258
- const orgDataType = orgField.type
259
- const orgSelectData = this.getOrgSelectData(
260
- orgDataType,
261
- orgData,
262
- this.isUserTree(treeType),
263
- isMulti
264
- )
265
- const model = this.getPropName(orgField.model)
266
- this.getOrgDataModel(
267
- model,
268
- orgSelectData,
269
- isMulti,
270
- orgDataType,
271
- isRemove,
272
- removeItems
273
- )
274
- })
275
- }
276
- },
277
- /**
278
- * @param orgDataType 字段属性:id、name、loginName、code、email、telephone
279
- */
280
- getOrgDataModel(
281
- model,
282
- orgSelectData,
283
- isMulti,
284
- orgDataType,
285
- isRemove,
286
- removeItems
287
- ) {
288
- if (isMulti) {
289
- // 表示是替换或添加操作
290
- const orgResult = this.getModelValue(model)
291
- // 表示替换结果
292
- this.selectOrganizationAllInfo[orgDataType] = orgSelectData
293
- this.setValue(model, orgSelectData)
294
- // 参数分别为:属性名、原来的值、新替换的值
295
- this.$emit('replace', model, orgResult, orgSelectData)
296
- } else {
297
- this.setValue(model, orgSelectData)
298
- }
299
- },
300
- getModelValue(model) {
301
- let modelValue = ''
302
- if (this.isJoinTable === false && model && model.indexOf('.') > 0) {
303
- const parentObj = this.getParentObject(model, this.models)
304
- modelValue = parentObj[model.substring(model.lastIndexOf('.') + 1)]
305
- } else {
306
- model = this.getPropName(model)
307
- modelValue = this.models[model]
308
- }
309
- return modelValue
310
- },
311
- // 是否是人员树
312
- isUserTree(treeType) {
313
- return treeType === 'DeptUserTree' || treeType === 'WgUserTree'
314
- },
315
- // 获得组织树选择的结果
316
- getOrgSelectData(orgDataType, selectNodeInfo, isUserTree, isMulti) {
317
- if (isMulti === true) {
318
- // 多选树时
319
- if (orgDataType === 'id') {
320
- if (isUserTree) {
321
- return selectNodeInfo.userIds.join(this.separator)
322
- } else {
323
- return selectNodeInfo.ids.join(this.separator)
324
- }
325
- } else if (orgDataType === 'name') {
326
- if (isUserTree) {
327
- return selectNodeInfo.userNames.join(this.separator)
328
- } else {
329
- return selectNodeInfo.names.join(this.separator)
330
- }
331
- } else if (orgDataType === 'code') {
332
- if (!isUserTree) {
333
- return selectNodeInfo.codes.join(this.separator)
334
- }
335
- } else if (orgDataType === 'loginName') {
336
- return selectNodeInfo.loginNames.join(this.separator)
337
- } else if (orgDataType === 'email') {
338
- return selectNodeInfo.emails.join(this.separator)
339
- } else if (orgDataType === 'telephone') {
340
- return selectNodeInfo.telephones.join(this.separator)
341
- } else if (orgDataType === 'mainDeptName') {
342
- // 正职部门名称
343
- const mainDeptNames = []
344
- if (isUserTree) {
345
- const users = selectNodeInfo.users
346
- if (users) {
347
- users.forEach((user) => {
348
- mainDeptNames.push(user.mainDepartmentName)
349
- })
350
- }
351
- }
352
- return mainDeptNames.join(this.separator)
353
- } else if (orgDataType === 'mainDeptId') {
354
- // 正职部门id
355
- const mainDeptIds = []
356
- if (isUserTree) {
357
- const users = selectNodeInfo.users
358
- if (users) {
359
- users.forEach((user) => {
360
- if (user.mainDepartmentId) {
361
- mainDeptIds.push(user.mainDepartmentId)
362
- }
363
- })
364
- }
365
- }
366
- return mainDeptIds.join(this.separator)
367
- } else if (orgDataType === 'mainDeptCode') {
368
- // 正职部门code
369
- const mainDeptCodes = []
370
- if (isUserTree) {
371
- const users = selectNodeInfo.users
372
- if (users) {
373
- users.forEach((user) => {
374
- if (user.mainDepartmentCode) {
375
- mainDeptCodes.push(user.mainDepartmentCode)
376
- }
377
- })
378
- }
379
- }
380
- return mainDeptCodes.join(this.separator)
381
- } else if (orgDataType === 'subCompanyName') {
382
- // 分支名称
383
- const branchNames = []
384
- if (isUserTree) {
385
- const users = selectNodeInfo.users
386
- if (users) {
387
- users.forEach((user) => {
388
- if (user.subCompanyName) {
389
- branchNames.push(user.subCompanyName)
390
- }
391
- })
392
- }
393
- }
394
- return branchNames.join(this.separator)
395
- } else if (orgDataType === 'subCompanyId') {
396
- // 分支id
397
- const branchDeptIds = []
398
- if (isUserTree) {
399
- const users = selectNodeInfo.users
400
- if (users) {
401
- users.forEach((user) => {
402
- if (user.subCompanyId) {
403
- branchDeptIds.push(user.subCompanyId)
404
- }
405
- })
406
- }
407
- }
408
- return branchDeptIds.join(this.separator)
409
- }
410
- } else {
411
- // 单选树时
412
- if (orgDataType === 'mainDeptName') {
413
- // 正职部门名称
414
- let mainDeptName = null
415
- if (isUserTree) {
416
- const user = selectNodeInfo.user
417
- if (user) {
418
- mainDeptName = user.mainDepartmentName
419
- }
420
- }
421
- return mainDeptName
422
- } else if (orgDataType === 'mainDeptId') {
423
- // 正职部门id
424
- let mainDeptId = null
425
- if (isUserTree) {
426
- const user = selectNodeInfo.user
427
- if (user) {
428
- mainDeptId = user.mainDepartmentId
429
- }
430
- }
431
- return mainDeptId
432
- } else if (orgDataType === 'mainDeptCode') {
433
- // 正职部门code
434
- let mainDeptCode = null
435
- if (isUserTree) {
436
- const user = selectNodeInfo.user
437
- if (user) {
438
- mainDeptCode = user.mainDepartmentCode
439
- }
440
- }
441
- return mainDeptCode
442
- } else if (orgDataType === 'subCompanyName') {
443
- // 分支名称
444
- let branchName = null
445
- if (isUserTree) {
446
- const user = selectNodeInfo.user
447
- if (user) {
448
- branchName = user.subCompanyName
449
- }
450
- }
451
- return branchName
452
- } else if (orgDataType === 'subCompanyId') {
453
- // 分支id
454
- let branchId = null
455
- if (isUserTree) {
456
- const user = selectNodeInfo.user
457
- if (user) {
458
- branchId = user.subCompanyId
459
- }
460
- }
461
- return branchId
462
- } else {
463
- return selectNodeInfo[orgDataType]
464
- }
465
- }
466
- },
467
- // 显示移除用户、部门、工作组组件
468
- showMyRemoveComponent() {
469
- this.getSelectInfo()
470
- if (
471
- !this.selectOrganizationInfo ||
472
- this.selectOrganizationInfo === null ||
473
- this.selectOrganizationInfo === ''
474
- ) {
475
- this.$message({
476
- showClose: true,
477
- type: 'warning',
478
- message: this.$t(
479
- 'imatrixUIMessage.organizationTreeNoResultNotRemove'
480
- ),
481
- })
482
- } else {
483
- this.showRemoveComponent = true
484
- }
485
- },
486
- getSelectInfo() {
487
- const searchFields = [
488
- 'id',
489
- 'code',
490
- 'loginName',
491
- 'email',
492
- 'telephone',
493
- 'name',
494
- ]
495
- const keys = Object.keys(this.selectOrganizationAllInfo)
496
- if (keys.length === 0) {
497
- // 表示是初始化时,从表单对象中获得信息
498
- for (let i = 0; i < searchFields.length; i++) {
499
- const prop = searchFields[i]
500
- const fieldSettings = this.fields.filter((field) => {
501
- return field.type === prop
502
- })
503
- if (fieldSettings && fieldSettings.length > 0) {
504
- const fieldSetting = fieldSettings[0]
505
- if (fieldSetting) {
506
- const model = this.getPropName(fieldSetting.model)
507
- const selectInfo = this.getModelValue(model)
508
- if (selectInfo && selectInfo !== null && selectInfo !== '') {
509
- this.selectOrganizationInfo = selectInfo
510
- this.searchField = prop
511
- break
512
- }
513
- }
514
- }
515
- }
516
- } else {
517
- // 表示是选择用户后
518
- for (let i = 0; i < searchFields.length; i++) {
519
- const prop = searchFields[i]
520
- const selectInfo = this.selectOrganizationAllInfo[prop]
521
- if (selectInfo && selectInfo !== null && selectInfo !== '') {
522
- this.selectOrganizationInfo = selectInfo
523
- this.searchField = prop
524
- break
525
- }
526
- }
527
- }
528
- },
529
- setValue(model, finallyOrgResult) {
530
- if (this.models) {
531
- if (this.isJoinTable === false && model && model.indexOf('.') > 0) {
532
- const parentObj = this.getParentObject(model, this.models)
533
- if (parentObj) {
534
- setEntityFieldValue(
535
- parentObj,
536
- model.substring(model.lastIndexOf('.') + 1),
537
- finallyOrgResult
538
- )
539
- // Vue.set(parentObj, model.substring(model.lastIndexOf('.') + 1), finallyOrgResult)
540
- }
541
- } else {
542
- model = this.getPropName(model)
543
- setEntityFieldValue(this.models, model, finallyOrgResult)
544
- // Vue.set(this.models, model, finallyOrgResult)
545
- }
546
- console.log('this.value', this.models)
547
- // 调用setValue事件
548
- this.$emit('setValue', model, finallyOrgResult)
549
- if (
550
- finallyOrgResult === undefined ||
551
- finallyOrgResult === null ||
552
- finallyOrgResult === ''
553
- ) {
554
- this.$emit( 'clear', model)
555
- }
556
- }
557
- },
558
- getParentObject(prop, models) {
559
- const nestedProp = prop.split('.')
560
- // 属性只有一个时父对象就是models
561
- if (nestedProp.length === 1) {
562
- return models
563
- } else {
564
- let parentObject
565
- // 属性超过2个时先找到最后一层属性的父对象
566
- for (let i = 0; i < nestedProp.length - 1; i++) {
567
- if (i === 0) {
568
- parentObject = this.getParentModelProp(nestedProp[i], models)
569
- } else {
570
- parentObject = this.getParentModelProp(nestedProp[i], parentObject)
571
- }
572
- }
573
- return parentObject
574
- }
575
- },
576
- getParentModelProp(prop, parentObj) {
577
- if (!parentObj) {
578
- parentObj = {}
579
- }
580
- if (!parentObj[prop]) {
581
- parentObj[prop] = {}
582
- }
583
- return parentObj[prop]
584
- },
585
- },
586
- emits: [
587
- 'replace',
588
- 'setValue',
589
- 'clear',
590
- 'focus',
591
- 'update:value',
592
- ],
107
+ components: {
108
+ ElIconSearch,
109
+ ElIconDelete
110
+ },
111
+ name: 'OrganizationInput',
112
+ model: {
113
+ prop: 'value',
114
+ event: 'input'
115
+ },
116
+ props: {
117
+ value: {
118
+ type: String,
119
+ default: ''
120
+ },
121
+ // 是否多选
122
+ multiple: {
123
+ type: Boolean,
124
+ default: false
125
+ },
126
+ // 是否 “不选中” 子部门
127
+ checkStrictly: {
128
+ type: Boolean,
129
+ default: false
130
+ },
131
+ // 树类型 部门人员树DeptUserTree、部门树DeptTree、工作组树WgTree、工作组人员树WgUserTree
132
+ treeType: {
133
+ type: String,
134
+ default: 'DeptUserTree'
135
+ },
136
+ // 是否禁用
137
+ disabled: {
138
+ type: Boolean,
139
+ default: false
140
+ },
141
+ // 字段与组织结构对应信息集合,格式为:[{type:'loginName',model:'字段名'}]
142
+ // 人员树时,type的可选值有:id、name、loginName、email、telephone、mainDeptName、mainDeptId、subCompanyName、subCompanyId
143
+ // 部门/工作组树时:type的可选值有:id、name、code
144
+ fields: {
145
+ type: Array,
146
+ default: null
147
+ },
148
+ // 当前表单数据信息
149
+ models: {
150
+ type: Object,
151
+ default: null
152
+ },
153
+ // 文本框大小large/medium/small/mini
154
+ size: {
155
+ type: String,
156
+ default: ''
157
+ },
158
+ // 列表组件行编辑使用,sql查询时数据表名称,用于自定义系统中列表组件中字段多表查询带有别名时,将点"."改成两个下划线"__"时使用
159
+ tableName: {
160
+ type: String,
161
+ default: null
162
+ },
163
+ // 列表组件行编辑使用,是否是关联表,用于确定属性名是否需要拼接tableName
164
+ isJoinTable: {
165
+ type: Boolean,
166
+ default: false
167
+ },
168
+ // 指定部门或者工作组
169
+ departmentInfo: {
170
+ type: Array,
171
+ default: null
172
+ },
173
+ // 多选树时结果之间的分隔符,默认是逗号分隔
174
+ separator: {
175
+ type: String,
176
+ default: ','
177
+ },
178
+ // 是否打开树
179
+ openTree: {
180
+ type: Boolean,
181
+ default: true
182
+ }
183
+ },
184
+ data() {
185
+ return {
186
+ showOrganizationTreeFlag: false, // 选择组织树所用
187
+ isAppendResult: false, // 是否添加用户、部门、工作组,默认是替换,false表示替换选择的结果,true表示追加选择的结果
188
+ showRemoveComponent: false, // 实现显示移除用户、部门、工作组组件
189
+ selectOrganizationInfo: null, // 已选择集合,多个信息之间以逗号隔开
190
+ searchField: null, // 已选的集合是什么内容,id、loginName(登录名)、name(用户名称/部门名称/工作组名称)、code(部门编码/工作组编码)、email(邮箱)、telephone(电话)等等
191
+ selectOrganizationAllInfo: {} // 选择的所有信息,{id:'xx',name:'xx',loginName:'xx',code:'xx',email:'xx',telephone:'xx'}
192
+ }
193
+ },
194
+ created() {},
195
+ methods: {
196
+ // change事件
197
+ changeEvent(value) {
198
+ this.$emit('change', value)
199
+ },
200
+ // 打开组织树
201
+ showOrganizationTree() {
202
+ if (this.openTree) {
203
+ let isMulti = this.multiple
204
+ if (typeof isMulti === 'undefined') {
205
+ isMulti = false
206
+ }
207
+ if (isMulti === true) {
208
+ // 多选时才需要显示结果集合
209
+ this.getSelectInfo()
210
+ }
211
+ this.$emit('focus')
212
+ this.showOrganizationTreeFlag = true
213
+ this.$emit('show-tree')
214
+ }
215
+ },
216
+ getPropName(prop, isJoinTable, tableName) {
217
+ return getPropNameWhenJoinTable(prop, isJoinTable, tableName)
218
+ },
219
+ // 清空已选的结果
220
+ emptyOrganizationResult() {
221
+ const orgFields = this.fields
222
+ if (orgFields && orgFields.length > 0) {
223
+ orgFields.forEach((orgField) => {
224
+ // orgDataType的值:
225
+ // 人员时:id、name、loginName、email、telephone
226
+ // 部门或工作组时:id、name
227
+ const model = this.getPropName(orgField.model)
228
+ this.setValue(model, null)
229
+ })
230
+ this.selectOrganizationAllInfo = {}
231
+ this.selectOrganizationInfo = null
232
+ this.searchField = null
233
+ }
234
+ },
235
+ // 关闭组织树
236
+ closeOrganizationTree(selectNodeInfo) {
237
+ if (selectNodeInfo) {
238
+ // 是否是多选树
239
+ this.setOrganizationData(selectNodeInfo)
240
+ }
241
+ this.showOrganizationTreeFlag = false
242
+ },
243
+ setOrganizationData(orgData, isRemove, removeItems) {
244
+ let isMulti = this.multiple
245
+ if (typeof isMulti === 'undefined') {
246
+ isMulti = false
247
+ }
248
+ const treeType = this.treeType
249
+ const orgFields = this.fields
250
+ if (orgFields && orgFields.length > 0) {
251
+ orgFields.forEach((orgField) => {
252
+ // orgDataType的值:
253
+ // 人员时:id、name、loginName、email、telephone
254
+ // 部门或工作组时:id、name、code
255
+ const orgDataType = orgField.type
256
+ const orgSelectData = this.getOrgSelectData(orgDataType, orgData, this.isUserTree(treeType), isMulti)
257
+ const model = this.getPropName(orgField.model)
258
+ this.getOrgDataModel(model, orgSelectData, isMulti, orgDataType, isRemove, removeItems)
259
+ })
260
+ }
261
+ },
262
+ /**
263
+ * @param orgDataType 字段属性:id、name、loginName、code、email、telephone
264
+ */
265
+ getOrgDataModel(model, orgSelectData, isMulti, orgDataType, isRemove, removeItems) {
266
+ if (isMulti) {
267
+ // 表示是替换或添加操作
268
+ const orgResult = this.getModelValue(model)
269
+ // 表示替换结果
270
+ this.selectOrganizationAllInfo[orgDataType] = orgSelectData
271
+ this.setValue(model, orgSelectData)
272
+ // 参数分别为:属性名、原来的值、新替换的值
273
+ this.$emit('replace', model, orgResult, orgSelectData)
274
+ } else {
275
+ this.setValue(model, orgSelectData)
276
+ }
277
+ },
278
+ getModelValue(model) {
279
+ let modelValue = ''
280
+ if (this.isJoinTable === false && model && model.indexOf('.') > 0) {
281
+ const parentObj = this.getParentObject(model, this.models)
282
+ modelValue = parentObj[model.substring(model.lastIndexOf('.') + 1)]
283
+ } else {
284
+ model = this.getPropName(model)
285
+ modelValue = this.models[model]
286
+ }
287
+ return modelValue
288
+ },
289
+ // 是否是人员树
290
+ isUserTree(treeType) {
291
+ return treeType === 'DeptUserTree' || treeType === 'WgUserTree'
292
+ },
293
+ // 获得组织树选择的结果
294
+ getOrgSelectData(orgDataType, selectNodeInfo, isUserTree, isMulti) {
295
+ if (isMulti === true) {
296
+ // 多选树时
297
+ if (orgDataType === 'id') {
298
+ if (isUserTree) {
299
+ return selectNodeInfo.userIds.join(this.separator)
300
+ } else {
301
+ return selectNodeInfo.ids.join(this.separator)
302
+ }
303
+ } else if (orgDataType === 'name') {
304
+ if (isUserTree) {
305
+ return selectNodeInfo.userNames.join(this.separator)
306
+ } else {
307
+ return selectNodeInfo.names.join(this.separator)
308
+ }
309
+ } else if (orgDataType === 'code') {
310
+ if (!isUserTree) {
311
+ return selectNodeInfo.codes.join(this.separator)
312
+ }
313
+ } else if (orgDataType === 'loginName') {
314
+ return selectNodeInfo.loginNames.join(this.separator)
315
+ } else if (orgDataType === 'email') {
316
+ return selectNodeInfo.emails.join(this.separator)
317
+ } else if (orgDataType === 'telephone') {
318
+ return selectNodeInfo.telephones.join(this.separator)
319
+ } else if (orgDataType === 'mainDeptName') {
320
+ // 正职部门名称
321
+ const mainDeptNames = []
322
+ if (isUserTree) {
323
+ const users = selectNodeInfo.users
324
+ if (users) {
325
+ users.forEach((user) => {
326
+ mainDeptNames.push(user.mainDepartmentName)
327
+ })
328
+ }
329
+ }
330
+ return mainDeptNames.join(this.separator)
331
+ } else if (orgDataType === 'mainDeptId') {
332
+ // 正职部门id
333
+ const mainDeptIds = []
334
+ if (isUserTree) {
335
+ const users = selectNodeInfo.users
336
+ if (users) {
337
+ users.forEach((user) => {
338
+ if (user.mainDepartmentId) {
339
+ mainDeptIds.push(user.mainDepartmentId)
340
+ }
341
+ })
342
+ }
343
+ }
344
+ return mainDeptIds.join(this.separator)
345
+ } else if (orgDataType === 'mainDeptCode') {
346
+ // 正职部门code
347
+ const mainDeptCodes = []
348
+ if (isUserTree) {
349
+ const users = selectNodeInfo.users
350
+ if (users) {
351
+ users.forEach((user) => {
352
+ if (user.mainDepartmentCode) {
353
+ mainDeptCodes.push(user.mainDepartmentCode)
354
+ }
355
+ })
356
+ }
357
+ }
358
+ return mainDeptCodes.join(this.separator)
359
+ } else if (orgDataType === 'subCompanyName') {
360
+ // 分支名称
361
+ const branchNames = []
362
+ if (isUserTree) {
363
+ const users = selectNodeInfo.users
364
+ if (users) {
365
+ users.forEach((user) => {
366
+ if (user.subCompanyName) {
367
+ branchNames.push(user.subCompanyName)
368
+ }
369
+ })
370
+ }
371
+ }
372
+ return branchNames.join(this.separator)
373
+ } else if (orgDataType === 'subCompanyId') {
374
+ // 分支id
375
+ const branchDeptIds = []
376
+ if (isUserTree) {
377
+ const users = selectNodeInfo.users
378
+ if (users) {
379
+ users.forEach((user) => {
380
+ if (user.subCompanyId) {
381
+ branchDeptIds.push(user.subCompanyId)
382
+ }
383
+ })
384
+ }
385
+ }
386
+ return branchDeptIds.join(this.separator)
387
+ }
388
+ } else {
389
+ // 单选树时
390
+ if (orgDataType === 'mainDeptName') {
391
+ // 正职部门名称
392
+ let mainDeptName = null
393
+ if (isUserTree) {
394
+ const user = selectNodeInfo.user
395
+ if (user) {
396
+ mainDeptName = user.mainDepartmentName
397
+ }
398
+ }
399
+ return mainDeptName
400
+ } else if (orgDataType === 'mainDeptId') {
401
+ // 正职部门id
402
+ let mainDeptId = null
403
+ if (isUserTree) {
404
+ const user = selectNodeInfo.user
405
+ if (user) {
406
+ mainDeptId = user.mainDepartmentId
407
+ }
408
+ }
409
+ return mainDeptId
410
+ } else if (orgDataType === 'mainDeptCode') {
411
+ // 正职部门code
412
+ let mainDeptCode = null
413
+ if (isUserTree) {
414
+ const user = selectNodeInfo.user
415
+ if (user) {
416
+ mainDeptCode = user.mainDepartmentCode
417
+ }
418
+ }
419
+ return mainDeptCode
420
+ } else if (orgDataType === 'subCompanyName') {
421
+ // 分支名称
422
+ let branchName = null
423
+ if (isUserTree) {
424
+ const user = selectNodeInfo.user
425
+ if (user) {
426
+ branchName = user.subCompanyName
427
+ }
428
+ }
429
+ return branchName
430
+ } else if (orgDataType === 'subCompanyId') {
431
+ // 分支id
432
+ let branchId = null
433
+ if (isUserTree) {
434
+ const user = selectNodeInfo.user
435
+ if (user) {
436
+ branchId = user.subCompanyId
437
+ }
438
+ }
439
+ return branchId
440
+ } else {
441
+ return selectNodeInfo[orgDataType]
442
+ }
443
+ }
444
+ },
445
+ // 显示移除用户、部门、工作组组件
446
+ showMyRemoveComponent() {
447
+ this.getSelectInfo()
448
+ if (!this.selectOrganizationInfo || this.selectOrganizationInfo === null || this.selectOrganizationInfo === '') {
449
+ this.$message({
450
+ showClose: true,
451
+ type: 'warning',
452
+ message: this.$t('imatrixUIMessage.organizationTreeNoResultNotRemove')
453
+ })
454
+ } else {
455
+ this.showRemoveComponent = true
456
+ }
457
+ },
458
+ getSelectInfo() {
459
+ const searchFields = ['id', 'code', 'loginName', 'email', 'telephone', 'name']
460
+ const keys = Object.keys(this.selectOrganizationAllInfo)
461
+ if (keys.length === 0) {
462
+ // 表示是初始化时,从表单对象中获得信息
463
+ for (let i = 0; i < searchFields.length; i++) {
464
+ const prop = searchFields[i]
465
+ const fieldSettings = this.fields.filter((field) => {
466
+ return field.type === prop
467
+ })
468
+ if (fieldSettings && fieldSettings.length > 0) {
469
+ const fieldSetting = fieldSettings[0]
470
+ if (fieldSetting) {
471
+ const model = this.getPropName(fieldSetting.model)
472
+ const selectInfo = this.getModelValue(model)
473
+ if (selectInfo && selectInfo !== null && selectInfo !== '') {
474
+ this.selectOrganizationInfo = selectInfo
475
+ this.searchField = prop
476
+ break
477
+ }
478
+ }
479
+ }
480
+ }
481
+ } else {
482
+ // 表示是选择用户后
483
+ for (let i = 0; i < searchFields.length; i++) {
484
+ const prop = searchFields[i]
485
+ const selectInfo = this.selectOrganizationAllInfo[prop]
486
+ if (selectInfo && selectInfo !== null && selectInfo !== '') {
487
+ this.selectOrganizationInfo = selectInfo
488
+ this.searchField = prop
489
+ break
490
+ }
491
+ }
492
+ }
493
+ },
494
+ setValue(model, finallyOrgResult) {
495
+ if (this.models) {
496
+ if (this.isJoinTable === false && model && model.indexOf('.') > 0) {
497
+ const parentObj = this.getParentObject(model, this.models)
498
+ if (parentObj) {
499
+ setEntityFieldValue(parentObj, model.substring(model.lastIndexOf('.') + 1), finallyOrgResult)
500
+ // Vue.set(parentObj, model.substring(model.lastIndexOf('.') + 1), finallyOrgResult)
501
+ }
502
+ } else {
503
+ model = this.getPropName(model)
504
+ setEntityFieldValue(this.models, model, finallyOrgResult)
505
+ // Vue.set(this.models, model, finallyOrgResult)
506
+ }
507
+ console.log('this.value', this.models)
508
+ // 调用setValue事件
509
+ this.$emit('setValue', model, finallyOrgResult)
510
+ if (finallyOrgResult === undefined || finallyOrgResult === null || finallyOrgResult === '') {
511
+ this.$emit('clear', model)
512
+ }
513
+ }
514
+ },
515
+ getParentObject(prop, models) {
516
+ const nestedProp = prop.split('.')
517
+ // 属性只有一个时父对象就是models
518
+ if (nestedProp.length === 1) {
519
+ return models
520
+ } else {
521
+ let parentObject
522
+ // 属性超过2个时先找到最后一层属性的父对象
523
+ for (let i = 0; i < nestedProp.length - 1; i++) {
524
+ if (i === 0) {
525
+ parentObject = this.getParentModelProp(nestedProp[i], models)
526
+ } else {
527
+ parentObject = this.getParentModelProp(nestedProp[i], parentObject)
528
+ }
529
+ }
530
+ return parentObject
531
+ }
532
+ },
533
+ getParentModelProp(prop, parentObj) {
534
+ if (!parentObj) {
535
+ parentObj = {}
536
+ }
537
+ if (!parentObj[prop]) {
538
+ parentObj[prop] = {}
539
+ }
540
+ return parentObj[prop]
541
+ }
542
+ },
543
+ emits: ['replace', 'setValue', 'clear', 'focus', 'update:value', 'change']
593
544
  }
594
545
  </script>