@infly/ui 1.0.18 → 1.0.20

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.
Files changed (34) hide show
  1. package/README.md +53 -43
  2. package/index.js +47 -33
  3. package/package.json +60 -29
  4. package/scripts/install-comp.js +13 -0
  5. package/src/Base/InflyCheckBox/InflyCheckBox.test.js +154 -0
  6. package/src/Base/InflyCheckBox/InflyCheckBox.vue +227 -0
  7. package/src/Base/InflyCheckBox/index.js +6 -0
  8. package/src/Base/InflyDialog/InflyDialog.test.js +122 -0
  9. package/src/Base/InflyDialog/InflyDialog.vue +111 -0
  10. package/src/Base/InflyDialog/index.js +6 -0
  11. package/src/Base/InflyForm/InflyForm.test.js +239 -0
  12. package/src/Base/InflyForm/InflyForm.vue +974 -0
  13. package/src/Base/InflyForm/index.js +6 -0
  14. package/src/Base/InflyInput/InflyInput.test.js +105 -0
  15. package/src/Base/InflyInput/InflyInput.vue +167 -0
  16. package/src/Base/InflyInput/index.js +6 -0
  17. package/src/Base/InflyList/InflyList.test.js +229 -0
  18. package/src/Base/InflyList/InflyList.vue +926 -0
  19. package/src/Base/InflyList/index.js +6 -0
  20. package/src/Business/BusinessSwitch/BusinessSwitch.test.js +250 -0
  21. package/src/Business/BusinessSwitch/BusinessSwitch.vue +115 -0
  22. package/src/Business/BusinessSwitch/index.js +6 -0
  23. package/src/Business/BusinessTag/BusinessTag.test.js +70 -0
  24. package/src/Business/BusinessTag/BusinessTag.vue +58 -0
  25. package/src/Business/BusinessTag/index.js +6 -0
  26. package/src/Business/InstitutionSelect/InstitutionSelect.test.js +281 -0
  27. package/src/Business/InstitutionSelect/InstitutionSelect.vue +768 -0
  28. package/src/Business/InstitutionSelect/index.js +6 -0
  29. package/src/utils/Uts.js +3 -0
  30. package/src/utils/ts-libs.test.js +31 -0
  31. package/styles/base.scss +755 -0
  32. package/styles/index.scss +202 -0
  33. package/styles/mixin.scss +19 -0
  34. package/styles/variables.scss +24 -0
@@ -0,0 +1,768 @@
1
+ <template>
2
+ <!-- packages\infly-ui\Business\InstitutionSelect\InstitutionSelect 选择机构弹窗-单选 -->
3
+ <div class="comp-InstitutionSelect">
4
+ <div class="institutions__select" v-if="showSelectBtn">
5
+ <!-- 单选模式:展示单个机构名称 -->
6
+ <span v-if="!showTableSelect && displayLevelName">
7
+ <span> {{ displayLevelName }} </span>
8
+ <i class="el-icon-delete text-danger btn--delete" @click="onDelete()"></i>
9
+ </span>
10
+ <el-button class="institutions__btn-select" type="primary" size="mini" plain @click="openModal()">{{
11
+ btnText
12
+ }}</el-button>
13
+ <!-- 多选模式:展示已选机构标签列表 -->
14
+ <div v-if="showTableSelect && Uts.notEmptyArray(selectedInsList) && !hideSelectedTags" class="selected-tags-wrap">
15
+ <el-tag
16
+ v-for="item in selectedInsList"
17
+ :key="item[IdKey]"
18
+ closable
19
+ size="small"
20
+ @close="delSingleSelectedItem(item)"
21
+ >
22
+ {{ levelNameRender(item) }}
23
+ </el-tag>
24
+ </div>
25
+ <template v-for="{ label, name, ...otherAttributes } in filterList">
26
+ <el-checkbox v-if="label" :key="name" v-model="formData[name]" v-bind="otherAttributes">
27
+ {{ label }}
28
+ </el-checkbox>
29
+ </template>
30
+ <!-- 显示选择数量提示 -->
31
+ <span v-if="showTableSelect && maxSelectCount > 0" class="text-info">
32
+ (已选 {{ selectedInsList.length }} / {{ maxSelectCount }})
33
+ </span>
34
+ <span v-else-if="!hideTips" class="text-info">{{ selectLevelTips }}</span>
35
+ </div>
36
+ <el-dialog
37
+ :title="title || label"
38
+ :visible.sync="modalVisible"
39
+ :before-close="closeModal"
40
+ :class="['institution__dialog', dialogClass]"
41
+ v-bind="dialogProps"
42
+ append-to-body
43
+ @open="beforeOpen()"
44
+ >
45
+ <el-form :model="insFormData" label-suffix=":" size="mini" :class="['institutions__filter-container']">
46
+ <template v-for="{ label, prop, type, isHide, tabs, showSearchBtn, tabClick } in insFilterList">
47
+ <el-form-item v-if="!isHide" :key="prop" v-bind="showFormFilter ? { label, 'label-width': '140px' } : {}">
48
+ <el-tabs v-if="type === 'el-tabs'" v-model="insFormData[prop]" type="card" @tab-click="tabClick">
49
+ <el-tab-pane
50
+ v-for="{ label, prop, name, level } in tabs"
51
+ :label="label"
52
+ :name="level || name || prop"
53
+ :key="prop || name"
54
+ >
55
+ {{ label }}
56
+ </el-tab-pane>
57
+ </el-tabs>
58
+ <el-input
59
+ v-if="type === 'el-input'"
60
+ v-model="insFormData[prop]"
61
+ :class="['institutions__search', searchClass]"
62
+ :placeholder="searchPlacholder"
63
+ size="mini"
64
+ clearable
65
+ @keyup.native.enter="getList(1)"
66
+ />
67
+ <el-button
68
+ v-if="showSearchBtn"
69
+ :class="['btn--search', searchBtnClass]"
70
+ icon="el-icon-search"
71
+ size="mini"
72
+ type="primary"
73
+ plain
74
+ @click="getList(1)"
75
+ >搜索</el-button
76
+ >
77
+ </el-form-item>
78
+ </template>
79
+ </el-form>
80
+ <div class="institutions__body">
81
+ <div class="institutions__wrap">
82
+ <div v-if="showTableSelect" class="infly__bold">
83
+ <span>选择机构列表</span>
84
+ <el-divider></el-divider>
85
+ </div>
86
+ <el-table
87
+ ref="institutionsTable"
88
+ :class="['institutions__table']"
89
+ :data="dataList"
90
+ :row-key="IdKey"
91
+ v-bind="tableProps"
92
+ v-loading="showTableLoading"
93
+ stripe
94
+ @selection-change="handleSelectionChange"
95
+ @select="handleSelect"
96
+ @select-all="handleSelectAll"
97
+ >
98
+ <el-table-column v-if="showTableSelect" type="selection" width="55" :reserve-selection="true" />
99
+ <el-table-column
100
+ v-for="{ prop, label, width, showOverflowTooltip, type, change } in columns"
101
+ :key="prop"
102
+ :label="label"
103
+ :width="width"
104
+ :show-overflow-tooltip="showOverflowTooltip"
105
+ >
106
+ <template slot-scope="{ row }">
107
+ <el-radio
108
+ v-if="type === 'radio' && !showTableSelect"
109
+ v-model="insideLevelId"
110
+ :label="row[IdKey]"
111
+ @change="change(row)"
112
+ >
113
+ {{ row[IdKey] }}
114
+ </el-radio>
115
+ <span v-else> {{ row[prop] }}</span>
116
+ </template>
117
+ </el-table-column>
118
+ </el-table>
119
+ </div>
120
+ <div v-if="showTableSelect" class="institutions__wrap--selected">
121
+ <div v-if="showTableSelect" class="infly__bold">
122
+ <span>已选择机构列表</span>
123
+ <el-divider></el-divider>
124
+ </div>
125
+ <el-table :data="selectedInsList" v-bind="tableProps">
126
+ <el-table-column
127
+ v-for="{ prop, label, width, showOverflowTooltip, type, buttonList } in selectColumns"
128
+ :key="prop"
129
+ :label="label"
130
+ :width="width"
131
+ :show-overflow-tooltip="showOverflowTooltip"
132
+ >
133
+ <template slot-scope="{ row }">
134
+ <template v-if="type === 'el-button'">
135
+ <el-button
136
+ v-for="(btnItem, index) in buttonList"
137
+ :key="index"
138
+ :type="btnItem.type"
139
+ @click="btnItem.click(row)"
140
+ >
141
+ <span :class="['btn__text', btnItem.className]">{{
142
+ Uts.isFunction(btnItem.name) ? btnItem.name(row) : btnItem.name
143
+ }}</span>
144
+ </el-button>
145
+ </template>
146
+ <span v-else-if="prop === 'level_name'">{{ levelNameRender(row) }}</span>
147
+ <span v-else> {{ row[prop] }}</span>
148
+ </template>
149
+ </el-table-column>
150
+ </el-table>
151
+ </div>
152
+ </div>
153
+ <el-pagination
154
+ layout="total,prev, pager, next"
155
+ :total="pageData.counts"
156
+ :current-page.sync="pageData.page"
157
+ @current-change="getList"
158
+ />
159
+ <span slot="footer">
160
+ <el-button size="mini" @click="closeModal()">取 消</el-button>
161
+ <el-button size="mini" type="primary" :loading="btn_loading" @click="onConfirm()">确 定</el-button>
162
+ </span>
163
+ </el-dialog>
164
+ </div>
165
+ </template>
166
+
167
+ <script>
168
+ import { mapGetters } from "vuex";
169
+ import Uts from "../../utils/Uts.js";
170
+
171
+ export default {
172
+ name: "InstitutionSelect",
173
+ inheritAttrs: false,
174
+ props: {
175
+ // v-model 绑定值
176
+ value: { type: [String, Number, Array], default: () => "" },
177
+
178
+ // 数据 / 配置
179
+ formData: { type: Object, default: () => ({}) },
180
+ name: { type: String, default: "level_id" },
181
+ levelId: { type: [String, Number], default: "" },
182
+ IdKey: { type: String, default: "id" },
183
+ levelNameKey: { type: String, default: "level_name" },
184
+
185
+ // 传参配置
186
+ filterList: { type: Array, default: () => [] },
187
+ merchantId: { type: String, default: "" },
188
+ source: { type: String, default: "" },
189
+ activity_id: { type: String, default: "" }, //活动id-派发明细需要过滤对应的机构(支付宝/微信代金券)
190
+ cash_activity_id: { type: String, default: "" }, //活动id-派发明细需要过滤对应的机构(微邮惠礼包)
191
+ reqModule: { type: String, default: "admin" },
192
+ reqUrl: { type: String, default: "" },
193
+ request: { type: Function, default: null },
194
+ levelTypes: { type: [String, Number], default: "" },
195
+ limitEmptySelected: { type: Boolean, default: false },
196
+ orgType: { type: [String, Number], default: "" },
197
+
198
+ // UI 配置
199
+ hideTips: { type: Boolean, default: false },
200
+ showSelectBtn: { type: Boolean, default: true },
201
+ btn_loading: { type: Boolean, default: false },
202
+ dialogVisible: { type: Boolean, default: false },
203
+ onOff: { type: Boolean, default: false }, // 外部传入参数控制弹窗显示(兼容旧逻辑,语义不明确,不建议使用)
204
+ title: { type: String, default: "选择机构" },
205
+ label: { type: String, default: "选择机构" },
206
+ dialogClass: { type: String, default: "" },
207
+ searchClass: { type: String, default: "" },
208
+ searchBtnClass: { type: String, default: "" },
209
+ searchPlacholder: { type: String, default: "请输入机构名称" },
210
+ btnText: { type: String, default: "选 择" },
211
+ showTableSelect: { type: Boolean, default: false },
212
+ hideSelectedTags: { type: Boolean, default: false },
213
+ maxSelectCount: { type: Number, default: 0 }, // 最多可选中的机构数量,0 表示不限制
214
+ showFormFilter: { type: Boolean, default: false },
215
+ showTabsFilter: { type: Boolean, default: false },
216
+ selectLevelTips: { type: String, default: "(不选默认全部机构)" },
217
+
218
+ // 表格配置
219
+ tableProps: {
220
+ type: Object,
221
+ default: () => ({
222
+ height: "400px",
223
+ size: "mini"
224
+ })
225
+ },
226
+
227
+ // 弹窗配置
228
+ dialogProps: {
229
+ type: Object,
230
+ default: () => ({
231
+ width: "800px"
232
+ })
233
+ },
234
+
235
+ // 处理函数
236
+ dealRes: { type: Function, default: () => {} }
237
+ },
238
+ data() {
239
+ // 获取初始值(支持数组和单个值)
240
+ const initialValue = this.value || this.formData[this.name];
241
+ const initialList = Array.isArray(initialValue) ? initialValue : [];
242
+
243
+ return {
244
+ insideLevelId: this.value || this.levelId || this.formData[this.name] || "",
245
+ selectedInsItem: {},
246
+ selectedInsList: initialList,
247
+ selectedInsMap: new Map(), // 使用 Map 存储所有已选中的机构,key: 机构ID, value: 机构数据
248
+ dataList: [],
249
+ pageData: {},
250
+ levelName: this.formData[this.levelNameKey] || "",
251
+ showTableLoading: false,
252
+ isShowModal: false,
253
+ hasInitialized: false, // 标记是否已经初始化过选中状态
254
+ insFormData: {
255
+ level_type: "0",
256
+ search: ""
257
+ }
258
+ };
259
+ },
260
+ watch: {
261
+ value: {
262
+ immediate: true,
263
+ handler(val) {
264
+ if (this.showTableSelect && Array.isArray(val)) {
265
+ // 多选模式:更新选中列表
266
+ this.selectedInsList = val;
267
+ this.initializeSelectedMap(val);
268
+ } else if (!this.showTableSelect && val) {
269
+ // 单选模式
270
+ this.insideLevelId = val;
271
+ } else {
272
+ this.insideLevelId = "";
273
+ }
274
+ }
275
+ }
276
+ },
277
+ computed: {
278
+ ...mapGetters(["user"]),
279
+ modalVisible() {
280
+ return this.isShowModal || this.dialogVisible || this.onOff;
281
+ },
282
+ displayLevelName() {
283
+ return this.levelName || this.formData[this.levelNameKey] || "";
284
+ },
285
+ insFilterList() {
286
+ return [
287
+ {
288
+ label: "机构类型",
289
+ prop: "level_type",
290
+ type: "el-tabs",
291
+ tabs: this.levelTabList,
292
+ isHide: !this.showTabsFilter,
293
+ tabClick: (tab) => this.getList(1, tab)
294
+ },
295
+ { label: "关键词", prop: "search", type: "el-input", showSearchBtn: true }
296
+ ];
297
+ },
298
+ levelTabList() {
299
+ const [levelNumber, ...levelTabs] = this.columns;
300
+ return [{ label: "全国", prop: "nationwide", level: "0" }, ...levelTabs];
301
+ },
302
+ columns() {
303
+ return [
304
+ { label: "机构号", type: "radio", prop: this.IdKey, change: this.updateSelectedINS },
305
+ { label: "省", prop: "prov_name", level: "1", width: 120, showOverflowTooltip: true },
306
+ { label: "市", prop: "city_name", level: "2", width: 120, showOverflowTooltip: true },
307
+ { label: "区/县", prop: "district_name", level: "3", showOverflowTooltip: true },
308
+ { label: "网点", prop: "branch_name", level: "4", showOverflowTooltip: true }
309
+ ];
310
+ },
311
+ selectColumns() {
312
+ return [
313
+ { label: "机构名称", prop: "level_name", width: 120, showOverflowTooltip: true },
314
+ {
315
+ label: "操作",
316
+ prop: "action",
317
+ type: "el-button",
318
+ buttonList: [
319
+ {
320
+ name: "删除",
321
+ type: "text",
322
+ className: "text-danger",
323
+ click: (row) => this.delSingleSelectedItem(row)
324
+ }
325
+ ]
326
+ }
327
+ ];
328
+ }
329
+ },
330
+ methods: {
331
+ levelNameRender(row) {
332
+ const { branch_name, district_name, city_name, prov_name } = row || {};
333
+ return branch_name || district_name || city_name || prov_name || row[this.IdKey];
334
+ },
335
+ resetFormData() {
336
+ this.levelName = "";
337
+ this.insideLevelId = "";
338
+ this.formData[this.levelNameKey] = "";
339
+ if (Uts.notEmptyObject(this.formData)) {
340
+ this.formData[this.name] = "";
341
+ }
342
+ },
343
+ beforeOpen() {
344
+ if (this.insideLevelId) {
345
+ this.getList(this.pageData.page);
346
+ } else {
347
+ this.selectedInsItem = {};
348
+ this.getList(1);
349
+ }
350
+ },
351
+ openModal() {
352
+ this.isShowModal = true;
353
+ },
354
+ closeModal() {
355
+ this.isShowModal = false;
356
+ this.$emit("close");
357
+ this.$emit("onClose");
358
+ },
359
+ resolveRequest() {
360
+ return this.request || this.$axios || null;
361
+ },
362
+ resolveReqUrl() {
363
+ return this.reqUrl || `/${this.reqModule}/level/`;
364
+ },
365
+ getList(page, tab) {
366
+ const { level_id: userLevelId } = this.user || {};
367
+ const { search, level_type } = this.insFormData || {};
368
+ const request = this.resolveRequest();
369
+ const reqUrl = this.resolveReqUrl();
370
+
371
+ if (!request || !Uts.isFunction(request.get)) {
372
+ const err = new Error("InstitutionSelect request is not configured");
373
+ this.$emit("request-error", err);
374
+ this.$message && this.$message.error && this.$message.error(err.message);
375
+ return;
376
+ }
377
+
378
+ const params = {
379
+ search,
380
+ page,
381
+ merchant_id: this.merchantId,
382
+ activity_id: this.activity_id, //活动id-派发明细需要过滤对应的机构(支付宝/微信代金券)
383
+ cash_activity_id: this.cash_activity_id, //活动id-派发明细需要过滤对应的机构(微邮惠礼包)
384
+ org_type: this.orgType, // 所属机构类型
385
+ level_type: this.levelTypes || (level_type == 0 ? null : level_type)
386
+ };
387
+
388
+ if (this.source === "institutions" && userLevelId) {
389
+ params.level = userLevelId;
390
+ }
391
+
392
+ this.showTableLoading = true;
393
+
394
+ request
395
+ .get(reqUrl, { params })
396
+ .then((res) => {
397
+ this.dealRes(res);
398
+ const { lists, ...pageData } = res || {};
399
+ this.pageData = pageData || {};
400
+ this.dataList = lists;
401
+
402
+ // 首次加载时,如果有初始值,需要初始化 Map
403
+ if (!this.hasInitialized && this.showTableSelect && this.selectedInsList.length > 0) {
404
+ this.initializeSelectedMapFromList(lists);
405
+ this.hasInitialized = true;
406
+ }
407
+
408
+ // 恢复当前页的选中状态
409
+ this.$nextTick(() => {
410
+ this.restoreSelection();
411
+ });
412
+ })
413
+ .catch((err) => {
414
+ this.$emit("request-error", err);
415
+ })
416
+ .finally(() => {
417
+ this.showTableLoading = false;
418
+ });
419
+ },
420
+
421
+ /**
422
+ * 从初始传入的数组初始化 Map(用于编辑模式)
423
+ * @param {Array} selectedList - 已选中的机构列表
424
+ */
425
+ initializeSelectedMap(selectedList) {
426
+ if (!Array.isArray(selectedList) || selectedList.length === 0) return;
427
+
428
+ this.selectedInsMap.clear();
429
+ selectedList.forEach((item) => {
430
+ const rowId = item[this.IdKey];
431
+
432
+ if (rowId) {
433
+ this.selectedInsMap.set(rowId, item);
434
+ }
435
+ });
436
+ },
437
+
438
+ /**
439
+ * 从列表数据中匹配并初始化 Map(当初始值只有ID时)
440
+ * @param {Array} lists - 当前页的列表数据
441
+ */
442
+ initializeSelectedMapFromList(lists) {
443
+ if (!Array.isArray(lists) || lists.length === 0) return;
444
+ const selectedIdKey = this.IdKey;
445
+
446
+ // 如果 selectedInsList 中的项只有 ID,需要从 lists 中找到完整数据
447
+ this.selectedInsList.forEach((selectedItem) => {
448
+ const selectedId = selectedItem[selectedIdKey] || selectedItem;
449
+
450
+ // 在当前页数据中查找匹配的完整数据
451
+ const fullDataItem = lists.find((item) => item[selectedIdKey] === selectedId);
452
+
453
+ if (fullDataItem) {
454
+ // 使用完整数据更新 Map
455
+ this.selectedInsMap.set(fullDataItem[selectedIdKey], fullDataItem);
456
+ } else if (typeof selectedItem === "object" && selectedItem[selectedIdKey]) {
457
+ // 如果列表中没有,但 selectedItem 本身是完整对象,直接使用
458
+ this.selectedInsMap.set(selectedItem[selectedIdKey], selectedItem);
459
+ }
460
+ });
461
+
462
+ // 更新 selectedInsList 为完整数据
463
+ this.selectedInsList = Array.from(this.selectedInsMap.values());
464
+ },
465
+
466
+ /**
467
+ * 恢复选中状态(切换分页时调用)
468
+ */
469
+ restoreSelection() {
470
+ if (!this.$refs.institutionsTable || !this.showTableSelect) return;
471
+
472
+ // 清空当前选中状态
473
+ this.$refs.institutionsTable.clearSelection();
474
+
475
+ // 根据 Map 中存储的数据恢复选中状态
476
+ this.dataList.forEach((row) => {
477
+ const rowId = row[this.IdKey];
478
+ if (this.selectedInsMap.has(rowId)) {
479
+ this.$refs.institutionsTable.toggleRowSelection(row, true);
480
+ }
481
+ });
482
+ },
483
+ updateSelectedINS(row) {
484
+ this.insideLevelId = row[this.IdKey];
485
+ this.selectedInsItem = row;
486
+ this.$emit("input", this.insideLevelId);
487
+ },
488
+ onConfirm() {
489
+ if (this.showTableSelect) {
490
+ // 多选模式
491
+ if (this.limitEmptySelected && this.selectedInsList.length === 0) {
492
+ this.$message.warning("请至少选择一个机构");
493
+ return false;
494
+ }
495
+
496
+ this.closeModal();
497
+ this.$emit("input", this.selectedInsList);
498
+ this.$emit("confirm", this.selectedInsList);
499
+ this.$emit("onConfirm", this.selectedInsList);
500
+ } else {
501
+ // 单选模式(原有逻辑)
502
+ const { branch_name, district_name, city_name, prov_name } = this.selectedInsItem || {};
503
+ const levelId = this.selectedInsItem[this.IdKey];
504
+
505
+ if (!Uts.notEmptyObject(this.selectedInsItem)) {
506
+ this.$message.warning("请选择一个机构");
507
+ return false;
508
+ }
509
+ //判断机构名称的最小级别;
510
+ this.levelName = branch_name || district_name || city_name || prov_name || levelId;
511
+
512
+ if (Uts.isObject(this.formData)) {
513
+ this.formData[this.name] = levelId;
514
+ }
515
+
516
+ this.closeModal();
517
+
518
+ this.$emit("input", levelId);
519
+ this.$emit("confirm", this.selectedInsItem);
520
+ this.$emit("onConfirm", this.selectedInsItem);
521
+ }
522
+ },
523
+ onDelete() {
524
+ this.closeModal();
525
+ this.resetFormData();
526
+
527
+ this.$emit("input", "");
528
+ this.$emit("onDelete", this.selectedInsItem);
529
+ },
530
+ handleSelectionChange(selection) {
531
+ // 更新已选列表(从 Map 中获取)
532
+ this.selectedInsList = Array.from(this.selectedInsMap.values());
533
+ },
534
+
535
+ /**
536
+ * 单行选择事件
537
+ */
538
+ handleSelect(selection, row) {
539
+ const rowId = row[this.IdKey];
540
+
541
+ // 判断是选中还是取消选中
542
+ const isSelected = selection.some((item) => item[this.IdKey] === rowId);
543
+
544
+ if (isSelected) {
545
+ // 检查是否超过最大选择数量
546
+ if (this.maxSelectCount > 0 && this.selectedInsMap.size >= this.maxSelectCount) {
547
+ this.$message.warning(`最多只能选择 ${this.maxSelectCount} 个机构`);
548
+ // 取消当前选中
549
+ this.$nextTick(() => {
550
+ this.$refs.institutionsTable.toggleRowSelection(row, false);
551
+ });
552
+ return;
553
+ }
554
+ // 添加到 Map 中
555
+ this.selectedInsMap.set(rowId, row);
556
+ } else {
557
+ // 从 Map 中移除
558
+ this.selectedInsMap.delete(rowId);
559
+ }
560
+
561
+ // 更新已选列表
562
+ this.selectedInsList = Array.from(this.selectedInsMap.values());
563
+ },
564
+
565
+ /**
566
+ * 全选/取消全选事件
567
+ */
568
+ handleSelectAll(selection) {
569
+ if (selection.length > 0) {
570
+ // 检查是否超过最大选择数量
571
+ if (this.maxSelectCount > 0) {
572
+ const remainingSlots = this.maxSelectCount - this.selectedInsMap.size;
573
+
574
+ if (remainingSlots <= 0) {
575
+ this.$message.warning(`最多只能选择 ${this.maxSelectCount} 个机构`);
576
+ // 取消所有选中
577
+ this.$nextTick(() => {
578
+ this.$refs.institutionsTable.clearSelection();
579
+ this.restoreSelection();
580
+ });
581
+ return;
582
+ }
583
+
584
+ // 只选择允许的数量
585
+ let addedCount = 0;
586
+ selection.forEach((row) => {
587
+ const rowId = row[this.IdKey];
588
+ if (!this.selectedInsMap.has(rowId) && addedCount < remainingSlots) {
589
+ this.selectedInsMap.set(rowId, row);
590
+ addedCount++;
591
+ }
592
+ });
593
+
594
+ if (addedCount < selection.length) {
595
+ this.$message.warning(`已达到最大选择数量 ${this.maxSelectCount},仅添加了 ${addedCount} 个机构`);
596
+ // 恢复选中状态
597
+ this.$nextTick(() => {
598
+ this.restoreSelection();
599
+ });
600
+ }
601
+ } else {
602
+ // 无限制,全选:将当前页所有数据添加到 Map
603
+ selection.forEach((row) => {
604
+ const rowId = row[this.IdKey];
605
+ this.selectedInsMap.set(rowId, row);
606
+ });
607
+ }
608
+ } else {
609
+ // 取消全选:从 Map 中移除当前页的所有数据
610
+ this.dataList.forEach((row) => {
611
+ const rowId = row[this.IdKey];
612
+ this.selectedInsMap.delete(rowId);
613
+ });
614
+ }
615
+
616
+ // 更新已选列表
617
+ this.selectedInsList = Array.from(this.selectedInsMap.values());
618
+ },
619
+ /**
620
+ * 删除单个已选项
621
+ */
622
+ delSingleSelectedItem(row) {
623
+ const rowId = row[this.IdKey];
624
+
625
+ // 从 Map 中删除
626
+ this.selectedInsMap.delete(rowId);
627
+
628
+ // 更新已选列表
629
+ this.selectedInsList = Array.from(this.selectedInsMap.values());
630
+
631
+ // 🔥 同步更新 v-model
632
+ this.$emit("input", this.selectedInsList);
633
+
634
+ // 如果当前页有这条数据,取消选中状态
635
+ this.$nextTick(() => {
636
+ const tableRow = this.dataList.find((item) => item[this.IdKey] === rowId);
637
+ if (tableRow && this.$refs.institutionsTable) {
638
+ this.$refs.institutionsTable.toggleRowSelection(tableRow, false);
639
+ }
640
+ });
641
+ }
642
+ }
643
+ };
644
+ </script>
645
+
646
+ <style scoped lang="scss">
647
+ .institutions__select {
648
+ display: flex;
649
+ align-items: center;
650
+ flex-wrap: wrap;
651
+ gap: 8px;
652
+
653
+ .selected-tags-wrap {
654
+ display: flex;
655
+ align-items: center;
656
+ flex-wrap: wrap;
657
+ flex-basis: 100%;
658
+ gap: 8px;
659
+ margin-right: 8px;
660
+ padding: 8px;
661
+ height: 100px;
662
+ overflow-y: scroll;
663
+ border: 1px solid #dcdfe6;
664
+ border-radius: 4px;
665
+ }
666
+
667
+ .institutions__btn-select {
668
+ margin-right: 8px;
669
+ }
670
+
671
+ .btn--delete {
672
+ margin: 0 10px;
673
+ cursor: pointer;
674
+ }
675
+ }
676
+
677
+ .institutions__filter-container {
678
+ margin-bottom: 20px;
679
+
680
+ .btn--search {
681
+ margin-left: 8px;
682
+ }
683
+
684
+ ::v-deep {
685
+ .el-tabs__header {
686
+ width: min-content;
687
+ margin-bottom: 0;
688
+ border-radius: 4px;
689
+ overflow: hidden;
690
+ }
691
+
692
+ .el-tabs__item {
693
+ height: 28px;
694
+ line-height: 28px;
695
+ border-bottom-right-radius: 4px;
696
+ }
697
+
698
+ .el-tabs__content {
699
+ display: none;
700
+ }
701
+ }
702
+ }
703
+
704
+ .institutions__body {
705
+ display: flex;
706
+ justify-content: center;
707
+ align-items: center;
708
+ width: 100%;
709
+
710
+ .institutions__wrap {
711
+ flex: 1;
712
+ }
713
+
714
+ .institutions__wrap--selected {
715
+ margin-left: 48px;
716
+ }
717
+
718
+ // 或者在父容器判断:当有两个表格时
719
+ &:has(.institutions__wrap--selected) {
720
+ .institutions__wrap {
721
+ // 左侧表格样式
722
+ flex: 1;
723
+ width: 75%;
724
+ }
725
+ }
726
+ }
727
+
728
+ .institution__dialog::v-deep {
729
+ margin-top: 15px;
730
+
731
+ .institutions__search {
732
+ width: 300px;
733
+ }
734
+
735
+ .el-table {
736
+ .cell {
737
+ min-height: 23px;
738
+ }
739
+
740
+ th {
741
+ &:first-child > .cell {
742
+ text-indent: 10px;
743
+ }
744
+
745
+ &:not(:first-child) > .cell {
746
+ text-align: center;
747
+ }
748
+ }
749
+
750
+ td:not(:first-child) > .cell {
751
+ text-align: center;
752
+ }
753
+
754
+ &::before {
755
+ background-color: #fff;
756
+ }
757
+ }
758
+
759
+ .el-radio {
760
+ position: absolute;
761
+ top: 0;
762
+ z-index: 50;
763
+ width: 800px;
764
+ height: 36px;
765
+ line-height: 36px;
766
+ }
767
+ }
768
+ </style>