@bit-sun/business-component 2.0.30 → 2.0.32

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 (110) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +4 -4
  3. package/.gitlab-ci.yml +174 -174
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/components/Business/BsSulaQueryTable/index.d.ts +2 -0
  9. package/dist/components/Business/BsSulaQueryTable/setting.d.ts +59 -0
  10. package/dist/components/Business/BsSulaQueryTable/utils.d.ts +98 -0
  11. package/dist/components/Business/CommonAlert/index.d.ts +3 -0
  12. package/dist/components/Business/DetailPageWrapper/index.d.ts +9 -0
  13. package/dist/components/Business/DetailPageWrapper/utils.d.ts +9 -0
  14. package/dist/components/Business/HomePageWrapper/index.d.ts +3 -0
  15. package/dist/components/Business/columnSettingTable/index.d.ts +1 -0
  16. package/dist/components/Business/columnSettingTable/sulaSettingTable.d.ts +1 -0
  17. package/dist/index.esm.js +7600 -5489
  18. package/dist/index.js +7597 -5486
  19. package/docs/index.md +21 -21
  20. package/lib/assets/drag.svg +17 -17
  21. package/lib/assets/exportFail.svg +37 -37
  22. package/lib/assets/exportProcessing.svg +28 -28
  23. package/lib/assets/exportSuccess.svg +34 -34
  24. package/lib/assets/label_icon_bottom.svg +25 -25
  25. package/lib/assets/upExport.svg +22 -22
  26. package/package.json +69 -63
  27. package/src/assets/btn-delete.svg +30 -0
  28. package/src/assets/btn-edit.svg +20 -0
  29. package/src/assets/btn-more.svg +18 -0
  30. package/src/assets/btn-submit.svg +20 -0
  31. package/src/assets/close.svg +26 -26
  32. package/src/assets/drag.svg +17 -17
  33. package/src/assets/exportFail.svg +37 -37
  34. package/src/assets/exportProcessing.svg +28 -28
  35. package/src/assets/exportSuccess.svg +34 -34
  36. package/src/assets/fixed-left-active.svg +12 -0
  37. package/src/assets/fixed-left.svg +16 -0
  38. package/src/assets/fixed-right-active.svg +12 -0
  39. package/src/assets/fixed-right.svg +16 -0
  40. package/src/assets/icon-quanping.svg +16 -0
  41. package/src/assets/icon-shezhi.svg +17 -17
  42. package/src/assets/label_icon_bottom.svg +25 -25
  43. package/src/assets/scanning.svg +25 -0
  44. package/src/assets/upExport.svg +22 -22
  45. package/src/components/Business/AddSelectBusiness/index.md +41 -41
  46. package/src/components/Business/AddSelectBusiness/index.tsx +290 -290
  47. package/src/components/Business/BsSulaQueryTable/index.less +220 -0
  48. package/src/components/Business/BsSulaQueryTable/index.tsx +534 -0
  49. package/src/components/Business/BsSulaQueryTable/setting.tsx +817 -0
  50. package/src/components/Business/BsSulaQueryTable/utils.less +65 -0
  51. package/src/components/Business/BsSulaQueryTable/utils.tsx +690 -0
  52. package/src/components/Business/CommodityEntry/index.md +70 -70
  53. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  54. package/src/components/Business/CommonAlert/index.less +0 -0
  55. package/src/components/Business/CommonAlert/index.tsx +23 -0
  56. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  57. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  58. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  59. package/src/components/Business/DetailPageWrapper/index.less +80 -0
  60. package/src/components/Business/DetailPageWrapper/index.tsx +325 -0
  61. package/src/components/Business/DetailPageWrapper/utils.tsx +111 -0
  62. package/src/components/Business/HomePageWrapper/index.less +33 -0
  63. package/src/components/Business/HomePageWrapper/index.md +45 -0
  64. package/src/components/Business/HomePageWrapper/index.tsx +150 -0
  65. package/src/components/Business/SearchSelect/BusinessUtils.ts +1448 -1448
  66. package/src/components/Business/SearchSelect/common.ts +53 -53
  67. package/src/components/Business/SearchSelect/index.md +1137 -1137
  68. package/src/components/Business/SearchSelect/index.tsx +51 -51
  69. package/src/components/Business/SearchSelect/utils.ts +99 -99
  70. package/src/components/Business/StateFlow/index.less +130 -130
  71. package/src/components/Business/StateFlow/index.md +60 -60
  72. package/src/components/Business/StateFlow/index.tsx +29 -29
  73. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  74. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  75. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  76. package/src/components/Business/columnSettingTable/columnSetting.tsx +762 -594
  77. package/src/components/Business/columnSettingTable/index.less +247 -247
  78. package/src/components/Business/columnSettingTable/index.md +357 -357
  79. package/src/components/Business/columnSettingTable/index.tsx +225 -216
  80. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +233 -224
  81. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  82. package/src/components/Functional/AddSelect/index.less +367 -367
  83. package/src/components/Functional/AddSelect/index.md +122 -122
  84. package/src/components/Functional/AddSelect/index.tsx +962 -952
  85. package/src/components/Functional/BillEntry/index.less +371 -371
  86. package/src/components/Functional/BillEntry/index.md +37 -37
  87. package/src/components/Functional/BillEntry/index.tsx +547 -547
  88. package/src/components/Functional/DataImport/index.less +63 -63
  89. package/src/components/Functional/DataImport/index.md +44 -44
  90. package/src/components/Functional/DataImport/index.tsx +689 -689
  91. package/src/components/Functional/DataValidation/index.less +63 -63
  92. package/src/components/Functional/DataValidation/index.md +38 -38
  93. package/src/components/Functional/DataValidation/index.tsx +681 -681
  94. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  95. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  96. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  97. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  98. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  99. package/src/components/Functional/SearchSelect/index.less +115 -115
  100. package/src/components/Functional/SearchSelect/index.md +141 -141
  101. package/src/components/Functional/SearchSelect/index.tsx +812 -812
  102. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  103. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  104. package/src/index.ts +30 -27
  105. package/src/utils/CheckOneUser/index.md +39 -39
  106. package/src/utils/CheckOneUser/index.ts +51 -51
  107. package/src/utils/requestUtils.ts +32 -32
  108. package/src/utils/utils.ts +22 -22
  109. package/tsconfig.json +29 -29
  110. package/typings.d.ts +4 -4
@@ -1,812 +1,812 @@
1
- // @ts-nocheck
2
- import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
- import { useDebounceFn } from 'ahooks';
4
- import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
- import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
6
- import axios from 'axios';
7
- import { stringify } from 'querystring';
8
- import _ from "lodash"
9
- import './index.less';
10
- import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
-
12
- const { Option } = Select;
13
-
14
- const SearchSelect = forwardRef((props: any, ref: any) => {
15
- const {
16
- value, // 必传
17
- onChange,
18
- selectProps = {},
19
- modalTableProps = {},
20
- labelInValue = false,
21
- requestConfig,
22
- ctx,
23
- sourceName,
24
- needModalTable = true,
25
- getPopupContainer = undefined,
26
- fieldComponent,
27
- } = props;
28
- const {
29
- url,
30
- otherParams,// 默认参数
31
- isMap,
32
- fixedparameter,
33
- fieldValToParam,
34
- mappingTextField = 'name',
35
- mappingTextShowKeyField,
36
- mappingValueField = 'code',
37
- mappingTextShowTextField,
38
- init = true,// 是否初始请求
39
- extralHeaders = {},// 额外请求头参数
40
- } = requestConfig || {};
41
- const resultSourceKey = sourceName || requestConfig?.sourceName || 'supplierCode'
42
-
43
- const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
44
- const initVal = value || (selectMode ? [] : null);
45
- const pageSize = 100 // 下拉框默认分页 条数
46
- const tableInitPageSize = 10 // 弹框默认分页 条数
47
- const currentPage = 1
48
- const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
49
- const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
50
- const currentSelectProps = {
51
- ...selectProps,
52
- // 以下属性不可更改----设计配置项
53
- showSearch: false,
54
- filterOption: false,
55
- allowClear: true,
56
- listHeight: 160,
57
- optionLabelProp: "label",
58
- autoClearSearchValue: false
59
- }
60
-
61
- const [items, setItems] = useState([]);
62
- const [scrollPage, setScrollPage] = useState(1);
63
- const [itemsTotal, setItemsTotal] = useState(0);
64
- const [fetching, setFetching] = useState(false);
65
- const [searchValue, setSearchValue] = useState('');
66
- const [isModalVisible, setIsModalVisible] = useState(false);
67
- const [popvalue, setPopValue] = useState(initVal);
68
- const [uniqueValue, setUniqueValue] = useState(sourceName)
69
- const { run } = useDebounceFn(
70
- (v?: any) => {
71
- // 优化搜索参数 支持传多个
72
- let searchParams = {};
73
- if (typeof selectParamsKey === 'string') {
74
- let selectParamsInitValue = initVal
75
- if (labelInValue) {
76
- selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
77
- } else {
78
- selectParamsInitValue = Array.isArray(initVal) ? initVal.join(',') : initVal
79
- }
80
- searchParams = v ? { [selectParamsInitKey]: selectParamsInitValue } : { [selectParamsKey]: searchValue }
81
- }
82
- if (Array.isArray(selectParamsKey)) {
83
- selectParamsKey.forEach((i: any) => {
84
- searchParams = { ...searchParams, [i]: searchValue }
85
- })
86
- }
87
- // 防抖函数 待定
88
- getData(searchParams)
89
- },
90
- {
91
- wait: 1000,
92
- },
93
- );
94
-
95
- const [form] = Form.useForm();
96
- const [caretLeftFlag, setCaretLeftFlag] = useState(true);
97
- const [tableData, setTableData] = useState([]);
98
- const [tablePagination, setTablePagination] = useState({ showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize })
99
- const [selectedRowKeys, setSelectedRowKeys] = useState([]);
100
- const [doubleArr, setDoubleArr] = useState([]); // 存放双数组的数组
101
- const [checkedAll, setCheckedAll] = useState(false)
102
- const [indeterminate, setIndeterminate] = useState(false)
103
- const [tableFormParams, setTableFormParams] = useState({});
104
- const [tooltipVisible, setTooltipVisible] = useState(false);
105
-
106
- useImperativeHandle(ref, () => ({
107
- refreshDataSource: (reset: boolean = false) => {
108
- if (reset) {
109
- if (init) {
110
- run('init');
111
- } else {
112
- setItems([]);
113
- setItemsTotal(0);
114
- }
115
- } else {
116
- run();
117
- }
118
- },
119
- clearDataSource: () => {
120
- setItems([]);
121
- setItemsTotal(0);
122
- },
123
- getTableFormRef: () => form,
124
- }))
125
-
126
- // 获取数据源 (type: 1下拉框 2弹框 不传值默认为下拉框)
127
- const getData = (params = {}, type = 1) => {
128
- if (!requestConfig) return;
129
-
130
- setFetching(true)
131
-
132
- // 处理dependence参数
133
- const fixedParam = {};
134
- if (fixedparameter && fieldValToParam && ctx) {
135
- fixedparameter.forEach((item: any, index: any) => {
136
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
137
- if (fixedParamVal) {
138
- fixedParam[item] = fixedParamVal;
139
- form.setFieldsValue({ ...form?.getFieldsValue(), [item]: fixedParamVal })
140
- }
141
- });
142
- }
143
-
144
- // 数组对象处理,对带有特殊标记的name进行处理
145
- for (const key in params) {
146
- if (Object.prototype.hasOwnProperty.call(params, key)) {
147
- const element = params[key];
148
- if (element && key.indexOf('*number*') >= 0) {
149
- const dataParams = key.split('*number*');
150
- dataParams.forEach((value, index) => {
151
- params[value] = element[index];
152
- });
153
- delete params[key];
154
- } else if (element && key.indexOf('*address*') >= 0) {
155
- const dataParams = key.split('*address*');
156
- dataParams.forEach((value, index) => {
157
- params[value] = element.PCDCode[index];
158
- });
159
- delete params[key];
160
- } else if (element && key.indexOf('*costType*') >= 0) {
161
- const dataParams = key.split('*costType*');
162
- // eslint-disable-next-line prefer-destructuring
163
- params[dataParams[0]] = element[1];
164
- delete params[key];
165
- } else if (element && key.indexOf('*fullDate*') >= 0) {
166
- const dataParams = key.split('*fullDate*');
167
- dataParams.forEach((value, index) => {
168
- if (index === 0) {
169
- params[value] = moment(element[index])
170
- .millisecond(0)
171
- .second(0)
172
- .minute(0)
173
- .hour(0)
174
- .format('YYYY-MM-DD HH:mm:ss');
175
- } else {
176
- params[value] = moment(element[index])
177
- .millisecond(59)
178
- .second(59)
179
- .minute(59)
180
- .hour(23)
181
- .format('YYYY-MM-DD HH:mm:ss');
182
- }
183
- });
184
- delete params[key];
185
- } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
186
- const dataParams = key.split('*checkBox*');
187
- if (element) {
188
- params[dataParams[0]] = 0
189
- }
190
- delete params[key];
191
- } else if (element && key.indexOf('*cascader*') >= 0) {
192
- const dataParams = key.split('*cascader*');
193
- params[dataParams[0]] = element[element.length - 1]
194
- delete params[key];
195
- } else if (element && key.indexOf('*date*') >= 0) {
196
- const dataParams = key.split('*date*')
197
- dataParams.forEach((value, index) => {
198
- if (index === 0) {
199
- params[value] = moment(element[index])
200
- .format('YYYY-MM-DD');
201
- } else {
202
- params[value] = moment(element[index])
203
- .format('YYYY-MM-DD');
204
- }
205
- });
206
- delete params[key];
207
- }
208
- else if (element && key.indexOf('*') >= 0) {
209
- const dataParams = key.split('*');
210
- dataParams.forEach((value, index) => {
211
- params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
212
- });
213
- delete params[key];
214
- } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
215
- const dataParams = key.split('_selectNumberRange')[0]
216
- if (params[key][0] === 'range') {
217
- if (params[key][1][0]) {
218
- params[`qp-${dataParams}-ge`] = params[key][1][0]
219
- }
220
- if (params[key][1][1]) {
221
- params[`qp-${dataParams}-le`] = params[key][1][1]
222
- }
223
- } else {
224
- params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
225
- }
226
- delete params[key]
227
- } else if (Array.isArray(element)) {
228
- params[key] = element.join(',');
229
- } else if (element == null || element === undefined || String(element).trim() === '') {
230
- delete params[key]
231
- }
232
- }
233
- }
234
-
235
- const queryParams = {
236
- pageSize,
237
- currentPage,
238
- ...otherParams, // 默认参数
239
- ...fixedParam,
240
- ...params,
241
- }
242
-
243
- axios
244
- .get(
245
- `${url}?${stringify(queryParams)}`,
246
- {
247
- headers: { ...extralHeaders }
248
- })
249
- .then((result: any) => {
250
- setFetching(false)
251
- result = result.data;
252
- if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
253
- message.error(result.msg);
254
- return;
255
- }
256
- const res = result.data;
257
- let source = [];
258
- if (isMap) {
259
- source = Object.keys(res).map((d, i) => {
260
- return {
261
- text: Object.values(res)[i],
262
- value: d,
263
- };
264
- });
265
- } else {
266
- const keys = res.list ? 'list' : 'items';
267
- source = res
268
- ? res[keys]
269
- ? res[keys].map((item: any) => {
270
- let textShowText = item[mappingTextField]
271
- if (mappingTextShowTextField) {
272
- textShowText = []
273
- if (Array.isArray(mappingTextShowTextField)) {
274
- mappingTextShowTextField.forEach((r: any) => {
275
- textShowText.push(item[r])
276
- })
277
- } else {
278
- textShowText = item[mappingTextShowTextField]
279
- }
280
- }
281
- return {
282
- ...item,
283
- text: item[mappingTextField],
284
- textShowText,
285
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
286
- value: item[mappingValueField],
287
- };
288
- })
289
- : Array.isArray(res) &&
290
- res?.map((item: Record<string, any>) => {
291
- let textShowText = item[mappingTextField]
292
- if (mappingTextShowTextField) {
293
- textShowText = []
294
- if (Array.isArray(mappingTextShowTextField)) {
295
- mappingTextShowTextField.forEach((r: any) => {
296
- textShowText.push(item[r])
297
- })
298
- } else {
299
- textShowText = item[mappingTextShowTextField]
300
- }
301
- }
302
- return {
303
- ...item,
304
- text: item[mappingTextField],
305
- textShowText,
306
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
307
- value: item[mappingValueField],
308
- };
309
- })
310
- : [];
311
- }
312
- source = Array.isArray(source) ? source : []
313
- if (type === 1) {
314
- ctx?.form?.setFieldSource(resultSourceKey, source)
315
- setItems(source)
316
- setItemsTotal(Number(res?.total || res?.totalCount || source.length))
317
- } else {
318
- setTableData(source)
319
- setTablePagination({ ...tablePagination, total: Number(res?.total || res?.totalCount || source.length), pageSize: Number(res?.size || res?.pageSize || (params?.pageSize || pageSize)), current: Number(res?.page || res?.currentPage || (params?.currentPage || currentPage)) })
320
- }
321
- })
322
- .catch((err) => { setFetching(false) });
323
- }
324
-
325
- const SelectScroll = e => {
326
- e.persist();
327
- const { target } = e;
328
- const totalPage = Math.ceil(itemsTotal / pageSize)
329
- // 判断是否滑动到底部
330
- const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
331
- // 判断数据是否还没有加载到了最后一页
332
- const canPageAdd = scrollPage < totalPage
333
- if (isTouchGround && canPageAdd) {
334
- const nextScrollPage = scrollPage + 1;
335
- setScrollPage(nextScrollPage);
336
- getData({ currentPage: nextScrollPage }); // 调用api方法
337
- }
338
-
339
- //判断是否滑动到顶部
340
- const isTouchTop = target.scrollTop === 0 // <=0
341
- // 判断数据是否到第一页
342
- const canPageJian = scrollPage > 1
343
- if (isTouchTop && canPageJian) {
344
- const preScrollPage = scrollPage - 1;
345
- setScrollPage(preScrollPage);
346
- getData({ currentPage: preScrollPage }); // 调用api方法
347
- }
348
- }
349
-
350
- useEffect(() => {
351
- if (init) {
352
- run('init')
353
- }
354
- }, [])
355
-
356
- useEffect(() => {
357
- if (value) {
358
- setPopValue(value);
359
- }
360
- }, [value]);
361
-
362
- useEffect(() => {
363
- makeUniqueValue();
364
- }, [sourceName])
365
-
366
- const showModal = () => {
367
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
368
- setIsModalVisible(true);
369
- // 回显
370
- if (value) {
371
- if (selectMode) {
372
- setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
373
- setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
374
- setIndeterminate(!!value.length && value.length < itemsTotal);
375
- setCheckedAll(itemsTotal && value.length === itemsTotal);
376
- // 需清空数据
377
- if (!value.length) {
378
- setDoubleArr([])
379
- }
380
- } else {
381
- setSelectedRowKeys(labelInValue ? [value.key] : [value])
382
- setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
383
- }
384
- }
385
- };
386
-
387
- const handleSelectOver = (selectedValue: any) => {
388
- if (selectedValue?.length) {
389
- formaData(selectedValue);
390
- // 解决选择最后1页的sku,返回后,不显示名称问题
391
- const source = _.uniqBy(items.concat(selectedValue), 'value')
392
- ctx?.form?.setFieldSource(resultSourceKey, source)
393
- setItems(source)
394
- }
395
- }
396
-
397
- const handleOk = () => {
398
- handleSelectOver(popvalue)
399
- handleCancel();
400
- };
401
-
402
- const formaData = (value) => {
403
- if (labelInValue) {
404
- const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
405
- onChange(selectMode ? formatResult : formatResult[0])
406
- } else {
407
- const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
408
- onChange(formatResult)
409
- }
410
- };
411
-
412
- const handleCancel = () => {
413
- form.resetFields();
414
- setTableFormParams({});
415
- setIsModalVisible(false);
416
- if (selectMode) {
417
- run();
418
- }
419
- };
420
-
421
- const refreshItems = () => {
422
- // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
423
- if (fieldValToParam && ctx) {
424
- let formValueList = [];
425
- fieldValToParam.forEach((item: any, index: any) => {
426
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
427
- formValueList.push(fixedParamVal);
428
- });
429
- if (formValueList.filter((item: any) => item).length > 0) {
430
- run();
431
- } else {
432
- setItems([]);
433
- setItemsTotal(0);
434
- }
435
- } else {
436
- run();
437
- }
438
- }
439
-
440
- const onSearchChange = (e) => {
441
- setSearchValue(e.target.value);
442
- refreshItems();
443
- }
444
-
445
- const onSearchBlur = () => {
446
- setSearchValue('');
447
- refreshItems();
448
- }
449
-
450
- const onSearchTable = () => {
451
- const params = form.getFieldsValue();
452
- setTableFormParams(params);
453
- getData({ ...params, pageSize: tableInitPageSize }, 2)
454
- if (selectMode) {
455
- getData(params)
456
- }
457
- }
458
-
459
- const onResetTable = () => {
460
- form.resetFields();
461
- setTableFormParams({});
462
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
463
- }
464
-
465
- const handleTableChange = (pagination) => {
466
- getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
467
- }
468
-
469
- const onChangeCheckAll = (e) => {
470
- if (e.target.checked) {
471
- // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
472
- // 如果超过100条 就默认查出所有数据
473
- const currentItemsData = JSON.parse(JSON.stringify(items))
474
- const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize)
475
- for (let i = 0; i <= totalPage - 1; i++) {
476
- doubleArr[i] = currentItemsData.slice(tablePagination?.pageSize * i, tablePagination?.pageSize * (i + 1))
477
- }
478
- setDoubleArr(doubleArr)
479
- setSelectedRowKeys(currentItemsData.map(i => i.value))
480
- setPopValue(currentItemsData);
481
- if (items.length < itemsTotal) {
482
- // TODO 请求接口获取所有数据
483
- }
484
- } else {
485
- setSelectedRowKeys([])
486
- setPopValue([]);
487
- setDoubleArr([])
488
- }
489
- setIndeterminate(false);
490
- setCheckedAll(e.target.checked);
491
- }
492
-
493
- const LightHeightOption = (props) => {
494
- const {
495
- filterTxt, text,
496
- } = props
497
- const heightLightTxt = (txt, heightTxt) => {
498
- if (heightTxt === '') {
499
- return txt
500
- }
501
- // 前面filterOption 不区分大小写,这里用i
502
- const regexp = new RegExp(heightTxt, 'gi')
503
- return txt.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
504
- }
505
- return (
506
- <Tooltip title={text}>
507
- <div ref={(nodeElement) => {
508
- if (nodeElement) {
509
- nodeElement.innerHTML = heightLightTxt(text, filterTxt)
510
- }
511
- }}
512
- />
513
- </Tooltip>
514
- )
515
- }
516
-
517
- // 扁平化二维数组的方法
518
- const mapRows = params => {
519
- var res = [];
520
- for (var i = 0; i < params.length; i++) {
521
- if (Array.isArray(params[i])) {
522
- // 去重
523
- res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
524
- } else {
525
- res.push(params[i]);
526
- // 去重
527
- res = _.uniqBy(res, 'value')
528
- }
529
- }
530
- return res.filter(Boolean); //去掉undefined的情况
531
- };
532
-
533
- const onChangeSelectedKeys = (selectKeys, selectRows) => {
534
- const nowPage = tablePagination?.current;
535
-
536
- let filterRows = []; // 存放拼接后的一维数组的变量
537
- let sksResult = [];
538
-
539
- if (selectMode) {
540
- // 处理多选分页累计选中
541
- // 勾选生成二维数组
542
- doubleArr[nowPage ? nowPage - 1 : 0] = selectRows
543
- // console.log(doubleArr)
544
- setDoubleArr(doubleArr)
545
- // 这块扁平化成为一位数组
546
- filterRows = mapRows(doubleArr);
547
- // console.log(filterRows)
548
-
549
- sksResult = filterRows.map((i) => i.value)
550
- } else {
551
- // 处理单选
552
- filterRows = selectRows;
553
- sksResult = selectRows.map((i) => i.value)
554
- // 单选直接选中 不需要确定
555
- handleSelectOver(filterRows)
556
- handleCancel();
557
- }
558
-
559
- setSelectedRowKeys(sksResult)
560
- setPopValue(filterRows);
561
- setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
562
- setCheckedAll(filterRows.length === tablePagination?.total);
563
- }
564
-
565
- // 生成唯一值
566
- const makeUniqueValue = () => {
567
- const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
568
- setUniqueValue(generateUnitKey);
569
- return generateUnitKey;
570
- }
571
-
572
- const rowSelection = {
573
- type: selectMode ? 'checkbox' : 'radio',
574
- selectedRowKeys,
575
- onChange: (sks, srs) => {
576
- onChangeSelectedKeys(sks, srs)
577
- },
578
- getCheckboxProps: () => {
579
- return ({
580
- disabled: selectProps?.disabled || props?.disabled || !items.length,
581
- })
582
- },
583
- };
584
-
585
- const onDoubleClickSelect = (e, record) => {
586
- if (!selectMode && !(selectProps?.disabled || props?.disabled || !items.length)) {
587
- const srs = [JSON.parse(JSON.stringify(record))]
588
- const sks = srs.map((i: any) => i.value)
589
- onChangeSelectedKeys(sks, srs)
590
- }
591
- }
592
-
593
- const themeColor = { color: '#1890ff' }
594
-
595
- const formItem = (list) => {
596
- if (isModalVisible && list?.length) {
597
- const setDisabled = (name: any) => {
598
- const { fixedparamsDisabled = false, fixedparameter = [] }: any = requestConfig;
599
- if (fixedparamsDisabled && fixedparameter.find((item: any) => item === name)) {
600
- return true
601
- } else {
602
- return false
603
- }
604
- };
605
- return list.map((i: any) => {
606
- if (i?.type === 'select' || i?.field?.type === 'select') {
607
- return (
608
- <Form.Item name={i.name} label={i.label} key={i.name}>
609
- <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}>
610
- {i?.initialSource?.length && i?.initialSource.map((m: any) => (
611
- <Option value={m.value} key={m.value}>{m.text}</Option>
612
- ))}
613
- </Select>
614
- </Form.Item>
615
- )
616
- }
617
-
618
- if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
619
- return (
620
- <Form.Item name={i.name} label={i.label} key={i.name}>
621
- <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></TreeSelect>
622
- </Form.Item>
623
- )
624
- }
625
-
626
- if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
627
- return (
628
- <div>
629
- <Form.Item name={i.name} label={i.label} key={i.name}>
630
- <BusinessSearchSelect {...i.field.props} disabled={setDisabled(i.name)} />
631
- </Form.Item>
632
- </div>
633
- )
634
- }
635
-
636
- if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
637
- return (
638
- <div>
639
- <Form.Item name={i.name} label={i.label} key={i.name}>
640
- <QueryMutipleInput onValueChange={(value) => {
641
- form.setFieldsValue({
642
- [i.name]: value
643
- })
644
- }} />
645
- </Form.Item>
646
- </div>
647
- );
648
- }
649
-
650
- // 默认type是input
651
- return (
652
- <Form.Item name={i.name} label={i.label} key={i.name}>
653
- <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} disabled={setDisabled(i.name)} />
654
- </Form.Item>
655
- )
656
- })
657
- } else {
658
- return null
659
- }
660
- }
661
-
662
- const maxTagPlaceholder = (selectedValues) => {
663
- const onClose = (e: any, item: any) => {
664
- e.preventDefault();
665
- const newValue = labelInValue ? JSON.parse(JSON.stringify(value)).filter((i: any) => i.value !== item.value) : JSON.parse(JSON.stringify(value)).filter((i: any) => i !== item.value)
666
- onChange(newValue);
667
- }
668
- return (
669
- <Tooltip title={selectedValues.map((i: any) => (
670
- <Tag
671
- closable={true}
672
- onClose={(e) => onClose(e, i)}
673
- style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
674
- >
675
- {i.label}
676
- </Tag>
677
- ))}>
678
- {`+ ${selectedValues?.length}`}
679
- </Tooltip>
680
- )
681
- }
682
-
683
- return (
684
- <div className={'search_select'}>
685
- {fieldComponent ?
686
- (<div onClick={() => {
687
- fieldComponent.props?.onClick?.()
688
- showModal()
689
- }}>{fieldComponent}</div>) :
690
- (<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
691
- <Select
692
- virtual
693
- labelInValue={labelInValue}
694
- value={value}
695
- onChange={onChange}
696
- disabled={props.disabled}
697
- dropdownRender={menu => (
698
- <>
699
- <Input
700
- value={searchValue}
701
- style={{ width: '98%', marginLeft: '1%' }}
702
- placeholder="请输入"
703
- onChange={e => onSearchChange(e)}
704
- onBlur={onSearchBlur}
705
- onKeyDown={(e) => {
706
- // 阻止多选的冒泡
707
- e.stopPropagation()
708
- }}
709
- />
710
- <Divider style={{ margin: '8px 0' }} />
711
- {menu}
712
- </>
713
- )}
714
- notFoundContent={
715
- fetching ? <Spin size="small" /> :
716
- <div style={{ textAlign: 'center' }}>
717
- <div style={{ marginBottom: 16 }}>
718
- <CopyOutlined style={{ fontSize: '50px' }} />
719
- </div>
720
- <div>无匹配结果,请更换其他内容再试</div>
721
- </div>
722
- }
723
- onPopupScroll={SelectScroll}
724
- style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
725
- placeholder="请选择"
726
- maxTagPlaceholder={maxTagPlaceholder}
727
- {...currentSelectProps}
728
- getPopupContainer={() => (getPopupContainer && getPopupContainer()) || document.getElementById(`search_select_div_${uniqueValue}`)}
729
- >
730
- {items.map(item => (
731
- <Option key={item.value} label={item.text}>
732
- {LightHeightOption({ text: `${item.textShowKey} ${Array.isArray(item.textShowText) && item.textShowText.join(' ') || item.textShowText}`, filterTxt: searchValue })}
733
- </Option>
734
- ))}
735
- </Select>
736
- {needModalTable && (
737
- <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
738
- <SearchOutlined />
739
- </Button>
740
- )}
741
- </div>)}
742
- {needModalTable && isModalVisible && (
743
- <Modal
744
- width='80%'
745
- title={modalTableProps?.modalTableTitle}
746
- visible={isModalVisible}
747
- onOk={handleOk}
748
- onCancel={handleCancel}
749
- footer={selectMode ? [
750
- <Button key="back" onClick={handleCancel}>
751
- 取消
752
- </Button>,
753
- <Button
754
- key="submit"
755
- type="primary"
756
- onClick={handleOk}
757
- disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
758
- >
759
- 确定
760
- </Button>,
761
- ] : null}
762
- >
763
- <div className={'search_select_wrapper'}>
764
- <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
765
- <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
766
- </div>
767
- <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
768
- <div className={'select_list_columns'}>
769
- <div className={'select_list_columns_tips'}>搜索</div>
770
- <div className={'select_list_columns_formItems'}>
771
- <Form form={form} layout='vertical' key='modalForm'>
772
- {formItem(modalTableProps?.tableSearchForm)}
773
- </Form>
774
- </div>
775
- </div>
776
- <div className={'select_list_searchButton'}>
777
- <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
778
- <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
779
- </div>
780
- </div>
781
- <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
782
- <div>
783
- <div className={'select_list_selectTips'}>
784
- <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
785
- <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
786
- </div>
787
- <Table
788
- size='small'
789
- rowSelection={rowSelection}
790
- columns={modalTableProps?.tableColumns}
791
- dataSource={tableData}
792
- pagination={tablePagination}
793
- onChange={handleTableChange}
794
- rowKey={mappingValueField}
795
- scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
796
- onRow={record => {
797
- return {
798
- onDoubleClick: event => onDoubleClickSelect(event, record),
799
- };
800
- }}
801
- />
802
- {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
803
- </div>
804
- </div>
805
- </div>
806
- </Modal>
807
- )}
808
- </div>
809
- );
810
- });
811
-
812
- export default SearchSelect;
1
+ // @ts-nocheck
2
+ import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
+ import { useDebounceFn } from 'ahooks';
4
+ import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
+ import { SearchOutlined, CopyOutlined, CaretLeftOutlined } from '@ant-design/icons';
6
+ import axios from 'axios';
7
+ import { stringify } from 'querystring';
8
+ import _ from "lodash"
9
+ import './index.less';
10
+ import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
+
12
+ const { Option } = Select;
13
+
14
+ const SearchSelect = forwardRef((props: any, ref: any) => {
15
+ const {
16
+ value, // 必传
17
+ onChange,
18
+ selectProps = {},
19
+ modalTableProps = {},
20
+ labelInValue = false,
21
+ requestConfig,
22
+ ctx,
23
+ sourceName,
24
+ needModalTable = true,
25
+ getPopupContainer = undefined,
26
+ fieldComponent,
27
+ } = props;
28
+ const {
29
+ url,
30
+ otherParams,// 默认参数
31
+ isMap,
32
+ fixedparameter,
33
+ fieldValToParam,
34
+ mappingTextField = 'name',
35
+ mappingTextShowKeyField,
36
+ mappingValueField = 'code',
37
+ mappingTextShowTextField,
38
+ init = true,// 是否初始请求
39
+ extralHeaders = {},// 额外请求头参数
40
+ } = requestConfig || {};
41
+ const resultSourceKey = sourceName || requestConfig?.sourceName || 'supplierCode'
42
+
43
+ const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
44
+ const initVal = value || (selectMode ? [] : null);
45
+ const pageSize = 100 // 下拉框默认分页 条数
46
+ const tableInitPageSize = 10 // 弹框默认分页 条数
47
+ const currentPage = 1
48
+ const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
49
+ const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
50
+ const currentSelectProps = {
51
+ ...selectProps,
52
+ // 以下属性不可更改----设计配置项
53
+ showSearch: false,
54
+ filterOption: false,
55
+ allowClear: true,
56
+ listHeight: 160,
57
+ optionLabelProp: "label",
58
+ autoClearSearchValue: false
59
+ }
60
+
61
+ const [items, setItems] = useState([]);
62
+ const [scrollPage, setScrollPage] = useState(1);
63
+ const [itemsTotal, setItemsTotal] = useState(0);
64
+ const [fetching, setFetching] = useState(false);
65
+ const [searchValue, setSearchValue] = useState('');
66
+ const [isModalVisible, setIsModalVisible] = useState(false);
67
+ const [popvalue, setPopValue] = useState(initVal);
68
+ const [uniqueValue, setUniqueValue] = useState(sourceName)
69
+ const { run } = useDebounceFn(
70
+ (v?: any) => {
71
+ // 优化搜索参数 支持传多个
72
+ let searchParams = {};
73
+ if (typeof selectParamsKey === 'string') {
74
+ let selectParamsInitValue = initVal
75
+ if (labelInValue) {
76
+ selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
77
+ } else {
78
+ selectParamsInitValue = Array.isArray(initVal) ? initVal.join(',') : initVal
79
+ }
80
+ searchParams = v ? { [selectParamsInitKey]: selectParamsInitValue } : { [selectParamsKey]: searchValue }
81
+ }
82
+ if (Array.isArray(selectParamsKey)) {
83
+ selectParamsKey.forEach((i: any) => {
84
+ searchParams = { ...searchParams, [i]: searchValue }
85
+ })
86
+ }
87
+ // 防抖函数 待定
88
+ getData(searchParams)
89
+ },
90
+ {
91
+ wait: 1000,
92
+ },
93
+ );
94
+
95
+ const [form] = Form.useForm();
96
+ const [caretLeftFlag, setCaretLeftFlag] = useState(true);
97
+ const [tableData, setTableData] = useState([]);
98
+ const [tablePagination, setTablePagination] = useState({ showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize })
99
+ const [selectedRowKeys, setSelectedRowKeys] = useState([]);
100
+ const [doubleArr, setDoubleArr] = useState([]); // 存放双数组的数组
101
+ const [checkedAll, setCheckedAll] = useState(false)
102
+ const [indeterminate, setIndeterminate] = useState(false)
103
+ const [tableFormParams, setTableFormParams] = useState({});
104
+ const [tooltipVisible, setTooltipVisible] = useState(false);
105
+
106
+ useImperativeHandle(ref, () => ({
107
+ refreshDataSource: (reset: boolean = false) => {
108
+ if (reset) {
109
+ if (init) {
110
+ run('init');
111
+ } else {
112
+ setItems([]);
113
+ setItemsTotal(0);
114
+ }
115
+ } else {
116
+ run();
117
+ }
118
+ },
119
+ clearDataSource: () => {
120
+ setItems([]);
121
+ setItemsTotal(0);
122
+ },
123
+ getTableFormRef: () => form,
124
+ }))
125
+
126
+ // 获取数据源 (type: 1下拉框 2弹框 不传值默认为下拉框)
127
+ const getData = (params = {}, type = 1) => {
128
+ if (!requestConfig) return;
129
+
130
+ setFetching(true)
131
+
132
+ // 处理dependence参数
133
+ const fixedParam = {};
134
+ if (fixedparameter && fieldValToParam && ctx) {
135
+ fixedparameter.forEach((item: any, index: any) => {
136
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
137
+ if (fixedParamVal) {
138
+ fixedParam[item] = fixedParamVal;
139
+ form.setFieldsValue({ ...form?.getFieldsValue(), [item]: fixedParamVal })
140
+ }
141
+ });
142
+ }
143
+
144
+ // 数组对象处理,对带有特殊标记的name进行处理
145
+ for (const key in params) {
146
+ if (Object.prototype.hasOwnProperty.call(params, key)) {
147
+ const element = params[key];
148
+ if (element && key.indexOf('*number*') >= 0) {
149
+ const dataParams = key.split('*number*');
150
+ dataParams.forEach((value, index) => {
151
+ params[value] = element[index];
152
+ });
153
+ delete params[key];
154
+ } else if (element && key.indexOf('*address*') >= 0) {
155
+ const dataParams = key.split('*address*');
156
+ dataParams.forEach((value, index) => {
157
+ params[value] = element.PCDCode[index];
158
+ });
159
+ delete params[key];
160
+ } else if (element && key.indexOf('*costType*') >= 0) {
161
+ const dataParams = key.split('*costType*');
162
+ // eslint-disable-next-line prefer-destructuring
163
+ params[dataParams[0]] = element[1];
164
+ delete params[key];
165
+ } else if (element && key.indexOf('*fullDate*') >= 0) {
166
+ const dataParams = key.split('*fullDate*');
167
+ dataParams.forEach((value, index) => {
168
+ if (index === 0) {
169
+ params[value] = moment(element[index])
170
+ .millisecond(0)
171
+ .second(0)
172
+ .minute(0)
173
+ .hour(0)
174
+ .format('YYYY-MM-DD HH:mm:ss');
175
+ } else {
176
+ params[value] = moment(element[index])
177
+ .millisecond(59)
178
+ .second(59)
179
+ .minute(59)
180
+ .hour(23)
181
+ .format('YYYY-MM-DD HH:mm:ss');
182
+ }
183
+ });
184
+ delete params[key];
185
+ } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
186
+ const dataParams = key.split('*checkBox*');
187
+ if (element) {
188
+ params[dataParams[0]] = 0
189
+ }
190
+ delete params[key];
191
+ } else if (element && key.indexOf('*cascader*') >= 0) {
192
+ const dataParams = key.split('*cascader*');
193
+ params[dataParams[0]] = element[element.length - 1]
194
+ delete params[key];
195
+ } else if (element && key.indexOf('*date*') >= 0) {
196
+ const dataParams = key.split('*date*')
197
+ dataParams.forEach((value, index) => {
198
+ if (index === 0) {
199
+ params[value] = moment(element[index])
200
+ .format('YYYY-MM-DD');
201
+ } else {
202
+ params[value] = moment(element[index])
203
+ .format('YYYY-MM-DD');
204
+ }
205
+ });
206
+ delete params[key];
207
+ }
208
+ else if (element && key.indexOf('*') >= 0) {
209
+ const dataParams = key.split('*');
210
+ dataParams.forEach((value, index) => {
211
+ params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
212
+ });
213
+ delete params[key];
214
+ } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
215
+ const dataParams = key.split('_selectNumberRange')[0]
216
+ if (params[key][0] === 'range') {
217
+ if (params[key][1][0]) {
218
+ params[`qp-${dataParams}-ge`] = params[key][1][0]
219
+ }
220
+ if (params[key][1][1]) {
221
+ params[`qp-${dataParams}-le`] = params[key][1][1]
222
+ }
223
+ } else {
224
+ params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
225
+ }
226
+ delete params[key]
227
+ } else if (Array.isArray(element)) {
228
+ params[key] = element.join(',');
229
+ } else if (element == null || element === undefined || String(element).trim() === '') {
230
+ delete params[key]
231
+ }
232
+ }
233
+ }
234
+
235
+ const queryParams = {
236
+ pageSize,
237
+ currentPage,
238
+ ...otherParams, // 默认参数
239
+ ...fixedParam,
240
+ ...params,
241
+ }
242
+
243
+ axios
244
+ .get(
245
+ `${url}?${stringify(queryParams)}`,
246
+ {
247
+ headers: { ...extralHeaders }
248
+ })
249
+ .then((result: any) => {
250
+ setFetching(false)
251
+ result = result.data;
252
+ if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
253
+ message.error(result.msg);
254
+ return;
255
+ }
256
+ const res = result.data;
257
+ let source = [];
258
+ if (isMap) {
259
+ source = Object.keys(res).map((d, i) => {
260
+ return {
261
+ text: Object.values(res)[i],
262
+ value: d,
263
+ };
264
+ });
265
+ } else {
266
+ const keys = res.list ? 'list' : 'items';
267
+ source = res
268
+ ? res[keys]
269
+ ? res[keys].map((item: any) => {
270
+ let textShowText = item[mappingTextField]
271
+ if (mappingTextShowTextField) {
272
+ textShowText = []
273
+ if (Array.isArray(mappingTextShowTextField)) {
274
+ mappingTextShowTextField.forEach((r: any) => {
275
+ textShowText.push(item[r])
276
+ })
277
+ } else {
278
+ textShowText = item[mappingTextShowTextField]
279
+ }
280
+ }
281
+ return {
282
+ ...item,
283
+ text: item[mappingTextField],
284
+ textShowText,
285
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
286
+ value: item[mappingValueField],
287
+ };
288
+ })
289
+ : Array.isArray(res) &&
290
+ res?.map((item: Record<string, any>) => {
291
+ let textShowText = item[mappingTextField]
292
+ if (mappingTextShowTextField) {
293
+ textShowText = []
294
+ if (Array.isArray(mappingTextShowTextField)) {
295
+ mappingTextShowTextField.forEach((r: any) => {
296
+ textShowText.push(item[r])
297
+ })
298
+ } else {
299
+ textShowText = item[mappingTextShowTextField]
300
+ }
301
+ }
302
+ return {
303
+ ...item,
304
+ text: item[mappingTextField],
305
+ textShowText,
306
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
307
+ value: item[mappingValueField],
308
+ };
309
+ })
310
+ : [];
311
+ }
312
+ source = Array.isArray(source) ? source : []
313
+ if (type === 1) {
314
+ ctx?.form?.setFieldSource(resultSourceKey, source)
315
+ setItems(source)
316
+ setItemsTotal(Number(res?.total || res?.totalCount || source.length))
317
+ } else {
318
+ setTableData(source)
319
+ setTablePagination({ ...tablePagination, total: Number(res?.total || res?.totalCount || source.length), pageSize: Number(res?.size || res?.pageSize || (params?.pageSize || pageSize)), current: Number(res?.page || res?.currentPage || (params?.currentPage || currentPage)) })
320
+ }
321
+ })
322
+ .catch((err) => { setFetching(false) });
323
+ }
324
+
325
+ const SelectScroll = e => {
326
+ e.persist();
327
+ const { target } = e;
328
+ const totalPage = Math.ceil(itemsTotal / pageSize)
329
+ // 判断是否滑动到底部
330
+ const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
331
+ // 判断数据是否还没有加载到了最后一页
332
+ const canPageAdd = scrollPage < totalPage
333
+ if (isTouchGround && canPageAdd) {
334
+ const nextScrollPage = scrollPage + 1;
335
+ setScrollPage(nextScrollPage);
336
+ getData({ currentPage: nextScrollPage }); // 调用api方法
337
+ }
338
+
339
+ //判断是否滑动到顶部
340
+ const isTouchTop = target.scrollTop === 0 // <=0
341
+ // 判断数据是否到第一页
342
+ const canPageJian = scrollPage > 1
343
+ if (isTouchTop && canPageJian) {
344
+ const preScrollPage = scrollPage - 1;
345
+ setScrollPage(preScrollPage);
346
+ getData({ currentPage: preScrollPage }); // 调用api方法
347
+ }
348
+ }
349
+
350
+ useEffect(() => {
351
+ if (init) {
352
+ run('init')
353
+ }
354
+ }, [])
355
+
356
+ useEffect(() => {
357
+ if (value) {
358
+ setPopValue(value);
359
+ }
360
+ }, [value]);
361
+
362
+ useEffect(() => {
363
+ makeUniqueValue();
364
+ }, [sourceName])
365
+
366
+ const showModal = () => {
367
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
368
+ setIsModalVisible(true);
369
+ // 回显
370
+ if (value) {
371
+ if (selectMode) {
372
+ setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
373
+ setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
374
+ setIndeterminate(!!value.length && value.length < itemsTotal);
375
+ setCheckedAll(itemsTotal && value.length === itemsTotal);
376
+ // 需清空数据
377
+ if (!value.length) {
378
+ setDoubleArr([])
379
+ }
380
+ } else {
381
+ setSelectedRowKeys(labelInValue ? [value.key] : [value])
382
+ setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
383
+ }
384
+ }
385
+ };
386
+
387
+ const handleSelectOver = (selectedValue: any) => {
388
+ if (selectedValue?.length) {
389
+ formaData(selectedValue);
390
+ // 解决选择最后1页的sku,返回后,不显示名称问题
391
+ const source = _.uniqBy(items.concat(selectedValue), 'value')
392
+ ctx?.form?.setFieldSource(resultSourceKey, source)
393
+ setItems(source)
394
+ }
395
+ }
396
+
397
+ const handleOk = () => {
398
+ handleSelectOver(popvalue)
399
+ handleCancel();
400
+ };
401
+
402
+ const formaData = (value) => {
403
+ if (labelInValue) {
404
+ const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
405
+ onChange(selectMode ? formatResult : formatResult[0])
406
+ } else {
407
+ const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
408
+ onChange(formatResult)
409
+ }
410
+ };
411
+
412
+ const handleCancel = () => {
413
+ form.resetFields();
414
+ setTableFormParams({});
415
+ setIsModalVisible(false);
416
+ if (selectMode) {
417
+ run();
418
+ }
419
+ };
420
+
421
+ const refreshItems = () => {
422
+ // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
423
+ if (fieldValToParam && ctx) {
424
+ let formValueList = [];
425
+ fieldValToParam.forEach((item: any, index: any) => {
426
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
427
+ formValueList.push(fixedParamVal);
428
+ });
429
+ if (formValueList.filter((item: any) => item).length > 0) {
430
+ run();
431
+ } else {
432
+ setItems([]);
433
+ setItemsTotal(0);
434
+ }
435
+ } else {
436
+ run();
437
+ }
438
+ }
439
+
440
+ const onSearchChange = (e) => {
441
+ setSearchValue(e.target.value);
442
+ refreshItems();
443
+ }
444
+
445
+ const onSearchBlur = () => {
446
+ setSearchValue('');
447
+ refreshItems();
448
+ }
449
+
450
+ const onSearchTable = () => {
451
+ const params = form.getFieldsValue();
452
+ setTableFormParams(params);
453
+ getData({ ...params, pageSize: tableInitPageSize }, 2)
454
+ if (selectMode) {
455
+ getData(params)
456
+ }
457
+ }
458
+
459
+ const onResetTable = () => {
460
+ form.resetFields();
461
+ setTableFormParams({});
462
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
463
+ }
464
+
465
+ const handleTableChange = (pagination) => {
466
+ getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
467
+ }
468
+
469
+ const onChangeCheckAll = (e) => {
470
+ if (e.target.checked) {
471
+ // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
472
+ // 如果超过100条 就默认查出所有数据
473
+ const currentItemsData = JSON.parse(JSON.stringify(items))
474
+ const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize)
475
+ for (let i = 0; i <= totalPage - 1; i++) {
476
+ doubleArr[i] = currentItemsData.slice(tablePagination?.pageSize * i, tablePagination?.pageSize * (i + 1))
477
+ }
478
+ setDoubleArr(doubleArr)
479
+ setSelectedRowKeys(currentItemsData.map(i => i.value))
480
+ setPopValue(currentItemsData);
481
+ if (items.length < itemsTotal) {
482
+ // TODO 请求接口获取所有数据
483
+ }
484
+ } else {
485
+ setSelectedRowKeys([])
486
+ setPopValue([]);
487
+ setDoubleArr([])
488
+ }
489
+ setIndeterminate(false);
490
+ setCheckedAll(e.target.checked);
491
+ }
492
+
493
+ const LightHeightOption = (props) => {
494
+ const {
495
+ filterTxt, text,
496
+ } = props
497
+ const heightLightTxt = (txt, heightTxt) => {
498
+ if (heightTxt === '') {
499
+ return txt
500
+ }
501
+ // 前面filterOption 不区分大小写,这里用i
502
+ const regexp = new RegExp(heightTxt, 'gi')
503
+ return txt.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
504
+ }
505
+ return (
506
+ <Tooltip title={text}>
507
+ <div ref={(nodeElement) => {
508
+ if (nodeElement) {
509
+ nodeElement.innerHTML = heightLightTxt(text, filterTxt)
510
+ }
511
+ }}
512
+ />
513
+ </Tooltip>
514
+ )
515
+ }
516
+
517
+ // 扁平化二维数组的方法
518
+ const mapRows = params => {
519
+ var res = [];
520
+ for (var i = 0; i < params.length; i++) {
521
+ if (Array.isArray(params[i])) {
522
+ // 去重
523
+ res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
524
+ } else {
525
+ res.push(params[i]);
526
+ // 去重
527
+ res = _.uniqBy(res, 'value')
528
+ }
529
+ }
530
+ return res.filter(Boolean); //去掉undefined的情况
531
+ };
532
+
533
+ const onChangeSelectedKeys = (selectKeys, selectRows) => {
534
+ const nowPage = tablePagination?.current;
535
+
536
+ let filterRows = []; // 存放拼接后的一维数组的变量
537
+ let sksResult = [];
538
+
539
+ if (selectMode) {
540
+ // 处理多选分页累计选中
541
+ // 勾选生成二维数组
542
+ doubleArr[nowPage ? nowPage - 1 : 0] = selectRows
543
+ // console.log(doubleArr)
544
+ setDoubleArr(doubleArr)
545
+ // 这块扁平化成为一位数组
546
+ filterRows = mapRows(doubleArr);
547
+ // console.log(filterRows)
548
+
549
+ sksResult = filterRows.map((i) => i.value)
550
+ } else {
551
+ // 处理单选
552
+ filterRows = selectRows;
553
+ sksResult = selectRows.map((i) => i.value)
554
+ // 单选直接选中 不需要确定
555
+ handleSelectOver(filterRows)
556
+ handleCancel();
557
+ }
558
+
559
+ setSelectedRowKeys(sksResult)
560
+ setPopValue(filterRows);
561
+ setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
562
+ setCheckedAll(filterRows.length === tablePagination?.total);
563
+ }
564
+
565
+ // 生成唯一值
566
+ const makeUniqueValue = () => {
567
+ const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
568
+ setUniqueValue(generateUnitKey);
569
+ return generateUnitKey;
570
+ }
571
+
572
+ const rowSelection = {
573
+ type: selectMode ? 'checkbox' : 'radio',
574
+ selectedRowKeys,
575
+ onChange: (sks, srs) => {
576
+ onChangeSelectedKeys(sks, srs)
577
+ },
578
+ getCheckboxProps: () => {
579
+ return ({
580
+ disabled: selectProps?.disabled || props?.disabled || !items.length,
581
+ })
582
+ },
583
+ };
584
+
585
+ const onDoubleClickSelect = (e, record) => {
586
+ if (!selectMode && !(selectProps?.disabled || props?.disabled || !items.length)) {
587
+ const srs = [JSON.parse(JSON.stringify(record))]
588
+ const sks = srs.map((i: any) => i.value)
589
+ onChangeSelectedKeys(sks, srs)
590
+ }
591
+ }
592
+
593
+ const themeColor = { color: '#1890ff' }
594
+
595
+ const formItem = (list) => {
596
+ if (isModalVisible && list?.length) {
597
+ const setDisabled = (name: any) => {
598
+ const { fixedparamsDisabled = false, fixedparameter = [] }: any = requestConfig;
599
+ if (fixedparamsDisabled && fixedparameter.find((item: any) => item === name)) {
600
+ return true
601
+ } else {
602
+ return false
603
+ }
604
+ };
605
+ return list.map((i: any) => {
606
+ if (i?.type === 'select' || i?.field?.type === 'select') {
607
+ return (
608
+ <Form.Item name={i.name} label={i.label} key={i.name}>
609
+ <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}>
610
+ {i?.initialSource?.length && i?.initialSource.map((m: any) => (
611
+ <Option value={m.value} key={m.value}>{m.text}</Option>
612
+ ))}
613
+ </Select>
614
+ </Form.Item>
615
+ )
616
+ }
617
+
618
+ if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
619
+ return (
620
+ <Form.Item name={i.name} label={i.label} key={i.name}>
621
+ <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></TreeSelect>
622
+ </Form.Item>
623
+ )
624
+ }
625
+
626
+ if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
627
+ return (
628
+ <div>
629
+ <Form.Item name={i.name} label={i.label} key={i.name}>
630
+ <BusinessSearchSelect {...i.field.props} disabled={setDisabled(i.name)} />
631
+ </Form.Item>
632
+ </div>
633
+ )
634
+ }
635
+
636
+ if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
637
+ return (
638
+ <div>
639
+ <Form.Item name={i.name} label={i.label} key={i.name}>
640
+ <QueryMutipleInput onValueChange={(value) => {
641
+ form.setFieldsValue({
642
+ [i.name]: value
643
+ })
644
+ }} />
645
+ </Form.Item>
646
+ </div>
647
+ );
648
+ }
649
+
650
+ // 默认type是input
651
+ return (
652
+ <Form.Item name={i.name} label={i.label} key={i.name}>
653
+ <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} disabled={setDisabled(i.name)} />
654
+ </Form.Item>
655
+ )
656
+ })
657
+ } else {
658
+ return null
659
+ }
660
+ }
661
+
662
+ const maxTagPlaceholder = (selectedValues) => {
663
+ const onClose = (e: any, item: any) => {
664
+ e.preventDefault();
665
+ const newValue = labelInValue ? JSON.parse(JSON.stringify(value)).filter((i: any) => i.value !== item.value) : JSON.parse(JSON.stringify(value)).filter((i: any) => i !== item.value)
666
+ onChange(newValue);
667
+ }
668
+ return (
669
+ <Tooltip title={selectedValues.map((i: any) => (
670
+ <Tag
671
+ closable={true}
672
+ onClose={(e) => onClose(e, i)}
673
+ style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
674
+ >
675
+ {i.label}
676
+ </Tag>
677
+ ))}>
678
+ {`+ ${selectedValues?.length}`}
679
+ </Tooltip>
680
+ )
681
+ }
682
+
683
+ return (
684
+ <div className={'search_select'}>
685
+ {fieldComponent ?
686
+ (<div onClick={() => {
687
+ fieldComponent.props?.onClick?.()
688
+ showModal()
689
+ }}>{fieldComponent}</div>) :
690
+ (<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
691
+ <Select
692
+ virtual
693
+ labelInValue={labelInValue}
694
+ value={value}
695
+ onChange={onChange}
696
+ disabled={props.disabled}
697
+ dropdownRender={menu => (
698
+ <>
699
+ <Input
700
+ value={searchValue}
701
+ style={{ width: '98%', marginLeft: '1%' }}
702
+ placeholder="请输入"
703
+ onChange={e => onSearchChange(e)}
704
+ onBlur={onSearchBlur}
705
+ onKeyDown={(e) => {
706
+ // 阻止多选的冒泡
707
+ e.stopPropagation()
708
+ }}
709
+ />
710
+ <Divider style={{ margin: '8px 0' }} />
711
+ {menu}
712
+ </>
713
+ )}
714
+ notFoundContent={
715
+ fetching ? <Spin size="small" /> :
716
+ <div style={{ textAlign: 'center' }}>
717
+ <div style={{ marginBottom: 16 }}>
718
+ <CopyOutlined style={{ fontSize: '50px' }} />
719
+ </div>
720
+ <div>无匹配结果,请更换其他内容再试</div>
721
+ </div>
722
+ }
723
+ onPopupScroll={SelectScroll}
724
+ style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
725
+ placeholder="请选择"
726
+ maxTagPlaceholder={maxTagPlaceholder}
727
+ {...currentSelectProps}
728
+ getPopupContainer={() => (getPopupContainer && getPopupContainer()) || document.getElementById(`search_select_div_${uniqueValue}`)}
729
+ >
730
+ {items.map(item => (
731
+ <Option key={item.value} label={item.text}>
732
+ {LightHeightOption({ text: `${item.textShowKey} ${Array.isArray(item.textShowText) && item.textShowText.join(' ') || item.textShowText}`, filterTxt: searchValue })}
733
+ </Option>
734
+ ))}
735
+ </Select>
736
+ {needModalTable && (
737
+ <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
738
+ <SearchOutlined />
739
+ </Button>
740
+ )}
741
+ </div>)}
742
+ {needModalTable && isModalVisible && (
743
+ <Modal
744
+ width='80%'
745
+ title={modalTableProps?.modalTableTitle}
746
+ visible={isModalVisible}
747
+ onOk={handleOk}
748
+ onCancel={handleCancel}
749
+ footer={selectMode ? [
750
+ <Button key="back" onClick={handleCancel}>
751
+ 取消
752
+ </Button>,
753
+ <Button
754
+ key="submit"
755
+ type="primary"
756
+ onClick={handleOk}
757
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
758
+ >
759
+ 确定
760
+ </Button>,
761
+ ] : null}
762
+ >
763
+ <div className={'search_select_wrapper'}>
764
+ <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
765
+ <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
766
+ </div>
767
+ <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
768
+ <div className={'select_list_columns'}>
769
+ <div className={'select_list_columns_tips'}>搜索</div>
770
+ <div className={'select_list_columns_formItems'}>
771
+ <Form form={form} layout='vertical' key='modalForm'>
772
+ {formItem(modalTableProps?.tableSearchForm)}
773
+ </Form>
774
+ </div>
775
+ </div>
776
+ <div className={'select_list_searchButton'}>
777
+ <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
778
+ <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
779
+ </div>
780
+ </div>
781
+ <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
782
+ <div>
783
+ <div className={'select_list_selectTips'}>
784
+ <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
785
+ <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
786
+ </div>
787
+ <Table
788
+ size='small'
789
+ rowSelection={rowSelection}
790
+ columns={modalTableProps?.tableColumns}
791
+ dataSource={tableData}
792
+ pagination={tablePagination}
793
+ onChange={handleTableChange}
794
+ rowKey={mappingValueField}
795
+ scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
796
+ onRow={record => {
797
+ return {
798
+ onDoubleClick: event => onDoubleClickSelect(event, record),
799
+ };
800
+ }}
801
+ />
802
+ {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
803
+ </div>
804
+ </div>
805
+ </div>
806
+ </Modal>
807
+ )}
808
+ </div>
809
+ );
810
+ });
811
+
812
+ export default SearchSelect;