t20-common-lib 0.11.4 → 0.12.0

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.
@@ -0,0 +1,1082 @@
1
+ <template>
2
+ <el-select
3
+ ref="selectTreeUnit"
4
+ :placeholder="placeholder"
5
+ :value="valueShow"
6
+ v-title="vTitle"
7
+ :clearable="clearable"
8
+ @clear="clearFn()"
9
+ :disabled="tagDisabled"
10
+ class="input-w nstc-mid"
11
+ popper-class="nstc-unit-select-popper"
12
+ @visible-change="showOpt"
13
+ @outClick="outClick"
14
+ >
15
+ <div
16
+ v-loading="loading"
17
+ class="nstc-unit-box"
18
+ :class="{ single: !multiple }"
19
+ @click="selecetClick($event)"
20
+ >
21
+ <el-option :label="null" :value="null" style="display: none" />
22
+ <el-option
23
+ v-for="(item, i) in wCdList"
24
+ :key="i"
25
+ :label="item[defineProps.label]"
26
+ :value="item[defineProps.value]"
27
+ style="display: none"
28
+ />
29
+ <div class="nstc-unit-select-row">
30
+ <el-input
31
+ v-model="searchKey"
32
+ :validate-event="false"
33
+ :placeholder="$t('common_a_0004')"
34
+ clearable
35
+ @input="debounce(searchTree, 1000)"
36
+ class="input-w nstc-unit-search"
37
+ ></el-input>
38
+ <Filters :isEnableCommonConfigControl="isEnableCommonConfigControl" @filterChange="filterChange" v-bind="$attrs" />
39
+ <div class="el-button-group n20-icon-group-button">
40
+ <button
41
+ type="button"
42
+ @click="changeType('tree')"
43
+ v-title="$t('common_a_0009')"
44
+ :class="
45
+ isList ? 'el-button--default is-plain' : 'el-button--primary'
46
+ "
47
+ class="el-button el-button--mini"
48
+ onlyicon=""
49
+ style="width: 31.5px"
50
+ >
51
+ <i class="iconfont icon-goujianshu"></i>
52
+ </button>
53
+ <button
54
+ type="button"
55
+ @click="changeType('list')"
56
+ v-title="$t('common_a_0010')"
57
+ :class="
58
+ isList ? 'el-button--primary' : 'el-button--default is-plain'
59
+ "
60
+ class="el-button el-button--mini"
61
+ onlyicon=""
62
+ style="width: 31.5px"
63
+ >
64
+ <i class="iconfont icon-liebiao"></i>
65
+ </button>
66
+ </div>
67
+ </div>
68
+ <div class="nstc-unit-content">
69
+ <el-checkbox
70
+ ref="allcheck"
71
+ v-if="showAllCheck && multiple && !onlyUnit"
72
+ v-model="checkD"
73
+ class="m-l-lg nstc-unit-content-heightfix"
74
+ :label="$t('common_a_0003')"
75
+ @change="handleCheckBox"
76
+ />
77
+ <Tree
78
+ ref="tree"
79
+ :data="data"
80
+ :isList="isList"
81
+ :node-key="nodeKey"
82
+ :multiple="multiple"
83
+ :defaultExpandedKeys="defaultExpandedKeys"
84
+ :props="defineProps"
85
+ :default-expanded-keys="expandedKeys"
86
+ @check="check"
87
+ @checkedBro="checkedBro"
88
+ @checkedChild="checkedChild"
89
+ @node-click="nodeClick"
90
+ :load="loadNode"
91
+ :lazy="isLazy"
92
+ v-on="$listeners"
93
+ v-bind="$attrs"
94
+ />
95
+ </div>
96
+ <div class="nstc-unit-footer" v-if="multiple">
97
+ <el-button type="primary" size="mini" @click="confirm">{{
98
+ $t("common_a_0001")
99
+ }}</el-button>
100
+ <el-button class="nstc-unit-cancel" size="mini" @click="cancel">{{
101
+ $t("common_a_0002")
102
+ }}</el-button>
103
+ </div>
104
+ </div>
105
+ </el-select>
106
+ </template>
107
+
108
+ <script>
109
+ import emitter from "element-ui/src/mixins/emitter";
110
+ import Tree from "@/common/selectTree/Tree/index.vue";
111
+ import ElSelect from "@/common/selectTree/Extends/ElSelect.vue";
112
+ import Filters from "@/common/selectTree/Filters/index.vue"
113
+ import request from "@/utils/request";
114
+ import { getCommonConfig } from "@/api/common";
115
+ import treeSelectImg from "@/common/selectTree/imgs/tree-select.png";
116
+ import treeUnSelectImg from "@/common/selectTree/imgs/tree-unselect.png";
117
+ import listSelectImg from "@/common/selectTree/imgs/list-select.png";
118
+ import listUnSelectImg from "@/common/selectTree/imgs/list-unselect.png";
119
+ export default {
120
+ name: "SelectTreeUnitForm",
121
+ components: { Tree, ElSelect, Filters },
122
+ mixins: [emitter],
123
+ inject: {
124
+ elForm: {
125
+ default: "",
126
+ },
127
+ elFormItem: {
128
+ default: "",
129
+ },
130
+ },
131
+ props: {
132
+ showAllCheck: {
133
+ type: Boolean,
134
+ default: false,
135
+ },
136
+ disabled: {
137
+ type: Boolean,
138
+ default: false,
139
+ },
140
+ clearable: {
141
+ type: Boolean,
142
+ default: true,
143
+ },
144
+ selectFirst: {
145
+ type: Boolean,
146
+ default: false,
147
+ },
148
+ url: {
149
+ type: String,
150
+ default: "/api/nstc-gtcp/1.0/fundTree",
151
+ },
152
+ listUrl: {
153
+ type: String,
154
+ default: "/api/nstc-gtcp/1.0/fundTree/list",
155
+ },
156
+ isUnitDataScope: {
157
+ type: String,
158
+ default: "0",
159
+ },
160
+ seachObj: {
161
+ type: Object,
162
+ default: () => {
163
+ return {};
164
+ },
165
+ },
166
+ multiple: {
167
+ type: Boolean,
168
+ default: false,
169
+ },
170
+ defaultSelectAll: {
171
+ type: Boolean,
172
+ default: false,
173
+ },
174
+ defaultSelect: {
175
+ type: Array,
176
+ default: () => [],
177
+ },
178
+ upDateValue: {
179
+ type: Array,
180
+ default: () => [],
181
+ },
182
+ searchUnitNo: {
183
+ type: String,
184
+ default: "",
185
+ },
186
+ moduleNo: {
187
+ type: String,
188
+ default: "bill-group", //bill-group,bill-collect
189
+ },
190
+ relaNo: {
191
+ type: String,
192
+ default: "",
193
+ },
194
+ value: {
195
+ type: [String, Number, Array],
196
+ default: () => [],
197
+ },
198
+ collapseTags: {
199
+ type: Boolean,
200
+ default: true,
201
+ },
202
+ nodeKey: {
203
+ type: String,
204
+ default: "id",
205
+ },
206
+ placeholder: {
207
+ type: String,
208
+ default: "请选择",
209
+ },
210
+ // showCheckbox: {
211
+ // type: Boolean,
212
+ // default: true,
213
+ // },
214
+ defineProps: {
215
+ type: Object,
216
+ default: () => {
217
+ return {
218
+ label: "unitName",
219
+ value: "unitNo",
220
+ children: "children",
221
+ isLeaf: "isLeaf",
222
+ };
223
+ },
224
+ },
225
+ filterConfig: {
226
+ type: Object,
227
+ default: () => {
228
+ return {
229
+ searchFields: [], // 需要展示在组件上的查询字段
230
+ filterList: [] // 与展示字段相匹配的表单组件配置
231
+ }
232
+ }
233
+ },
234
+ /**
235
+ * 是否根据财资公参配置显示
236
+ * - true:需要根据财资公参配置接口,根据返回结果控制是否显示
237
+ * - false:不需要根据财资公参配置接口,根据组件内配置控制是否显示
238
+ */
239
+ useCommonConfigControl: {
240
+ type: Boolean,
241
+ default: true
242
+ }
243
+ },
244
+ data() {
245
+ return {
246
+ mounseInTree: false,
247
+ mounseInList: false,
248
+ loading: false,
249
+ isList: false, //是否是平铺
250
+ isLazy: true, //默认开启懒加载
251
+ data: [],
252
+ show: false,
253
+ list: [],
254
+ expandedKeys: [],
255
+ wCdList: [],
256
+ checkD: false,
257
+ queryType: "0", //0,查询顶级单位;1,查询所有;2,查询直属下级(不含本身,包含子孙);3,查询所有下级(不含本身,不含子孙);4,查询兄弟级(不含子孙)5,查询直接父级
258
+ hasQueryAll: false, //是否已请求过全部数据,默认否
259
+ selectData: [],
260
+ selectDataCache: [],
261
+ valueShow: [],
262
+ searchKey: "",
263
+ timer: null,
264
+ onlyUnit: false,
265
+ defaultExpandedKeys: [],
266
+ page: {
267
+ current: 1,
268
+ size: -1,
269
+ },
270
+ treeSelectImg,
271
+ treeUnSelectImg,
272
+ listSelectImg,
273
+ listUnSelectImg,
274
+ searchParams: {},
275
+ isEnableCommonConfigControl: false
276
+ };
277
+ },
278
+ computed: {
279
+ vTitle() {
280
+ let vl = this.valueShow.length;
281
+ if (this.multiple) return vl ? this.valueShow.slice(0, 15) : "";
282
+ return vl ? this.valueShow : "";
283
+ },
284
+ tagDisabled() {
285
+ return this.disabled || (this.elForm || {}).disabled;
286
+ },
287
+ valueC: {
288
+ get() {
289
+ return this.value;
290
+ },
291
+ set(val) {
292
+ this.$emit("input", val);
293
+ this.$emit("dataChange", this.selectData);
294
+ },
295
+ },
296
+ },
297
+ async mounted() {
298
+ if (!this.url) {
299
+ this.$message.error("请传入单位树请求地址!");
300
+ return;
301
+ }
302
+ if (this.defaultSelectAll) {
303
+ //默认选择全部时,不会读取传的默认选项
304
+ this.checkD = true;
305
+ await this.getCommonConfig();
306
+ if (this.isList) {
307
+ await this.initList();
308
+ }
309
+ this.handleCheckBox(true);
310
+ return "end";
311
+ }
312
+ if (
313
+ this.defaultSelect &&
314
+ Array.isArray(this.defaultSelect) &&
315
+ this.defaultSelect.length > 0
316
+ ) {
317
+ this.selectData = [...this.defaultSelect];
318
+ // let checkData = this.defaultSelect.map((d) => {
319
+ // return d.unitNo;
320
+ // });
321
+ this.valueShow = this.defaultSelect.map((d) => {
322
+ return d.unitName;
323
+ });
324
+ // this.$emit("input", checkData);
325
+ // this.$emit("dataChange", this.selectData);
326
+ }
327
+ await this.getCommonConfig();
328
+ if (this.isList) {
329
+ this.initList();
330
+ } else {
331
+ this.init();
332
+ }
333
+ },
334
+ watch: {
335
+ value: {
336
+ handler(now) {
337
+ if (!now) {
338
+ this.clearFn();
339
+ }
340
+ },
341
+ },
342
+ },
343
+ methods: {
344
+ filterChange(val, searchKey) {
345
+ this.searchParams[searchKey] = val
346
+ if (!val && val !==0) {
347
+ delete this.searchParams[searchKey]
348
+ }
349
+ this.filterSearchTree()
350
+ },
351
+ changeType(type) {
352
+ if (type == "tree" && this.isList) {
353
+ this.data = [];
354
+ this.init(type);
355
+ this.isList = false;
356
+ } else if (type == "list" && !this.isList) {
357
+ this.data = [];
358
+ this.initList(type);
359
+ this.isList = true;
360
+ }
361
+ },
362
+ async getCommonConfig(resolve) {
363
+ let res = await getCommonConfig();
364
+ if (res && res.length > 0) {
365
+ res.forEach((r) => {
366
+ if (r.configGroupName.includes("单位树")) {
367
+ if (r.configs && r.configs.length > 0) {
368
+ r.configs.forEach((c) => {
369
+ if (c.configGroupName.includes("单位树")) {
370
+ if (c.configValue == "1") {
371
+ this.isList = true;
372
+ } else {
373
+ this.isList = false;
374
+ }
375
+ }
376
+ });
377
+ }
378
+ }
379
+ if (r.configs && r.configs.length) {
380
+ const cfg = r.configs[0]
381
+ if (cfg.configKey === 'ENABLE_AREA') {
382
+ this.isEnableCommonConfigControl = cfg.configValue === '1'
383
+ }
384
+ }
385
+ });
386
+ }
387
+ },
388
+ selecetClick(e) {
389
+ this.$refs.tree.showDropMenu = null;
390
+ },
391
+ init(type) {
392
+ this.$refs.tree.store.lazy = true;
393
+ if (this.searchUnitNo) {
394
+ //查询指定单位的下级
395
+ //暂不支持此模式下的默认单位设置,更新选择单位,没提需求
396
+ this.getUnitTree("6");
397
+ return "end";
398
+ }
399
+ new Promise((resolve) => {
400
+ this.getTreeData("1", { resolve });
401
+ })
402
+ .then(() => {
403
+ // 初始化时,判断是否选择节点
404
+ let temp = [];
405
+ let flatTemp = [];
406
+ this.flatData(this.data, flatTemp);
407
+ this.selectData.forEach((s, i) => {
408
+ flatTemp.forEach((d) => {
409
+ if (d.unitNo == s.unitNo) {
410
+ temp.push(d);
411
+ this.selectData[i] = d;
412
+ }
413
+ });
414
+ });
415
+ //去除没有权限的单位
416
+ temp = temp.filter((s) => {
417
+ return !s.disabled;
418
+ });
419
+ if (this.selectFirst && !type) {
420
+ //切换时不需要
421
+ //初始化时没有传默认单位和all时,根据selectFirst 默认选择第一家单位
422
+ if (temp.length < 1) {
423
+ let first = null;
424
+ let flatTemp = [];
425
+ this.flatData(this.data, flatTemp);
426
+ // flatTemp.reverse(); //递归的第一个单位会放到最后去,所以要反排一次
427
+ for (let i = 0; i < flatTemp.length; i++) {
428
+ if (!flatTemp[i].disabled) {
429
+ //取第一个有权限的单位
430
+ first = flatTemp[i];
431
+ break;
432
+ }
433
+ }
434
+ if (first) {
435
+ temp.push(first);
436
+ }
437
+ }
438
+ }
439
+ // else{
440
+ // this.$refs.tree.setCheckedNodes(temp);
441
+ // }
442
+ // this.$refs.tree.setCheckedNodes(temp);
443
+ //根据后续测试情况,看是否放进判断条件内 -----
444
+ this.$refs.tree.setCheckedNodes(temp);
445
+ this.selectData = temp;
446
+ if (!type) {
447
+ //模式切换时,不更新值
448
+ this.valueShow = this.selectData.map((s) => s.unitName);
449
+ let data = this.selectData.map((s) => s.unitNo);
450
+ this.$emit("input", this.multiple ? data : data[0]);
451
+ // this.$emit("input", data);
452
+ this.$emit("dataChange", this.selectData);
453
+ }
454
+ })
455
+ .finally(() => {
456
+ this.$emit("loaded");
457
+ });
458
+ },
459
+ /**
460
+ * @queryType 类型 //0,查询顶级单位;1,查询所有;2,查询直属下级(不含本身,不包含子孙);3,查询所有下级(不含本身,包含子孙);4,查询兄弟级(不含子孙)5,查询直接父级
461
+ */
462
+ getTreeData(queryType, dataT) {
463
+ this.loading = true;
464
+ let str =
465
+ "?moduleNo=" +
466
+ this.moduleNo +
467
+ "&isUnitDataScope=" +
468
+ this.isUnitDataScope;
469
+ if (queryType) {
470
+ str += "&queryType=" + queryType;
471
+ }
472
+ if (dataT) {
473
+ if (["2", "3", "4", "6"].includes(queryType)) {
474
+ //节点懒加载展开
475
+ str += "&unitNo=" + dataT.unitNo;
476
+ if (!dataT.unitNo) {
477
+ return "end";
478
+ }
479
+ }
480
+ }
481
+ for (let i in this.seachObj) {
482
+ str += `&${i}=${this.seachObj[i]}`;
483
+ }
484
+ for (let i in this.searchParams) {
485
+ str += `&${i}=${this.searchParams[i]}`
486
+ }
487
+ if (["1", "6"].includes(queryType) && this.searchKey) {
488
+ //搜索是在查询全部的模式下进行
489
+ str += "&unitNameOrNoLike=" + this.searchKey;
490
+ }
491
+ const headers = {
492
+ relaNo: this.relaNo,
493
+ };
494
+ request({
495
+ url: this.url + str,
496
+ method: "GET",
497
+ cache: true,
498
+ headers,
499
+ }).then((res) => {
500
+ let data = res.fundTreeVoList;
501
+ this.loading = false;
502
+ if (data && data.length > 0) {
503
+ data.forEach((d) => {
504
+ d.isLeaf = !Boolean(d.hasChild);
505
+ });
506
+ }
507
+ if (["0", "1", "6"].includes(queryType)) {
508
+ //树赋值
509
+ this.data = data;
510
+ if (["1", "6"].includes(queryType)) {
511
+ //查询过全部,就关闭懒加载
512
+ this.$refs.tree.$refs.tree.store.lazy = false;
513
+ this.hasQueryAll = true;
514
+ this.$nextTick(() => {
515
+ if (this.selectData.length > 0) {
516
+ //去除没有权限的单位
517
+ this.selectData = this.selectData.filter((s) => {
518
+ return !s.disabled;
519
+ });
520
+ this.$refs.tree.setCheckedNodes(this.selectData);
521
+ }
522
+ });
523
+ }
524
+ if (dataT.expandFlag) {
525
+ //筛选时,将展开单位传入
526
+ dataT.resolve(res.firstAuthUnit);
527
+ } else {
528
+ if (res.onlyUnit) {
529
+ //如果只有一家单位的权限时,默认勾选
530
+ this.onlyUnit = true;
531
+ this.data = [res.onlyUnit];
532
+ this.selectData = [res.onlyUnit];
533
+ this.$refs.tree.setCheckedNodes(this.selectData);
534
+ let cdata = this.selectData.map((s) => s.unitNo);
535
+ this.valueShow = this.selectData.map((s) => s.unitName);
536
+ this.$emit("input", this.multiple ? cdata : cdata[0]);
537
+ // this.$emit("input", cdata);
538
+ this.$emit("dataChange", this.selectData);
539
+ } else {
540
+ dataT.resolve(data);
541
+ }
542
+ }
543
+ }
544
+ if (queryType == "2" && dataT) {
545
+ if (dataT.type && dataT.type == "direct") {
546
+ //查询直接下级,并勾选,抛到方法里面去做
547
+ dataT.resolve(data);
548
+ } else {
549
+ //节点懒加载展开,只更新直属子节点
550
+ dataT.resolve(data);
551
+ //更新子节点后根据选择的数据,确定节点选择状态
552
+ // 传递的defaultSelect和upDateValue没有id,需要在加载时,重新对选择数据赋值
553
+ this.selectData.forEach((s, i) => {
554
+ data.forEach((d) => {
555
+ if (s.unitNo == d.unitNo) {
556
+ this.selectData[i] = d;
557
+ }
558
+ });
559
+ });
560
+ this.$nextTick(() => {
561
+ if (this.selectData.length > 0) {
562
+ //去除没有权限的单位
563
+ this.selectData = this.selectData.filter((s) => {
564
+ return !s.disabled;
565
+ });
566
+ this.$refs.tree.setCheckedNodes(this.selectData);
567
+ }
568
+ });
569
+ return;
570
+ }
571
+ }
572
+ if (queryType == "4" && dataT) {
573
+ //兄弟节点
574
+ dataT.resolve(data);
575
+ return;
576
+ }
577
+ if (queryType == "3" && dataT) {
578
+ //所有下级节点
579
+ dataT.resolve(data);
580
+ return;
581
+ }
582
+ });
583
+ },
584
+ debounce(fn, delay) {
585
+ let context = this;
586
+ clearTimeout(context.timer);
587
+ context.timer = setTimeout(() => {
588
+ fn.apply(context);
589
+ }, delay);
590
+ },
591
+ searchTree(type) {
592
+ if (this.isList) {
593
+ if (!type) {
594
+ this.selectData = [];
595
+ }
596
+ this.checkD = false;
597
+ this.$refs.tree.setCheckedNodes([]);
598
+ this.getListData("search");
599
+ } else {
600
+ //搜索取消所有选中状态
601
+ this.checkD = false;
602
+ if (!type) {
603
+ this.selectData = [];
604
+ }
605
+ this.$refs.tree.setCheckedNodes([]);
606
+ new Promise((resolve) => {
607
+ if (this.searchUnitNo) {
608
+ //指定单位编号的搜索
609
+ this.getTreeData("6", {
610
+ unitNo: this.searchUnitNo,
611
+ resolve,
612
+ expandFlag: true,
613
+ });
614
+ } else {
615
+ this.getTreeData("1", { resolve, expandFlag: true });
616
+ }
617
+ }).then((data) => {
618
+ if (data) {
619
+ //默认展开节点
620
+ this.defaultExpandedKeys = [data.id];
621
+ }
622
+ });
623
+ }
624
+ },
625
+ filterSearchTree() {
626
+ if (this.isList) {
627
+ this.selectData = [];
628
+ this.checkD = false;
629
+ this.$refs.tree.setCheckedNodes([]);
630
+ this.getListData("search");
631
+ } else {
632
+ //搜索取消所有选中状态
633
+ this.checkD = false;
634
+ this.selectData = [];
635
+ this.$refs.tree.setCheckedNodes([]);
636
+ new Promise((resolve) => {
637
+ this.getTreeData("1", { resolve, expandFlag: true });
638
+ }).then((data) => {
639
+ // if (data) {
640
+ // //默认展开节点
641
+ // this.defaultExpandedKeys = [data.id];
642
+ // }
643
+ this.checkD = true;
644
+ this.selectData = JSON.parse(JSON.stringify(this.data));
645
+ this.valueShow = this.$t("common_a_0003");
646
+ this.$nextTick(() => {
647
+ console.log(11111, this.selectData);
648
+ this.$refs.tree.setCheckedNodes(this.selectData);
649
+ });
650
+ });
651
+ }
652
+ },
653
+ outClick() {
654
+ // this.cancel()
655
+ },
656
+ clearFn() {
657
+ this.checkD = false;
658
+ this.selectData = [];
659
+ this.valueShow = [];
660
+ this.$refs.tree.setCheckedNodes([]);
661
+ this.$emit("input", this.multiple ? [] : "");
662
+ this.$emit("dataChange", this.selectData,'clear');
663
+ },
664
+ loadNode(node, resolve) {
665
+ //懒加载,查询子节点
666
+ this.getTreeData("2", { unitNo: node.data.unitNo, resolve: resolve });
667
+ },
668
+ check(data, { checkedKeys }) {
669
+ // let checkData = [...this.valueC]
670
+ if (checkedKeys.includes(data.id)) {
671
+ // this.valueShow.push(data.unitName)
672
+ this.selectData.push(data);
673
+ let hash = {};
674
+ let temp = [];
675
+ this.selectData.forEach((s) => {
676
+ //去重
677
+ if (!hash[s.unitNo + ""]) {
678
+ hash[s.unitNo + ""] = true;
679
+ temp.push(s);
680
+ }
681
+ });
682
+ this.selectData = temp;
683
+ // checkData.push(data.unitNo)
684
+ } else {
685
+ let temp = this.selectData.filter((s) => s.unitNo != data.unitNo);
686
+ this.selectData = temp;
687
+ // this.valueShow = temp.map(t => t.unitName)
688
+ // checkData = temp.map(t => t.unitNo)
689
+ }
690
+ // this.$emit('input', checkData)
691
+ },
692
+ showOpt(flag) {
693
+ this.$refs.tree.showDropMenu = null;
694
+ if (flag) {
695
+ // this.init();
696
+ //打开时暂存选择的节点
697
+ this.selectDataCache = JSON.parse(JSON.stringify(this.selectData));
698
+ } else {
699
+ //关闭时清空暂存
700
+ this.selectDataCache = [];
701
+ if (this.searchKey) {
702
+ this.searchKey = "";
703
+ this.searchTree("cache");
704
+ }
705
+ }
706
+ },
707
+ getUnitTree(type) {
708
+ new Promise((resolve) => {
709
+ this.getTreeData("6", { unitNo: this.searchUnitNo, resolve: resolve });
710
+ }).then(() => {
711
+ });
712
+ },
713
+ handleCheckBox(key) {
714
+ // debugger
715
+ if (key) {
716
+ //全选时,需要先查全部数据
717
+ if (!this.hasQueryAll) {
718
+ if (this.isList) {
719
+ return;
720
+ }
721
+ new Promise((resolve) => {
722
+ this.getTreeData("1", { resolve });
723
+ }).then(() => {
724
+ this.$nextTick(() => {
725
+ let temp = [];
726
+ this.flatData(this.data, temp);
727
+ //默认全选时,选中数据
728
+ //去除没有权限的单位
729
+ temp = temp.filter((s) => {
730
+ return !s.disabled;
731
+ });
732
+ this.$refs.tree.setCheckedNodes(temp);
733
+ this.selectData = temp;
734
+ // let s = temp.map((t) => {
735
+ // return t.unitNo;
736
+ // });
737
+ this.valueShow = temp.map((t) => {
738
+ return t.unitName;
739
+ });
740
+ this.$emit("dataChange", this.selectData);
741
+ });
742
+ });
743
+ } else {
744
+ let temp = [];
745
+ this.flatData(this.data, temp);
746
+ //去除没有权限的单位
747
+ temp = temp.filter((s) => {
748
+ return !s.disabled;
749
+ });
750
+ this.$refs.tree.setCheckedNodes(temp);
751
+ // const data = this.$refs.tree.getCheckedKeys()
752
+ this.selectData = temp;
753
+ // let s = temp.map((t) => {
754
+ // return t.unitNo;
755
+ // });
756
+ this.valueShow = temp.map((t) => {
757
+ return t.unitName;
758
+ });
759
+ this.$emit("dataChange", this.selectData);
760
+ // this.$emit('input', s)
761
+ }
762
+ } else {
763
+ this.$refs.tree.setCheckedNodes([]);
764
+ this.selectData = [];
765
+ // this.valueShow = []
766
+ // this.$emit('input', [])
767
+ // this.$message.warning(this.$t("common_a_0005"));
768
+ }
769
+ },
770
+ checkedBro(data) {
771
+ this.$refs.selectTreeUnit.handleClose(false);
772
+ new Promise((resolve) => {
773
+ this.getTreeData("4", { unitNo: data.unitNo, resolve });
774
+ }).then((bro) => {
775
+ this.selectData = this.selectData.concat(bro);
776
+ let hash = {};
777
+ let temp = [];
778
+ this.selectData.forEach((s) => {
779
+ //去重
780
+ if (!hash[s.unitNo + ""]) {
781
+ hash[s.unitNo + ""] = true;
782
+ temp.push(s);
783
+ }
784
+ });
785
+ this.selectData = temp;
786
+ //去除没有权限的单位
787
+ this.selectData = this.selectData.filter((s) => {
788
+ return !s.disabled;
789
+ });
790
+ this.$refs.tree.setCheckedNodes(this.selectData);
791
+ const data = this.$refs.tree.getCheckedKeys();
792
+ // this.$emit('input', data)
793
+ });
794
+ },
795
+ checkedChild(obj) {
796
+ this.$refs.selectTreeUnit.handleClose(false);
797
+ if (obj.type === "cancel") {
798
+ //取消勾选所有下级
799
+ new Promise((resolve) => {
800
+ this.getTreeData("3", { unitNo: obj.data.unitNo, resolve });
801
+ }).then((child) => {
802
+ if (!child || child.length < 1) {
803
+ return "end";
804
+ }
805
+ let temp1 = [];
806
+ this.flatData(child, temp1);
807
+ let ids = temp1.map((t) => t.id);
808
+ this.selectData = this.selectData.filter((s) => {
809
+ return !ids.includes(s.id);
810
+ });
811
+ this.$refs.tree.setCheckedNodes(this.selectData);
812
+ // const data = this.$refs.tree.getCheckedKeys()
813
+ // this.$emit('input', data)
814
+ });
815
+ } else if (obj.type == "all") {
816
+ //所有下级未完成开发todo
817
+ //勾选所有下级单位时,会先请求所有数据,取消懒加载模式,再请求对应的下级单位数据再勾选(包括已经勾选的数据)
818
+ new Promise((resolve) => {
819
+ this.getTreeData("3", { unitNo: obj.data.unitNo, resolve });
820
+ }).then((child) => {
821
+ if (!child || child.length < 1) {
822
+ return "end";
823
+ }
824
+ let temp1 = [];
825
+ this.flatData(child, temp1);
826
+ this.selectData = this.selectData.concat(temp1);
827
+ let hash = {};
828
+ let temp = [];
829
+ this.selectData.forEach((s) => {
830
+ //去重
831
+ if (!hash[s.unitNo + ""]) {
832
+ hash[s.unitNo + ""] = true;
833
+ temp.push(s);
834
+ }
835
+ });
836
+ this.selectData = temp;
837
+ //去除没有权限的单位
838
+ this.selectData = this.selectData.filter((s) => {
839
+ return !s.disabled;
840
+ });
841
+ this.$refs.tree.setCheckedNodes(this.selectData);
842
+ // const data = this.$refs.tree.getCheckedKeys()
843
+ // this.$emit('input', data)
844
+ });
845
+ } else {
846
+ // 勾选直接下级
847
+ new Promise((resolve) => {
848
+ this.getTreeData("2", {
849
+ unitNo: obj.data.unitNo,
850
+ resolve,
851
+ type: "direct",
852
+ });
853
+ }).then((child) => {
854
+ if (!child || child.length < 1) {
855
+ return "end";
856
+ }
857
+ let temp1 = [];
858
+ this.flatData(child, temp1);
859
+ this.selectData = this.selectData.concat(temp1);
860
+ let hash = {};
861
+ let temp = [];
862
+ this.selectData.forEach((s) => {
863
+ //去重
864
+ if (!hash[s.unitNo + ""]) {
865
+ hash[s.unitNo + ""] = true;
866
+ temp.push(s);
867
+ }
868
+ });
869
+ this.selectData = temp;
870
+ //去除没有权限的单位
871
+ this.selectData = this.selectData.filter((s) => {
872
+ return !s.disabled;
873
+ });
874
+ this.$refs.tree.setCheckedNodes(this.selectData);
875
+ // const data = this.$refs.tree.getCheckedKeys()
876
+ // this.$emit('input', data)
877
+ });
878
+ }
879
+ },
880
+ confirm() {
881
+ if (this.selectData.length < 1) {
882
+ this.$message.warning(this.$t("common_a_0005"));
883
+ return;
884
+ }
885
+ //去除没有权限的单位
886
+ this.selectData = this.selectData.filter((s) => {
887
+ return !s.disabled;
888
+ });
889
+ this.valueShow = this.selectData.map((s) => s.unitName);
890
+ let data = this.selectData.map((s) => s.unitNo);
891
+
892
+ this.$emit("input", this.multiple ? data : data[0]);
893
+ // this.$emit("input", data);
894
+ this.$emit("dataChange", this.selectData, "confirm");
895
+ this.$refs.selectTreeUnit.blur();
896
+ },
897
+ cancel() {
898
+ this.selectData = JSON.parse(JSON.stringify(this.selectDataCache));
899
+ //去除没有权限的单位
900
+ this.selectData = this.selectData.filter((s) => {
901
+ return !s.disabled;
902
+ });
903
+ this.$refs.tree.setCheckedNodes(this.selectData);
904
+ this.$refs.selectTreeUnit.blur();
905
+ },
906
+ flatData(arr, temp) {
907
+ arr.forEach((a) => {
908
+ temp.push(a);
909
+ if (
910
+ a &&
911
+ a.children &&
912
+ Array.isArray(a.children) &&
913
+ a.children.length > 0
914
+ ) {
915
+ this.flatData(a.children, temp);
916
+ }
917
+ });
918
+ },
919
+ nodeClick(data) {
920
+ this.$refs.tree.showDropMenu = null;
921
+ //单选才会进入
922
+ if (this.multiple) {
923
+ return;
924
+ }
925
+ if (!data.disabled) {
926
+ //有权限的单位才返回
927
+ this.selectData = [data];
928
+ this.valueShow = data.unitName;
929
+ this.$emit("input", data.unitNo);
930
+ this.$emit("dataChange", this.selectData, "click");
931
+ this.$refs.selectTreeUnit.blur();
932
+ }
933
+ },
934
+ upDateShowValue(flag) {
935
+ let isEqual =
936
+ JSON.stringify(this.selectData) === JSON.stringify(this.upDateValue);
937
+ // if(this.isList){
938
+ // //列表结构更新
939
+ // }else{
940
+ // //树结构更新
941
+
942
+ // }
943
+ if (this.upDateValue && Array.isArray(this.upDateValue) && !isEqual) {
944
+ //更新值和选择值不相等时才触发,避免使用的死循环
945
+ this.selectData = [...this.upDateValue];
946
+ let checkData = this.upDateValue.map((d) => {
947
+ return d.unitNo;
948
+ });
949
+ this.valueShow = this.upDateValue.map((d) => {
950
+ return d.unitName;
951
+ });
952
+ this.$emit("input", this.multiple ? checkData : checkData[0]);
953
+ this.$emit("dataChange", this.selectData);
954
+ }
955
+ if (flag) {
956
+ if (this.isList) {
957
+ // 列表模式
958
+ this.$refs.tree.setCheckedNodes([]);
959
+ this.$refs.tree.setCheckedNodes(this.selectData);
960
+ } else {
961
+ //传true时,会刷新整个树的状态,更新选择状态,有权限的单位才会选中
962
+ new Promise((resolve) => {
963
+ this.getTreeData("1", { resolve });
964
+ }).then(() => {
965
+ // 只加载顶级节点时,判断是否选择顶级节点
966
+ let temp = [];
967
+ const datas = [];
968
+ this.flatData(this.data, datas);
969
+ this.selectData.forEach((s, i) => {
970
+ datas.forEach((d) => {
971
+ if (d.unitNo == s.unitNo) {
972
+ temp.push(d);
973
+ this.selectData[i] = d; //传进来的单位没有id,将请求的数据节点,赋值给selectData
974
+ }
975
+ });
976
+ });
977
+ // this.selectData = temp;
978
+ //去除没有权限的单位
979
+ temp = temp.filter((s) => {
980
+ return !s.disabled;
981
+ });
982
+ this.$refs.tree.setCheckedNodes(temp);
983
+ });
984
+ }
985
+ }
986
+ },
987
+ async initList() {
988
+ await this.getListData();
989
+ },
990
+ async getListData(type) {
991
+ this.loading = true;
992
+ this.$refs.tree.store.lazy = false;
993
+ let params = {
994
+ current: this.page.current,
995
+ size: this.page.size,
996
+ ...this.seachObj,
997
+ ...this.searchParams,
998
+ data: {
999
+ ...this.seachObj,
1000
+ ...this.searchParams,
1001
+ moduleNo: this.moduleNo,
1002
+ isUnitDataScope: this.isUnitDataScope,
1003
+ unitNameOrNoLike: this.searchKey,
1004
+ },
1005
+ };
1006
+ // if(type=="search"){
1007
+ // params.data.unitNameOrNoLike =
1008
+ // }
1009
+ const headers = {
1010
+ relaNo: this.relaNo,
1011
+ };
1012
+ let res = await request({
1013
+ url: this.listUrl,
1014
+ method: "POST",
1015
+ data: params,
1016
+ headers,
1017
+ cache: true,
1018
+ });
1019
+ this.loading = false;
1020
+ if (res.records && res.records.length > 0) {
1021
+ res.records.forEach((r) => {
1022
+ r.children = null;
1023
+ });
1024
+ this.data = res.records;
1025
+ } else {
1026
+ this.data = [];
1027
+ }
1028
+ //全选时的逻辑
1029
+ if (this.defaultSelectAll && !this.selectData.length) {
1030
+ let temp = JSON.parse(JSON.stringify(this.data));
1031
+ this.selectData = temp.filter((s) => {
1032
+ return !s.disabled;
1033
+ });
1034
+ this.setCheck(type);
1035
+ return;
1036
+ }
1037
+ this.setId();
1038
+ //去除没有权限的单位
1039
+ // this.selectData = this.selectData.filter((s) => {
1040
+ // return !s.disabled;
1041
+ // });
1042
+ if (this.selectFirst && !type) {
1043
+ //切换时不需要
1044
+ //初始化时没有传默认单位和all时,根据selectFirst 默认选择第一家单位
1045
+ if (this.selectData.length < 1 && this.data.length > 0) {
1046
+ this.selectData = [this.data[0]];
1047
+ }
1048
+ }
1049
+ this.setCheck(type);
1050
+ },
1051
+ setId() {
1052
+ //初始化设置时,传入进来的单位id可能不对,也可能不存在,用请求数据通过unitNo匹配重新设置选中数据
1053
+ this.selectData.forEach((s, i) => {
1054
+ this.data.forEach((d) => {
1055
+ if (d.unitNo == s.unitNo) {
1056
+ this.selectData[i] = d;
1057
+ }
1058
+ });
1059
+ });
1060
+ },
1061
+ setCheck(type) {
1062
+ this.valueShow = this.selectData.map((t) => {
1063
+ return t.unitName;
1064
+ });
1065
+ let data = this.selectData.map((s) => s.unitNo);
1066
+ if (!type) {
1067
+ this.$emit("input", this.multiple ? data : data[0]);
1068
+ this.$emit("dataChange", this.selectData);
1069
+ }
1070
+ this.$nextTick(() => {
1071
+ this.$refs.tree.setCheckedNodes(this.selectData);
1072
+ });
1073
+ this.$emit("loaded");
1074
+ },
1075
+ },
1076
+ };
1077
+ </script>
1078
+ <style scoped lang="scss">
1079
+ .nstc-unit-search ::v-deep .el-input__validateIcon {
1080
+ display: none !important;
1081
+ }
1082
+ </style>