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