@bit-sun/business-component 2.0.10 → 2.0.11

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