@infly/ui 1.0.18 → 1.0.19

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