@bit-sun/business-component 2.1.3 → 2.1.5

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