@bit-sun/business-component 2.0.12 → 2.0.13

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 (68) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +4 -4
  3. package/.gitlab-ci.yml +174 -135
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -90
  7. package/README.md +27 -27
  8. package/dist/components/Business/SearchSelect/index.d.ts +1 -1
  9. package/dist/components/Functional/SearchSelect/index.d.ts +1 -2
  10. package/dist/index.d.ts +0 -1
  11. package/dist/index.esm.js +6794 -7350
  12. package/dist/index.js +6793 -7348
  13. package/docs/index.md +21 -21
  14. package/package.json +51 -60
  15. package/src/components/Business/AddSelectBusiness/index.md +41 -41
  16. package/src/components/Business/AddSelectBusiness/index.tsx +288 -300
  17. package/src/components/Business/CommodityEntry/index.md +69 -69
  18. package/src/components/Business/CommodityEntry/index.tsx +78 -78
  19. package/src/components/Business/SearchSelect/BusinessUtils.ts +1445 -1445
  20. package/src/components/Business/SearchSelect/common.ts +53 -53
  21. package/src/components/Business/SearchSelect/index.md +1137 -1136
  22. package/src/components/Business/SearchSelect/index.tsx +44 -49
  23. package/src/components/Business/SearchSelect/utils.ts +99 -99
  24. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  25. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  26. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  27. package/src/components/Functional/AddSelect/index.less +367 -352
  28. package/src/components/Functional/AddSelect/index.md +120 -120
  29. package/src/components/Functional/AddSelect/index.tsx +952 -896
  30. package/src/components/Functional/BillEntry/index.less +371 -371
  31. package/src/components/Functional/BillEntry/index.md +37 -37
  32. package/src/components/Functional/BillEntry/index.tsx +547 -561
  33. package/src/components/Functional/DataImport/index.less +63 -63
  34. package/src/components/Functional/DataImport/index.md +44 -44
  35. package/src/components/Functional/DataImport/index.tsx +689 -689
  36. package/src/components/Functional/DataValidation/index.less +63 -63
  37. package/src/components/Functional/DataValidation/index.md +38 -38
  38. package/src/components/Functional/DataValidation/index.tsx +680 -680
  39. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  40. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  41. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  42. package/src/components/Functional/SearchSelect/index.less +115 -115
  43. package/src/components/Functional/SearchSelect/index.md +141 -141
  44. package/src/components/Functional/SearchSelect/index.tsx +732 -791
  45. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  46. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  47. package/src/index.ts +22 -22
  48. package/src/utils/CheckOneUser/index.md +39 -39
  49. package/src/utils/CheckOneUser/index.ts +51 -51
  50. package/src/utils/requestUtils.ts +32 -32
  51. package/tsconfig.json +29 -29
  52. package/typings.d.ts +2 -2
  53. package/Dockerfile +0 -11
  54. package/dist/app.d.ts +0 -0
  55. package/dist/components/sulaQueryTable/BsSulaQueryTable.d.ts +0 -2
  56. package/dist/components/sulaQueryTable/draggableTable.d.ts +0 -22
  57. package/dist/components/sulaQueryTable/statusComponent.d.ts +0 -2
  58. package/dist/components/sulaQueryTable/utils.d.ts +0 -41
  59. package/nginx.conf +0 -43
  60. package/src/app.tsx +0 -3
  61. package/src/components/sulaQueryTable/BsSulaQueryTable.tsx +0 -368
  62. package/src/components/sulaQueryTable/draggableTable.tsx +0 -111
  63. package/src/components/sulaQueryTable/index.md +0 -271
  64. package/src/components/sulaQueryTable/status-component.less +0 -8
  65. package/src/components/sulaQueryTable/statusComponent.tsx +0 -42
  66. package/src/components/sulaQueryTable/utils.less +0 -48
  67. package/src/components/sulaQueryTable/utils.tsx +0 -336
  68. package/src/global.less +0 -97
@@ -1,791 +1,732 @@
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 refreshItems = () => {
414
- // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
415
- if (fieldValToParam && ctx) {
416
- let formValueList = [];
417
- fieldValToParam.forEach((item: any, index: any) => {
418
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
419
- formValueList.push(fixedParamVal);
420
- });
421
- if (formValueList.filter((item: any) => item).length > 0) {
422
- run();
423
- } else {
424
- setItems([]);
425
- setItemsTotal(0);
426
- }
427
- } else {
428
- run();
429
- }
430
- }
431
-
432
- const onSearchChange = (e) => {
433
- setSearchValue(e.target.value);
434
- refreshItems();
435
- }
436
-
437
- const onSearchBlur = () => {
438
- setSearchValue('');
439
- refreshItems();
440
- }
441
-
442
- const onSearchTable = () => {
443
- const params = form.getFieldsValue();
444
- setTableFormParams(params);
445
- getData({ ...params, pageSize: tableInitPageSize }, 2)
446
- if (selectMode) {
447
- getData(params)
448
- }
449
- }
450
-
451
- const onResetTable = () => {
452
- form.resetFields();
453
- setTableFormParams({});
454
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
455
- }
456
-
457
- const handleTableChange = (pagination) => {
458
- getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
459
- }
460
-
461
- const onChangeCheckAll = (e) => {
462
- if (e.target.checked) {
463
- // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
464
- // 如果超过100条 就默认查出所有数据
465
- const currentItemsData = JSON.parse(JSON.stringify(items))
466
- const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize)
467
- for (let i = 0; i <= totalPage - 1; i++) {
468
- doubleArr[i] = currentItemsData.slice(tablePagination?.pageSize * i, tablePagination?.pageSize * (i + 1))
469
- }
470
- setDoubleArr(doubleArr)
471
- setSelectedRowKeys(currentItemsData.map(i => i.value))
472
- setPopValue(currentItemsData);
473
- if (items.length < itemsTotal) {
474
- // TODO 请求接口获取所有数据
475
- }
476
- } else {
477
- setSelectedRowKeys([])
478
- setPopValue([]);
479
- setDoubleArr([])
480
- }
481
- setIndeterminate(false);
482
- setCheckedAll(e.target.checked);
483
- }
484
-
485
- const LightHeightOption = (props) => {
486
- const {
487
- filterTxt, text,
488
- } = props
489
- const heightLightTxt = (txt, heightTxt) => {
490
- if (heightTxt === '') {
491
- return txt
492
- }
493
- // 前面filterOption 不区分大小写,这里用i
494
- const regexp = new RegExp(heightTxt, 'gi')
495
- return txt.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
496
- }
497
- return (
498
- <Tooltip title={text}>
499
- <div ref={(nodeElement) => {
500
- if (nodeElement) {
501
- nodeElement.innerHTML = heightLightTxt(text, filterTxt)
502
- }
503
- }}
504
- />
505
- </Tooltip>
506
- )
507
- }
508
-
509
- // 扁平化二维数组的方法
510
- const mapRows = params => {
511
- var res = [];
512
- for (var i = 0; i < params.length; i++) {
513
- if (Array.isArray(params[i])) {
514
- // 去重
515
- res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
516
- } else {
517
- res.push(params[i]);
518
- // 去重
519
- res = _.uniqBy(res, 'value')
520
- }
521
- }
522
- return res.filter(Boolean); //去掉undefined的情况
523
- };
524
-
525
- const onChangeSelectedKeys = (selectKeys, selectRows) => {
526
- const nowPage = tablePagination?.current;
527
-
528
- let filterRows = []; // 存放拼接后的一维数组的变量
529
- let sksResult = [];
530
-
531
- if (selectMode) {
532
- // 处理多选分页累计选中
533
- // 勾选生成二维数组
534
- doubleArr[nowPage ? nowPage - 1 : 0] = selectRows
535
- // console.log(doubleArr)
536
- setDoubleArr(doubleArr)
537
- // 这块扁平化成为一位数组
538
- filterRows = mapRows(doubleArr);
539
- // console.log(filterRows)
540
-
541
- sksResult = filterRows.map((i) => i.value)
542
- } else {
543
- // 处理单选
544
- filterRows = selectRows;
545
- sksResult = selectRows.map((i) => i.value)
546
- // 单选直接选中 不需要确定
547
- handleSelectOver(filterRows)
548
- handleCancel();
549
- }
550
-
551
- setSelectedRowKeys(sksResult)
552
- setPopValue(filterRows);
553
- setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
554
- setCheckedAll(filterRows.length === tablePagination?.total);
555
- }
556
-
557
- // 生成唯一值
558
- const makeUniqueValue = () => {
559
- const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
560
- setUniqueValue(generateUnitKey);
561
- return generateUnitKey;
562
- }
563
-
564
- const rowSelection = {
565
- type: selectMode ? 'checkbox' : 'radio',
566
- selectedRowKeys,
567
- onChange: (sks, srs) => {
568
- onChangeSelectedKeys(sks, srs)
569
- },
570
- getCheckboxProps: () => {
571
- return ({
572
- disabled: selectProps?.disabled || props?.disabled || !items.length,
573
- })
574
- },
575
- };
576
-
577
- const onDoubleClickSelect = (e, record) => {
578
- if (!selectMode && !(selectProps?.disabled || props?.disabled || !items.length)) {
579
- const srs = [JSON.parse(JSON.stringify(record))]
580
- const sks = srs.map((i: any) => i.value)
581
- onChangeSelectedKeys(sks, srs)
582
- }
583
- }
584
-
585
- const themeColor = { color: '#1890ff' }
586
-
587
- const formItem = (list) => {
588
- if (isModalVisible && list?.length) {
589
- return list.map((i: any) => {
590
- if (i?.type === 'select' || i?.field?.type === 'select') {
591
- return (
592
- <Form.Item name={i.name} label={i.label} key={i.name}>
593
- <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}>
594
- {i?.initialSource?.length && i?.initialSource.map((m: any) => (
595
- <Option value={m.value} key={m.value}>{m.text}</Option>
596
- ))}
597
- </Select>
598
- </Form.Item>
599
- )
600
- }
601
-
602
- if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
603
- return (
604
- <Form.Item name={i.name} label={i.label} key={i.name}>
605
- <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}></TreeSelect>
606
- </Form.Item>
607
- )
608
- }
609
-
610
- if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
611
- return (
612
- <div>
613
- <Form.Item name={i.name} label={i.label} key={i.name}>
614
- <BusinessSearchSelect {...i.field.props} />
615
- </Form.Item>
616
- </div>
617
- )
618
- }
619
-
620
- if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
621
- return (
622
- <div>
623
- <Form.Item name={i.name} label={i.label} key={i.name}>
624
- <QueryMutipleInput onValueChange={(value) => {
625
- form.setFieldsValue({
626
- [i.name]: value
627
- })
628
- }} />
629
- </Form.Item>
630
- </div>
631
- );
632
- }
633
-
634
- // 默认type是input
635
- return (
636
- <Form.Item name={i.name} label={i.label} key={i.name}>
637
- <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} />
638
- </Form.Item>
639
- )
640
- })
641
- } else {
642
- return null
643
- }
644
- }
645
-
646
- const maxTagPlaceholder = (selectedValues) => {
647
- const onClose = (e: any, item: any) => {
648
- e.preventDefault();
649
- 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)
650
- onChange(newValue);
651
- }
652
- return (
653
- <Tooltip title={selectedValues.map((i: any) => (
654
- <Tag
655
- closable={true}
656
- onClose={(e) => onClose(e, i)}
657
- style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
658
- >
659
- {i.label}
660
- </Tag>
661
- ))}>
662
- {`+ ${selectedValues?.length}`}
663
- </Tooltip>
664
- )
665
- }
666
-
667
- return (
668
- <div className={'search_select'}>
669
- <div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
670
- <Select
671
- virtual
672
- labelInValue={labelInValue}
673
- value={value}
674
- onChange={onChange}
675
- disabled={props.disabled}
676
- dropdownRender={menu => (
677
- <>
678
- <Input
679
- value={searchValue}
680
- style={{ width: '98%', marginLeft: '1%' }}
681
- placeholder="请输入"
682
- onChange={e => onSearchChange(e)}
683
- onBlur={onSearchBlur}
684
- onKeyDown={(e) => {
685
- // 阻止多选的冒泡
686
- e.stopPropagation()
687
- }}
688
- />
689
- <Divider style={{ margin: '8px 0' }} />
690
- {menu}
691
- </>
692
- )}
693
- notFoundContent={
694
- fetching ? <Spin size="small" /> :
695
- <div style={{ textAlign: 'center' }}>
696
- <div style={{ marginBottom: 16 }}>
697
- <CopyOutlined style={{ fontSize: '50px' }} />
698
- </div>
699
- <div>无匹配结果,请更换其他内容再试</div>
700
- </div>
701
- }
702
- onPopupScroll={SelectScroll}
703
- style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
704
- placeholder="请选择"
705
- maxTagPlaceholder={maxTagPlaceholder}
706
- {...currentSelectProps}
707
- getPopupContainer={() => (getPopupContainer && getPopupContainer()) || document.getElementById(`search_select_div_${uniqueValue}`)}
708
- >
709
- {items.map(item => (
710
- <Option key={item.value} label={item.text}>
711
- {LightHeightOption({ text: `${item.textShowKey} ${Array.isArray(item.textShowText) && item.textShowText.join(' ') || item.textShowText}`, filterTxt: searchValue })}
712
- </Option>
713
- ))}
714
- </Select>
715
- {needModalTable && (
716
- <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
717
- <SearchOutlined />
718
- </Button>
719
- )}
720
- </div>
721
- {needModalTable && isModalVisible && (
722
- <Modal
723
- width='80%'
724
- title={modalTableProps?.modalTableTitle}
725
- visible={isModalVisible}
726
- onOk={handleOk}
727
- onCancel={handleCancel}
728
- footer={selectMode ? [
729
- <Button key="back" onClick={handleCancel}>
730
- 取消
731
- </Button>,
732
- <Button
733
- key="submit"
734
- type="primary"
735
- onClick={handleOk}
736
- disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
737
- >
738
- 确定
739
- </Button>,
740
- ] : null}
741
- >
742
- <div className={'search_select_wrapper'}>
743
- <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
744
- <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
745
- </div>
746
- <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
747
- <div className={'select_list_columns'}>
748
- <div className={'select_list_columns_tips'}>搜索</div>
749
- <div className={'select_list_columns_formItems'}>
750
- <Form form={form} layout='vertical' key='modalForm'>
751
- {formItem(modalTableProps?.tableSearchForm)}
752
- </Form>
753
- </div>
754
- </div>
755
- <div className={'select_list_searchButton'}>
756
- <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
757
- <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
758
- </div>
759
- </div>
760
- <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
761
- <div>
762
- <div className={'select_list_selectTips'}>
763
- <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
764
- <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
765
- </div>
766
- <Table
767
- size='small'
768
- rowSelection={rowSelection}
769
- columns={modalTableProps?.tableColumns}
770
- dataSource={tableData}
771
- pagination={tablePagination}
772
- onChange={handleTableChange}
773
- rowKey={mappingValueField}
774
- scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
775
- onRow={record => {
776
- return {
777
- onDoubleClick: event => onDoubleClickSelect(event, record),
778
- };
779
- }}
780
- />
781
- {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
782
- </div>
783
- </div>
784
- </div>
785
- </Modal>
786
- )}
787
- </div>
788
- );
789
- });
790
-
791
- export default SearchSelect;
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;