@bit-sun/business-component 2.0.30 → 2.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +4 -4
  3. package/.gitlab-ci.yml +174 -174
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/components/Business/BsSulaQueryTable/index.d.ts +2 -0
  9. package/dist/components/Business/BsSulaQueryTable/setting.d.ts +59 -0
  10. package/dist/components/Business/BsSulaQueryTable/utils.d.ts +98 -0
  11. package/dist/components/Business/CommonAlert/index.d.ts +3 -0
  12. package/dist/components/Business/DetailPageWrapper/index.d.ts +9 -0
  13. package/dist/components/Business/DetailPageWrapper/utils.d.ts +9 -0
  14. package/dist/components/Business/HomePageWrapper/index.d.ts +3 -0
  15. package/dist/components/Business/columnSettingTable/index.d.ts +1 -0
  16. package/dist/components/Business/columnSettingTable/sulaSettingTable.d.ts +1 -0
  17. package/dist/index.esm.js +7600 -5489
  18. package/dist/index.js +7597 -5486
  19. package/docs/index.md +21 -21
  20. package/lib/assets/drag.svg +17 -17
  21. package/lib/assets/exportFail.svg +37 -37
  22. package/lib/assets/exportProcessing.svg +28 -28
  23. package/lib/assets/exportSuccess.svg +34 -34
  24. package/lib/assets/label_icon_bottom.svg +25 -25
  25. package/lib/assets/upExport.svg +22 -22
  26. package/package.json +69 -63
  27. package/src/assets/btn-delete.svg +30 -0
  28. package/src/assets/btn-edit.svg +20 -0
  29. package/src/assets/btn-more.svg +18 -0
  30. package/src/assets/btn-submit.svg +20 -0
  31. package/src/assets/close.svg +26 -26
  32. package/src/assets/drag.svg +17 -17
  33. package/src/assets/exportFail.svg +37 -37
  34. package/src/assets/exportProcessing.svg +28 -28
  35. package/src/assets/exportSuccess.svg +34 -34
  36. package/src/assets/fixed-left-active.svg +12 -0
  37. package/src/assets/fixed-left.svg +16 -0
  38. package/src/assets/fixed-right-active.svg +12 -0
  39. package/src/assets/fixed-right.svg +16 -0
  40. package/src/assets/icon-quanping.svg +16 -0
  41. package/src/assets/icon-shezhi.svg +17 -17
  42. package/src/assets/label_icon_bottom.svg +25 -25
  43. package/src/assets/scanning.svg +25 -0
  44. package/src/assets/upExport.svg +22 -22
  45. package/src/components/Business/AddSelectBusiness/index.md +41 -41
  46. package/src/components/Business/AddSelectBusiness/index.tsx +290 -290
  47. package/src/components/Business/BsSulaQueryTable/index.less +220 -0
  48. package/src/components/Business/BsSulaQueryTable/index.tsx +534 -0
  49. package/src/components/Business/BsSulaQueryTable/setting.tsx +817 -0
  50. package/src/components/Business/BsSulaQueryTable/utils.less +65 -0
  51. package/src/components/Business/BsSulaQueryTable/utils.tsx +690 -0
  52. package/src/components/Business/CommodityEntry/index.md +70 -70
  53. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  54. package/src/components/Business/CommonAlert/index.less +0 -0
  55. package/src/components/Business/CommonAlert/index.tsx +23 -0
  56. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  57. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  58. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  59. package/src/components/Business/DetailPageWrapper/index.less +80 -0
  60. package/src/components/Business/DetailPageWrapper/index.tsx +325 -0
  61. package/src/components/Business/DetailPageWrapper/utils.tsx +111 -0
  62. package/src/components/Business/HomePageWrapper/index.less +33 -0
  63. package/src/components/Business/HomePageWrapper/index.md +45 -0
  64. package/src/components/Business/HomePageWrapper/index.tsx +150 -0
  65. package/src/components/Business/SearchSelect/BusinessUtils.ts +1448 -1448
  66. package/src/components/Business/SearchSelect/common.ts +53 -53
  67. package/src/components/Business/SearchSelect/index.md +1137 -1137
  68. package/src/components/Business/SearchSelect/index.tsx +51 -51
  69. package/src/components/Business/SearchSelect/utils.ts +99 -99
  70. package/src/components/Business/StateFlow/index.less +130 -130
  71. package/src/components/Business/StateFlow/index.md +60 -60
  72. package/src/components/Business/StateFlow/index.tsx +29 -29
  73. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  74. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  75. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  76. package/src/components/Business/columnSettingTable/columnSetting.tsx +762 -594
  77. package/src/components/Business/columnSettingTable/index.less +247 -247
  78. package/src/components/Business/columnSettingTable/index.md +357 -357
  79. package/src/components/Business/columnSettingTable/index.tsx +225 -216
  80. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +233 -224
  81. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  82. package/src/components/Functional/AddSelect/index.less +367 -367
  83. package/src/components/Functional/AddSelect/index.md +122 -122
  84. package/src/components/Functional/AddSelect/index.tsx +962 -952
  85. package/src/components/Functional/BillEntry/index.less +371 -371
  86. package/src/components/Functional/BillEntry/index.md +37 -37
  87. package/src/components/Functional/BillEntry/index.tsx +547 -547
  88. package/src/components/Functional/DataImport/index.less +63 -63
  89. package/src/components/Functional/DataImport/index.md +44 -44
  90. package/src/components/Functional/DataImport/index.tsx +689 -689
  91. package/src/components/Functional/DataValidation/index.less +63 -63
  92. package/src/components/Functional/DataValidation/index.md +38 -38
  93. package/src/components/Functional/DataValidation/index.tsx +681 -681
  94. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  95. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  96. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  97. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  98. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  99. package/src/components/Functional/SearchSelect/index.less +115 -115
  100. package/src/components/Functional/SearchSelect/index.md +141 -141
  101. package/src/components/Functional/SearchSelect/index.tsx +812 -812
  102. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  103. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  104. package/src/index.ts +30 -27
  105. package/src/utils/CheckOneUser/index.md +39 -39
  106. package/src/utils/CheckOneUser/index.ts +51 -51
  107. package/src/utils/requestUtils.ts +32 -32
  108. package/src/utils/utils.ts +22 -22
  109. package/tsconfig.json +29 -29
  110. package/typings.d.ts +4 -4
@@ -1,952 +1,962 @@
1
- // @ts-nocheck
2
- import React, { useState, useEffect } from 'react';
3
- import { useDebounceFn } from 'ahooks';
4
- import { Input, Button, Modal, Select, InputNumber, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
- import { SearchOutlined, CopyOutlined, CloseCircleOutlined } 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 { Resizable } from 'react-resizable';
12
-
13
- const loadSelectSource = (url: string, params?: any) => {
14
- return new Promise((resolve, reject) => {
15
- axios
16
- .get(`${url}?${stringify(params)}`)
17
- .then((result: any) => {
18
- result = result.data;
19
- if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
20
- message.error(result.msg);
21
- return;
22
- }
23
- resolve(result);
24
- })
25
- .catch((err) => {
26
- reject(err);
27
- });
28
- })
29
- };
30
-
31
- const ResizeableTitle = (props) => {
32
- const { onResize, width, ...restProps } = props;
33
-
34
- if (!width) {
35
- return <th {...restProps} />;
36
- }
37
- return (
38
- <Resizable
39
- width={width}
40
- height={0}
41
- onResize={onResize}
42
- draggableOpts={{ enableUserSelectHack: false }}
43
- >
44
- <th {...restProps} />
45
- </Resizable>
46
- );
47
- };
48
-
49
- const formatSource = (reData: any, position: number, changePosition: number,changeSearchForm: any,resKeyValue=['code', 'name']) => {
50
- const data = reData && reData[position]?.data;
51
- const list = Array.isArray(data) ? data :(data?.items || data?.list || data?.children || []);
52
- const formatData = list?.length ? list.map((v: any) => ({ text: v[resKeyValue[1]], value: v[resKeyValue[0]] })) : [];
53
- changeSearchForm[changePosition] = {...changeSearchForm[changePosition], initialSource: formatData}
54
- }
55
-
56
- // 格式化树选择器数据源
57
- const mapSearchTree = (treeDataItem: any, resKeyValue: any) => {
58
- const haveChildren = Array.isArray(treeDataItem.children) && treeDataItem.children.length > 0;
59
- return {
60
- title: treeDataItem[resKeyValue[1]],
61
- value: treeDataItem[resKeyValue[0]],
62
- parentId: treeDataItem.parent,
63
- data: { ...treeDataItem },
64
- isLeaf: !haveChildren,
65
- disabled: haveChildren,
66
- children: haveChildren ? treeDataItem.children.map((i: any) => mapSearchTree(i, resKeyValue)) : [],
67
- };
68
- };
69
- const formatTreeDataSource = (reData: any, position: number, changePosition: number,changeSearchForm: any,resKeyValue=['id', 'name']) => {
70
- const data = reData && reData[position]?.data;
71
- const formatData = (data &&
72
- Array.isArray(data) &&
73
- data.length &&
74
- data.map((ites: any) => mapSearchTree(ites, resKeyValue))) ||
75
- []
76
- changeSearchForm[changePosition].field.props.treeData = formatData;
77
- }
78
-
79
- const { Option } = Select;
80
-
81
- const AddSelect = (props: any) => {
82
- const {
83
- value, // 必传
84
- onChange,
85
- selectProps = {},
86
- modalTableProps = {},
87
- labelInValue = false,
88
- requestConfig,
89
- ctx,
90
- sourceName,
91
- needModalTable = true,
92
- getPopupContainer = undefined,
93
- onSaveCallback,
94
- buttonText = '添加',
95
- beforeShowModal
96
- } = props;
97
- const { url, otherParams, isMap, fixedparameter, fieldValToParam, mappingTextField = 'name', mappingTextShowKeyField, mappingValueField = 'code', mappingTextShowTextField } = requestConfig || {};
98
- const resultSourceKey = sourceName || requestConfig?.sourceName || 'supplierCode'
99
-
100
- const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
101
- const initVal = value || (selectMode ? [] : null);
102
- const pageSize = 100 // 下拉框默认分页 条数
103
- const tableInitPageSize = 10 // 弹框默认分页 条数
104
- const currentPage = 1
105
- const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
106
- const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
107
- const currentSelectProps = {
108
- ...selectProps,
109
- // 以下属性不可更改----设计配置项
110
- showSearch: false,
111
- filterOption: false,
112
- allowClear: true,
113
- listHeight: 160,
114
- optionLabelProp: "label",
115
- autoClearSearchValue: false
116
- }
117
- const [items, setItems] = useState([]);
118
- const [scrollPage, setScrollPage] = useState(1);
119
- const [itemsTotal, setItemsTotal] = useState(0);
120
- const [fetching, setFetching] = useState(false);
121
- const [searchValue, setSearchValue] = useState('');
122
- const [isModalVisible, setIsModalVisible] = useState(false);
123
- const [popvalue, setPopValue] = useState(initVal);
124
- const [uniqueValue, setUniqueValue] = useState(sourceName)
125
- const { run } = useDebounceFn(
126
- (v?: any) => {
127
- // 优化搜索参数 支持传多个
128
- let searchParams = {};
129
- if (typeof selectParamsKey === 'string') {
130
- searchParams = v ? { [selectParamsInitKey]: initVal } : { [selectParamsKey]: searchValue }
131
- }
132
- if (Array.isArray(selectParamsKey)) {
133
- selectParamsKey.forEach((i: any) => {
134
- searchParams = { ...searchParams, [i]: searchValue }
135
- })
136
- }
137
- // 防抖函数 待定
138
- getData(searchParams)
139
- },
140
- {
141
- wait: 1000,
142
- },
143
- );
144
-
145
- const [form] = Form.useForm();
146
- const [tableSearchForm, setTableSearchForm] = useState(modalTableProps?.tableSearchForm)
147
- const [caretLeftFlag, setCaretLeftFlag] = useState(true);
148
- const [tableData, setTableData] = useState([]);
149
- const [tablePagination, setTablePagination] = useState({ total: 0, size: "small", current: 1, pageSize: tableInitPageSize })
150
- const [selectedRowKeys, setSelectedRowKeys] = useState([]);
151
- const [doubleArr, setDoubleArr] = useState([]); // 存放双数组的数组
152
- const [checkedAll, setCheckedAll] = useState(false)
153
- const [indeterminate, setIndeterminate] = useState(false)
154
- const [tableFormParams, setTableFormParams] = useState({});
155
- const [tableColumns, setTableColumns] = useState([]);
156
-
157
- useEffect(() => {
158
- setTableColumns(
159
- modalTableProps?.tableColumns.map((item, index) => {
160
- return {
161
- ...item,
162
- width: item.width || 200,
163
- onHeaderCell: (column) => ({
164
- ...item,
165
- width:
166
- typeof column.width === 'number'
167
- ? column.width
168
- : parseInt(column.width.replace('px', '')),
169
- onResize: handleResize(index),
170
- })
171
- }
172
- })
173
- )
174
- }, [modalTableProps?.tableColumns])
175
-
176
- // 获取数据源 (type: 1下拉框 2弹框 不传值默认为下拉框)
177
- const getData = (params = {}, type = 1) => {
178
- if (!requestConfig) return;
179
-
180
- setFetching(true)
181
-
182
- // 处理dependence参数
183
- const fixedParam = {};
184
- if (fixedparameter && fieldValToParam && ctx) {
185
- fixedparameter.forEach((item: any, index: any) => {
186
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
187
- if (fixedParamVal) {
188
- fixedParam[item] = fixedParamVal;
189
- form.setFieldsValue({ ...form?.getFieldsValue(), [item]: fixedParamVal })
190
- }
191
- });
192
- }
193
-
194
- // 数组对象处理,对带有特殊标记的name进行处理
195
- for (const key in params) {
196
- if (Object.prototype.hasOwnProperty.call(params, key)) {
197
- const element = params[key];
198
- if (element && key.indexOf('*number*') >= 0) {
199
- const dataParams = key.split('*number*');
200
- dataParams.forEach((value, index) => {
201
- params[value] = element[index];
202
- });
203
- delete params[key];
204
- } else if (element && key.indexOf('*address*') >= 0) {
205
- const dataParams = key.split('*address*');
206
- dataParams.forEach((value, index) => {
207
- params[value] = element.PCDCode[index];
208
- });
209
- delete params[key];
210
- } else if (element && key.indexOf('*costType*') >= 0) {
211
- const dataParams = key.split('*costType*');
212
- // eslint-disable-next-line prefer-destructuring
213
- params[dataParams[0]] = element[1];
214
- delete params[key];
215
- } else if (element && key.indexOf('*fullDate*') >= 0) {
216
- const dataParams = key.split('*fullDate*');
217
- dataParams.forEach((value, index) => {
218
- if (index === 0) {
219
- params[value] = moment(element[index])
220
- .millisecond(0)
221
- .second(0)
222
- .minute(0)
223
- .hour(0)
224
- .format('YYYY-MM-DD HH:mm:ss');
225
- } else {
226
- params[value] = moment(element[index])
227
- .millisecond(59)
228
- .second(59)
229
- .minute(59)
230
- .hour(23)
231
- .format('YYYY-MM-DD HH:mm:ss');
232
- }
233
- });
234
- delete params[key];
235
- } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
236
- const dataParams = key.split('*checkBox*');
237
- if (element) {
238
- params[dataParams[0]] = 0
239
- }
240
- delete params[key];
241
- } else if (element && key.indexOf('*cascader*') >= 0) {
242
- const dataParams = key.split('*cascader*');
243
- params[dataParams[0]] = element[element.length - 1]
244
- delete params[key];
245
- } else if (element && key.indexOf('*date*') >= 0) {
246
- const dataParams = key.split('*date*')
247
- dataParams.forEach((value, index) => {
248
- if (index === 0) {
249
- params[value] = moment(element[index])
250
- .format('YYYY-MM-DD');
251
- } else {
252
- params[value] = moment(element[index])
253
- .format('YYYY-MM-DD');
254
- }
255
- });
256
- delete params[key];
257
- }
258
- else if (element && key.indexOf('*') >= 0) {
259
- const dataParams = key.split('*');
260
- dataParams.forEach((value, index) => {
261
- params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
262
- });
263
- delete params[key];
264
- } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
265
- const dataParams = key.split('_selectNumberRange')[0]
266
- if (params[key][0] === 'range') {
267
- if (params[key][1][0]) {
268
- params[`qp-${dataParams}-ge`] = params[key][1][0]
269
- }
270
- if (params[key][1][1]) {
271
- params[`qp-${dataParams}-le`] = params[key][1][1]
272
- }
273
- } else {
274
- params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
275
- }
276
- delete params[key]
277
- } else if (Array.isArray(element)) {
278
- params[key] = element.join(',');
279
- } else if (element == null || element === undefined || String(element).trim() === '') {
280
- delete params[key]
281
- }
282
- }
283
- }
284
-
285
- const queryParams = {
286
- pageSize,
287
- currentPage,
288
- ...otherParams, // 默认参数
289
- ...fixedParam,
290
- ...params,
291
- }
292
- axios
293
- .get(`${url}?${stringify(queryParams)}`)
294
- .then((result: any) => {
295
- setFetching(false)
296
- result = result.data;
297
- if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
298
- message.error(result.msg);
299
- return;
300
- }
301
- const res = result.data;
302
- let source = [];
303
- if (isMap) {
304
- source = Object.keys(res).map((d, i) => {
305
- return {
306
- text: Object.values(res)[i],
307
- value: d,
308
- };
309
- });
310
- } else {
311
- const keys = res.list ? 'list' : 'items';
312
- source = res
313
- ? res[keys]
314
- ? res[keys].map((item: any) => {
315
- let textShowText = item[mappingTextField]
316
- if (mappingTextShowTextField) {
317
- textShowText = []
318
- if (Array.isArray(mappingTextShowTextField)) {
319
- mappingTextShowTextField.forEach((r: any) => {
320
- textShowText.push(item[r])
321
- })
322
- } else {
323
- textShowText = item[mappingTextShowTextField]
324
- }
325
- }
326
- return {
327
- ...item,
328
- text: item[mappingTextField],
329
- textShowText,
330
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
331
- value: item[mappingValueField],
332
- baseUnitCode: item?.packingUnitList?.find((item: any) => item.baseUnit === true)?.unitCode
333
- };
334
- })
335
- : Array.isArray(res) &&
336
- res?.map((item: Record<string, any>) => {
337
- let textShowText = item[mappingTextField]
338
- if (mappingTextShowTextField) {
339
- textShowText = []
340
- if (Array.isArray(mappingTextShowTextField)) {
341
- mappingTextShowTextField.forEach((r: any) => {
342
- textShowText.push(item[r])
343
- })
344
- } else {
345
- textShowText = item[mappingTextShowTextField]
346
- }
347
- }
348
- return {
349
- ...item,
350
- text: item[mappingTextField],
351
- textShowText,
352
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
353
- value: item[mappingValueField],
354
- baseUnitCode: item?.packingUnitList?.find((item: any) => item.baseUnit === true)?.unitCode
355
- };
356
- })
357
- : [];
358
- }
359
- source = Array.isArray(source) ? source : []
360
- if (type === 1) {
361
- ctx?.form?.setFieldSource(resultSourceKey, source)
362
- setItems(source)
363
- setItemsTotal(Number(res?.total || res?.totalCount || source.length))
364
- } else {
365
- setTableData(source)
366
- 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)) })
367
- }
368
- })
369
- .catch((err) => { setFetching(false) });
370
- }
371
-
372
- const SelectScroll = e => {
373
- e.persist();
374
- const { target } = e;
375
- const totalPage = Math.ceil(itemsTotal / pageSize)
376
- // 判断是否滑动到底部
377
- const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
378
- // 判断数据是否还没有加载到了最后一页
379
- const canPageAdd = scrollPage < totalPage
380
- if (isTouchGround && canPageAdd) {
381
- const nextScrollPage = scrollPage + 1;
382
- setScrollPage(nextScrollPage);
383
- getData({ currentPage: nextScrollPage }); // 调用api方法
384
- }
385
-
386
- //判断是否滑动到顶部
387
- const isTouchTop = target.scrollTop === 0 // <=0
388
- // 判断数据是否到第一页
389
- const canPageJian = scrollPage > 1
390
- if (isTouchTop && canPageJian) {
391
- const preScrollPage = scrollPage - 1;
392
- setScrollPage(preScrollPage);
393
- getData({ currentPage: preScrollPage }); // 调用api方法
394
- }
395
- }
396
-
397
- useEffect(() => {
398
- Promise.all([
399
- loadSelectSource(`/items/brand/queryBrandList`, {
400
- pageSize: 5000,
401
- currentPage: 1,
402
- 'ctl-withAuth': true
403
- }),
404
- loadSelectSource(`/items/category/queryCategoryTree`, {
405
- pageSize: 5000,
406
- currentPage: 1,
407
- }),
408
- ]).then((x: any)=>{
409
- formatSource(x,0, 2, tableSearchForm,['id','name'])
410
- formatTreeDataSource(x,1, 3, tableSearchForm)
411
- })
412
- }, [])
413
-
414
- useEffect(() => {
415
- if (value) {
416
- setPopValue(value);
417
- }
418
- }, [value]);
419
-
420
- useEffect(() => {
421
- makeUniqueValue();
422
- }, [sourceName])
423
-
424
- const showModal = () => {
425
- // getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
426
- setIsModalVisible(true);
427
- // 回显
428
- if (value) {
429
- if (selectMode) {
430
- setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
431
- setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
432
- setIndeterminate(!!value.length && value.length < itemsTotal);
433
- setCheckedAll(itemsTotal && value.length === itemsTotal);
434
- // 需清空数据
435
- if (!value.length) {
436
- setDoubleArr([])
437
- }
438
- } else {
439
- setSelectedRowKeys(labelInValue ? [value.key] : [value])
440
- setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
441
- }
442
- }
443
-
444
- setTimeout(() => {
445
- document.getElementById("first-query")?.focus()
446
- }, 50)
447
- };
448
-
449
- const handleShowModal = () => {
450
- if(beforeShowModal) {
451
- beforeShowModal(popvalue).then(res => {
452
- showModal()
453
- }).catch(Error => {
454
- message.warning(Error)
455
- })
456
- } else {
457
- showModal()
458
- }
459
- }
460
-
461
- const handleSelectOver = (selectedValue: any) => {
462
- if (selectedValue?.length) {
463
- formaData(selectedValue);
464
- // 解决选择最后1页的sku,返回后,不显示名称问题
465
- const source = _.uniqBy(items.concat(selectedValue), 'value')
466
- ctx?.form?.setFieldSource(resultSourceKey, source)
467
- setItems(source)
468
- }
469
- }
470
-
471
- const handleOk = (isContinue) => {
472
- if(!popvalue.length) {
473
- message.warning('至少选中一条数据')
474
- return;
475
- }
476
- // handleSelectOver(popvalue)
477
- if(onSaveCallback) {
478
- onSaveCallback(popvalue).then(res => {
479
- if(true) {
480
- message.success('保存成功')
481
- deleteSelectRows();
482
- document.getElementById('first-query')?.focus()
483
- !isContinue && handleCancel();
484
- } else {
485
- }
486
- }).catch(Error => {
487
- message.error(Error)
488
- })
489
- } else {
490
- !isContinue && handleCancel();
491
- }
492
- };
493
-
494
- const formaData = (value) => {
495
- if (labelInValue) {
496
- const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
497
- onChange(selectMode ? formatResult : formatResult[0])
498
- } else {
499
- const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
500
- onChange(formatResult)
501
- }
502
- };
503
-
504
- const handleCancel = () => {
505
- form.resetFields();
506
- setTableFormParams({});
507
- setIsModalVisible(false);
508
- setTableData([])
509
- // if (selectMode) {
510
- // run();
511
- // }
512
- };
513
-
514
- const onSearchChange = (e) => {
515
- setSearchValue(e.target.value);
516
- run();
517
- }
518
-
519
- const onSearchBlur = () => {
520
- setSearchValue('')
521
- run();
522
- }
523
-
524
- const onSearchTable = () => {
525
- const params = form.getFieldsValue();
526
- setTableFormParams(params);
527
- getData({ ...params, pageSize: tableInitPageSize }, 2)
528
- if (selectMode) {
529
- getData(params)
530
- }
531
- }
532
-
533
- const onResetTable = () => {
534
- form.resetFields();
535
- setTableFormParams({});
536
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
537
- }
538
-
539
- const handleTableChange = (pagination) => {
540
- getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
541
- }
542
-
543
- // 扁平化二维数组的方法
544
- const mapRows = params => {
545
- var res = [];
546
- for (var i = 0; i < params.length; i++) {
547
- if (Array.isArray(params[i])) {
548
- // 去重
549
- res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
550
- } else {
551
- res.push(params[i]);
552
- // 去重
553
- res = _.uniqBy(res, 'value')
554
- }
555
- }
556
- return res.filter(Boolean); //去掉undefined的情况
557
- };
558
-
559
- const onChangeSelectedKeys = (selectKeys, selectRows) => {
560
- if(selectKeys.length - selectedRowKeys.length > 0) {
561
- if (selectKeys.length - selectedRowKeys.length === 1) {
562
- selectRows[selectRows.length -1]['needFocus'] = true;
563
- } else {
564
- selectRows[selectedRowKeys.length]['needFocus'] = true;
565
- }
566
- }
567
- setPopValue(selectRows);
568
- setSelectedRowKeys(selectKeys)
569
- // setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
570
- // setCheckedAll(filterRows.length === tablePagination?.total);
571
- }
572
-
573
- // 生成唯一值
574
- const makeUniqueValue = () => {
575
- const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
576
- setUniqueValue(generateUnitKey);
577
- return generateUnitKey;
578
- }
579
-
580
- const rowSelection = {
581
- type: 'checkbox',
582
- selectedRowKeys,
583
- preserveSelectedRowKeys: true,
584
- onChange: (sks, srs) => {
585
- onChangeSelectedKeys(sks, srs)
586
- },
587
- getCheckboxProps: () => ({
588
- disabled: selectProps?.disabled || props?.disabled,
589
- }),
590
- };
591
-
592
- const onDoubleClickSelect = (e, record) => {
593
- if (!selectMode) {
594
- const srs = [JSON.parse(JSON.stringify(record))]
595
- const sks = srs.map((i: any) => i.value)
596
- onChangeSelectedKeys(sks, srs)
597
- }
598
- }
599
-
600
- const themeColor = { color: '#005CFF' }
601
-
602
- const formItem = (list) => {
603
- if (isModalVisible && list?.length) {
604
- return list.map((i: any, index) => {
605
- if (i?.type === 'select' || i?.field?.type === 'select') {
606
- return (
607
- <Form.Item name={i.name} label={i.label} key={i.name}>
608
- <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}>
609
- {i?.initialSource?.length && i?.initialSource.map((m: any) => (
610
- <Option value={m.value} key={m.value}>{m.text}</Option>
611
- ))}
612
- </Select>
613
- </Form.Item>
614
- )
615
- }
616
-
617
- if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
618
- return (
619
- <Form.Item name={i.name} label={i.label} key={i.name}>
620
- <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}></TreeSelect>
621
- </Form.Item>
622
- )
623
- }
624
-
625
- if (i?.type === 'BusinessSearchSelect' || i?.field?.type === 'BusinessSearchSelect') {
626
- return (
627
- <div>
628
- <Form.Item name={i.name} label={i.label} key={i.name}>
629
- <BusinessSearchSelect {...i.field.props} />
630
- </Form.Item>
631
- </div>
632
- )
633
- }
634
-
635
- if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
636
- return (
637
- <div>
638
- <Form.Item name={i.name} label={i.label} key={i.name}>
639
- <QueryMutipleInput onValueChange={(value) => {
640
- form.setFieldsValue({
641
- [i.name]: value
642
- })
643
- }} />
644
- </Form.Item>
645
- </div>
646
- );
647
- }
648
-
649
- // 默认type是input
650
- return (
651
- <Form.Item name={i.name} label={i.label} key={i.name}>
652
- <Input id={index === 0 ? "first-query" : 'index'} style={{ width: '100%' }} onKeyDown={(e) => {
653
- if (e.keyCode === 13) {
654
- onSearchTable()
655
- }
656
- }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} />
657
- </Form.Item>
658
- )
659
- })
660
- } else {
661
- return null
662
- }
663
- }
664
-
665
- const maxTagPlaceholder = (selectedValues) => {
666
- const onClose = (e: any, item: any) => {
667
- e.preventDefault();
668
- 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)
669
- onChange(newValue);
670
- }
671
- return (
672
- <Tooltip title={selectedValues.map((i: any) => (
673
- <Tag
674
- closable={true}
675
- onClose={(e) => onClose(e, i)}
676
- style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
677
- >
678
- {i.label}
679
- </Tag>
680
- ))}>
681
- {`+ ${selectedValues?.length}`}
682
- </Tooltip>
683
- )
684
- }
685
-
686
- const deleteSelectRows = () => {
687
- setPopValue([])
688
- setSelectedRowKeys([])
689
- }
690
-
691
- const deleteRecord = (record) => {
692
- setPopValue(popvalue.filter(item => item.skuCode !== record.skuCode))
693
- setSelectedRowKeys([...selectedRowKeys.filter(item => item !== record.skuCode)])
694
- }
695
-
696
- let inputIndex = 0;
697
- let selectColumns = [... modalTableProps.selectColumn.map(item => {
698
- const inputLength = modalTableProps.selectColumn.filter(item => item.isInputItem).length
699
- const currentIndex = inputIndex
700
-
701
- if (item.isInputItem) {
702
- inputIndex++;
703
- return {
704
- ...item,
705
- render: (text, record, index) => {
706
- // let
707
- if(record.needFocus === true && currentIndex === 0) {
708
-
709
- }
710
- return (
711
- <InputNumber
712
- defaultValue={text || ''}
713
- min={0}
714
- autoFocus={record.needFocus}
715
- keyboard={false}
716
- onChange={(value) => {
717
- record[item.dataIndex] = value
718
- }}
719
- // onFocus={(e)=> {
720
- // let dom1 = e.currentTarget;
721
- // dom1.setSelectionRange(100, 0);
722
- // dom1.select(text);
723
- // }}
724
- onKeyDown={(e) => {
725
- if(e.keyCode === 13 && e.ctrlKey) {
726
- handleOk(true)
727
- document.getElementById("first-query")?.focus()
728
- }
729
- if(e.keyCode === 8 && e.ctrlKey) {
730
- message.success('删除当前行')
731
- e.stopPropagation();
732
- e.preventDefault();
733
- let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
734
- if (dom) {
735
- dom.select();
736
- dom.focus();
737
- dom.scrollIntoView(false)
738
- }
739
- dom = null
740
- deleteRecord(record, popvalue);
741
- }
742
- if (e.keyCode === 37 && e.shiftKey) { // 左滑动
743
- e.stopPropagation();
744
- e.preventDefault();
745
- let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
746
- if (dom) {
747
- dom.select();
748
- dom.focus();
749
- dom.scrollIntoView(false)
750
- }
751
- dom = null
752
- }
753
- if (e.keyCode === 39 && e.shiftKey) { // 右滑
754
- e.stopPropagation();
755
- e.preventDefault();
756
- let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
757
- if (dom) {
758
- dom.select();
759
- dom.focus();
760
- dom.scrollIntoView(false)
761
- }
762
- dom = null
763
- }
764
- if (e.keyCode === 40) {
765
- e.stopPropagation();
766
- e.preventDefault();
767
- let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
768
- if (dom) {
769
- dom.select();
770
- dom.focus();
771
- dom.scrollIntoView(false)
772
- }
773
- dom = null
774
- } else if (e.keyCode === 38) {
775
- e.stopPropagation();
776
- e.preventDefault();
777
- let dom1 = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
778
- if (dom1) {
779
- // dom1.value=""
780
- // dom1.setSelectionRange(100, 0);
781
- dom1.select();
782
- dom1.focus();
783
- dom1.scrollIntoViewIfNeeded(false)
784
- // dom1.value=record['count']
785
- }
786
- dom1 = null
787
- } else if (e.keyCode === 9 && index === selectedRowKeys.length - 1 && currentIndex === inputLength - 1) {
788
- e.stopPropagation();
789
- e.preventDefault();
790
- }
791
- }}
792
- />
793
- );
794
- },
795
- }
796
- }
797
-
798
- return item
799
- }), {
800
- title: '操作',
801
- width: 50,
802
- fixed: 'right',
803
- render: (text, record, index) => {
804
- return (
805
- <span style={{cursor: 'pointer', color: '#005CFF' }} onClick={() => {
806
- deleteRecord(record)
807
- }} type={"text"}>删除</span>
808
- )
809
- }
810
- },]
811
-
812
- const handleResize =
813
- (index) =>
814
- (e, { size }) => {
815
- setTableColumns((columns: any) => {
816
- let newColumns = [...columns];
817
- newColumns[index] = {
818
- ...newColumns[index],
819
- width: size.width,
820
- };
821
- return [...newColumns];
822
- });
823
- };
824
-
825
- return (
826
- <div className={'add_select'}>
827
- <div className="add_select_show" id={`add_select_div_${uniqueValue}`}>
828
- <Button onClick={handleShowModal} type="primary">
829
- {buttonText}
830
- </Button>
831
- </div>
832
- {needModalTable && isModalVisible && (
833
- <Modal
834
- width='1200px'
835
- style={{ top: 20 }}
836
- bodyStyle={{ padding: '0px' }}
837
- // title={modalTableProps?.modalTableTitle}
838
- visible={isModalVisible}
839
- onOk={handleOk}
840
- closable={false}
841
- onCancel={handleCancel}
842
- footer={selectMode ? [
843
- <Button key="back" onClick={handleCancel}>
844
- 取消
845
- </Button>,
846
- <Button
847
- key="submit"
848
- style={{color: '#005CFF', borderColor: '#005CFF'}}
849
- onClick={() => {handleOk(true)}}
850
- disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
851
- >
852
- 保存并继续
853
- </Button>,
854
- <Button
855
- key="submit"
856
- type="primary"
857
- onClick={() => {handleOk(false)}}
858
- disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
859
- >
860
- 确定
861
- </Button>,
862
- ] : null}
863
- >
864
- <div>
865
- <div className='add_select_header'>
866
- {modalTableProps?.modalTableTitle}
867
- <span><span>*</span> &nbsp;快捷键:【Tab】-跳格切换;【Shift+←、→】-当前行左、右移动;【 ↑、↓】-当前列上、下移动;【ctrl+Enter】-保存并继续;【ctrl+Delete】-删除当前行;</span>
868
- <span className='add_select_header_close'><CloseCircleOutlined style={{fontSize: '20px'}} onClick={handleCancel} /></span>
869
- </div>
870
- <div className={'add_select_wrapper'}>
871
- <div className={caretLeftFlag ? 'add_select_wrapper_left' : 'add_select_wrapper_left1'}>
872
- <div className={'select_list_columns'}>
873
- <div className={'select_list_columns_formItems'}>
874
- <Form form={form} layout='vertical' key='modalForm'>
875
- {formItem(tableSearchForm)}
876
- </Form>
877
- </div>
878
- </div>
879
- <div className={'select_list_searchButton'}>
880
- <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
881
- <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
882
- </div>
883
- </div>
884
- <div className={caretLeftFlag ? 'add_select_wrapper_right' : 'add_select_wrapper_right1'}>
885
- <div>
886
- <div className={'select_list_selectTips'}>
887
- <div style={{ marginLeft: 8 }}>搜索结果共&nbsp;<span style={themeColor}>{tablePagination?.total || 0}</span>&nbsp;项{selectMode ? <span>, 本次已选&nbsp;<span style={themeColor}>{selectedRowKeys?.length || 0}</span>&nbsp;项</span> : ''}</div>
888
- </div>
889
- <Table
890
- size='small'
891
- rowSelection={rowSelection}
892
- columns={tableColumns}
893
- dataSource={tableData}
894
- pagination={tablePagination}
895
- loading={fetching}
896
- onChange={handleTableChange}
897
- rowKey={mappingValueField}
898
- rowClassName={'row-class'}
899
- scroll={{ y: 500 }}
900
- components={{
901
- header: {
902
- cell: ResizeableTitle,
903
- },
904
- }}
905
- />
906
- </div>
907
- </div>
908
- {/* <div>
909
- <Table
910
- size='small'
911
- columns={modalTableProps?.tableColumns}
912
- dataSource={mapRows(doubleArr)}
913
- rowKey={mappingValueField}
914
- scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
915
- onRow={record => {
916
- return {
917
- onDoubleClick: event => onDoubleClickSelect(event, record),
918
- };
919
- }}
920
- />
921
- </div> */}
922
- </div>
923
- <div className={'add_select_wrapper_select'}>
924
- <div className={'select_list_selectTips'}>
925
- <div style={{ marginLeft: 8 }}><span>本次已选&nbsp;<span style={themeColor}>{selectedRowKeys?.length || 0}</span>&nbsp;项</span></div>
926
- <div style={{ marginRight: 8 }}><span onClick={deleteSelectRows} style={{ ...themeColor, cursor: 'pointer' }}>清空所选商品</span></div>
927
- </div>
928
- <Table
929
- size='small'
930
- // rowSelection={rowSelection}
931
- columns={selectColumns}
932
- dataSource={popvalue}
933
- pagination={false}
934
- // onChange={handleTableChange}
935
- rowKey={mappingValueField}
936
- rowClassName={'row-class'}
937
- scroll={{ y: 500 }}
938
- onRow={record => {
939
- return {
940
- onDoubleClick: event => onDoubleClickSelect(event, record),
941
- };
942
- }}
943
- />
944
- </div>
945
- </div>
946
- </Modal>
947
- )}
948
- </div>
949
- );
950
- };
951
-
952
- export default AddSelect;
1
+ // @ts-nocheck
2
+ import React, { useState, useEffect } from 'react';
3
+ import { useDebounceFn } from 'ahooks';
4
+ import { Input, Button, Modal, Select, InputNumber, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
+ import { SearchOutlined, CopyOutlined, CloseCircleOutlined } 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 { Resizable } from 'react-resizable';
12
+
13
+ const loadSelectSource = (url: string, params?: any) => {
14
+ return new Promise((resolve, reject) => {
15
+ axios
16
+ .get(`${url}?${stringify(params)}`)
17
+ .then((result: any) => {
18
+ result = result.data;
19
+ if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
20
+ message.error(result.msg);
21
+ return;
22
+ }
23
+ resolve(result);
24
+ })
25
+ .catch((err) => {
26
+ reject(err);
27
+ });
28
+ })
29
+ };
30
+
31
+ const ResizeableTitle = (props) => {
32
+ const { onResize, width, ...restProps } = props;
33
+
34
+ if (!width) {
35
+ return <th {...restProps} />;
36
+ }
37
+ return (
38
+ <Resizable
39
+ width={width}
40
+ height={0}
41
+ onResize={onResize}
42
+ draggableOpts={{ enableUserSelectHack: false }}
43
+ >
44
+ <th {...restProps} />
45
+ </Resizable>
46
+ );
47
+ };
48
+
49
+ const formatSource = (reData: any, position: number, changePosition: number,changeSearchForm: any,resKeyValue=['code', 'name']) => {
50
+ const data = reData && reData[position]?.data;
51
+ const list = Array.isArray(data) ? data :(data?.items || data?.list || data?.children || []);
52
+ const formatData = list?.length ? list.map((v: any) => ({ text: v[resKeyValue[1]], value: v[resKeyValue[0]] })) : [];
53
+ changeSearchForm[changePosition] = {...changeSearchForm[changePosition], initialSource: formatData}
54
+ }
55
+
56
+ // 格式化树选择器数据源
57
+ const mapSearchTree = (treeDataItem: any, resKeyValue: any) => {
58
+ const haveChildren = Array.isArray(treeDataItem.children) && treeDataItem.children.length > 0;
59
+ return {
60
+ title: treeDataItem[resKeyValue[1]],
61
+ value: treeDataItem[resKeyValue[0]],
62
+ parentId: treeDataItem.parent,
63
+ data: { ...treeDataItem },
64
+ isLeaf: !haveChildren,
65
+ disabled: haveChildren,
66
+ children: haveChildren ? treeDataItem.children.map((i: any) => mapSearchTree(i, resKeyValue)) : [],
67
+ };
68
+ };
69
+ const formatTreeDataSource = (reData: any, position: number, changePosition: number,changeSearchForm: any,resKeyValue=['id', 'name']) => {
70
+ const data = reData && reData[position]?.data;
71
+ const formatData = (data &&
72
+ Array.isArray(data) &&
73
+ data.length &&
74
+ data.map((ites: any) => mapSearchTree(ites, resKeyValue))) ||
75
+ []
76
+ changeSearchForm[changePosition].field.props.treeData = formatData;
77
+ }
78
+
79
+ const { Option } = Select;
80
+
81
+ const AddSelect = (props: any) => {
82
+ const {
83
+ value, // 必传
84
+ onChange,
85
+ selectProps = {},
86
+ modalTableProps = {},
87
+ labelInValue = false,
88
+ requestConfig,
89
+ ctx,
90
+ sourceName,
91
+ needModalTable = true,
92
+ getPopupContainer = undefined,
93
+ onSaveCallback,
94
+ buttonText = '添加',
95
+ beforeShowModal
96
+ } = props;
97
+ const { url, otherParams, isMap, fixedparameter, fieldValToParam, mappingTextField = 'name', mappingTextShowKeyField, mappingValueField = 'code', mappingTextShowTextField } = requestConfig || {};
98
+ const resultSourceKey = sourceName || requestConfig?.sourceName || 'supplierCode'
99
+
100
+ const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
101
+ const initVal = value || (selectMode ? [] : null);
102
+ const pageSize = 100 // 下拉框默认分页 条数
103
+ const tableInitPageSize = 10 // 弹框默认分页 条数
104
+ const currentPage = 1
105
+ const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
106
+ const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
107
+ const currentSelectProps = {
108
+ ...selectProps,
109
+ // 以下属性不可更改----设计配置项
110
+ showSearch: false,
111
+ filterOption: false,
112
+ allowClear: true,
113
+ listHeight: 160,
114
+ optionLabelProp: "label",
115
+ autoClearSearchValue: false
116
+ }
117
+ const [items, setItems] = useState([]);
118
+ const [scrollPage, setScrollPage] = useState(1);
119
+ const [itemsTotal, setItemsTotal] = useState(0);
120
+ const [fetching, setFetching] = useState(false);
121
+ const [searchValue, setSearchValue] = useState('');
122
+ const [isModalVisible, setIsModalVisible] = useState(false);
123
+ const [popvalue, setPopValue] = useState(initVal);
124
+ const [uniqueValue, setUniqueValue] = useState(sourceName)
125
+ const { run } = useDebounceFn(
126
+ (v?: any) => {
127
+ // 优化搜索参数 支持传多个
128
+ let searchParams = {};
129
+ if (typeof selectParamsKey === 'string') {
130
+ searchParams = v ? { [selectParamsInitKey]: initVal } : { [selectParamsKey]: searchValue }
131
+ }
132
+ if (Array.isArray(selectParamsKey)) {
133
+ selectParamsKey.forEach((i: any) => {
134
+ searchParams = { ...searchParams, [i]: searchValue }
135
+ })
136
+ }
137
+ // 防抖函数 待定
138
+ getData(searchParams)
139
+ },
140
+ {
141
+ wait: 1000,
142
+ },
143
+ );
144
+
145
+ const [form] = Form.useForm();
146
+ const [tableSearchForm, setTableSearchForm] = useState(modalTableProps?.tableSearchForm)
147
+ const [caretLeftFlag, setCaretLeftFlag] = useState(true);
148
+ const [tableData, setTableData] = useState([]);
149
+ const [tablePagination, setTablePagination] = useState({ total: 0, size: "small", current: 1, pageSize: tableInitPageSize })
150
+ const [selectedRowKeys, setSelectedRowKeys] = useState([]);
151
+ const [doubleArr, setDoubleArr] = useState([]); // 存放双数组的数组
152
+ const [checkedAll, setCheckedAll] = useState(false)
153
+ const [indeterminate, setIndeterminate] = useState(false)
154
+ const [tableFormParams, setTableFormParams] = useState({});
155
+ const [tableColumns, setTableColumns] = useState([]);
156
+ const [confirmLoading, setConfirmLoading] = useState(false);
157
+ const [confirmContinueLoading, setConfirmContinueLoading] = useState(false);
158
+
159
+ useEffect(() => {
160
+ setTableColumns(
161
+ modalTableProps?.tableColumns.map((item, index) => {
162
+ return {
163
+ ...item,
164
+ width: item.width || 200,
165
+ onHeaderCell: (column) => ({
166
+ ...item,
167
+ width:
168
+ typeof column.width === 'number'
169
+ ? column.width
170
+ : parseInt(column.width.replace('px', '')),
171
+ onResize: handleResize(index),
172
+ })
173
+ }
174
+ })
175
+ )
176
+ }, [modalTableProps?.tableColumns])
177
+
178
+ // 获取数据源 (type: 1下拉框 2弹框 不传值默认为下拉框)
179
+ const getData = (params = {}, type = 1) => {
180
+ if (!requestConfig) return;
181
+
182
+ setFetching(true)
183
+
184
+ // 处理dependence参数
185
+ const fixedParam = {};
186
+ if (fixedparameter && fieldValToParam && ctx) {
187
+ fixedparameter.forEach((item: any, index: any) => {
188
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
189
+ if (fixedParamVal) {
190
+ fixedParam[item] = fixedParamVal;
191
+ form.setFieldsValue({ ...form?.getFieldsValue(), [item]: fixedParamVal })
192
+ }
193
+ });
194
+ }
195
+
196
+ // 数组对象处理,对带有特殊标记的name进行处理
197
+ for (const key in params) {
198
+ if (Object.prototype.hasOwnProperty.call(params, key)) {
199
+ const element = params[key];
200
+ if (element && key.indexOf('*number*') >= 0) {
201
+ const dataParams = key.split('*number*');
202
+ dataParams.forEach((value, index) => {
203
+ params[value] = element[index];
204
+ });
205
+ delete params[key];
206
+ } else if (element && key.indexOf('*address*') >= 0) {
207
+ const dataParams = key.split('*address*');
208
+ dataParams.forEach((value, index) => {
209
+ params[value] = element.PCDCode[index];
210
+ });
211
+ delete params[key];
212
+ } else if (element && key.indexOf('*costType*') >= 0) {
213
+ const dataParams = key.split('*costType*');
214
+ // eslint-disable-next-line prefer-destructuring
215
+ params[dataParams[0]] = element[1];
216
+ delete params[key];
217
+ } else if (element && key.indexOf('*fullDate*') >= 0) {
218
+ const dataParams = key.split('*fullDate*');
219
+ dataParams.forEach((value, index) => {
220
+ if (index === 0) {
221
+ params[value] = moment(element[index])
222
+ .millisecond(0)
223
+ .second(0)
224
+ .minute(0)
225
+ .hour(0)
226
+ .format('YYYY-MM-DD HH:mm:ss');
227
+ } else {
228
+ params[value] = moment(element[index])
229
+ .millisecond(59)
230
+ .second(59)
231
+ .minute(59)
232
+ .hour(23)
233
+ .format('YYYY-MM-DD HH:mm:ss');
234
+ }
235
+ });
236
+ delete params[key];
237
+ } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
238
+ const dataParams = key.split('*checkBox*');
239
+ if (element) {
240
+ params[dataParams[0]] = 0
241
+ }
242
+ delete params[key];
243
+ } else if (element && key.indexOf('*cascader*') >= 0) {
244
+ const dataParams = key.split('*cascader*');
245
+ params[dataParams[0]] = element[element.length - 1]
246
+ delete params[key];
247
+ } else if (element && key.indexOf('*date*') >= 0) {
248
+ const dataParams = key.split('*date*')
249
+ dataParams.forEach((value, index) => {
250
+ if (index === 0) {
251
+ params[value] = moment(element[index])
252
+ .format('YYYY-MM-DD');
253
+ } else {
254
+ params[value] = moment(element[index])
255
+ .format('YYYY-MM-DD');
256
+ }
257
+ });
258
+ delete params[key];
259
+ }
260
+ else if (element && key.indexOf('*') >= 0) {
261
+ const dataParams = key.split('*');
262
+ dataParams.forEach((value, index) => {
263
+ params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
264
+ });
265
+ delete params[key];
266
+ } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
267
+ const dataParams = key.split('_selectNumberRange')[0]
268
+ if (params[key][0] === 'range') {
269
+ if (params[key][1][0]) {
270
+ params[`qp-${dataParams}-ge`] = params[key][1][0]
271
+ }
272
+ if (params[key][1][1]) {
273
+ params[`qp-${dataParams}-le`] = params[key][1][1]
274
+ }
275
+ } else {
276
+ params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
277
+ }
278
+ delete params[key]
279
+ } else if (Array.isArray(element)) {
280
+ params[key] = element.join(',');
281
+ } else if (element == null || element === undefined || String(element).trim() === '') {
282
+ delete params[key]
283
+ }
284
+ }
285
+ }
286
+
287
+ const queryParams = {
288
+ pageSize,
289
+ currentPage,
290
+ ...otherParams, // 默认参数
291
+ ...fixedParam,
292
+ ...params,
293
+ }
294
+ axios
295
+ .get(`${url}?${stringify(queryParams)}`)
296
+ .then((result: any) => {
297
+ setFetching(false)
298
+ result = result.data;
299
+ if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
300
+ message.error(result.msg);
301
+ return;
302
+ }
303
+ const res = result.data;
304
+ let source = [];
305
+ if (isMap) {
306
+ source = Object.keys(res).map((d, i) => {
307
+ return {
308
+ text: Object.values(res)[i],
309
+ value: d,
310
+ };
311
+ });
312
+ } else {
313
+ const keys = res.list ? 'list' : 'items';
314
+ source = res
315
+ ? res[keys]
316
+ ? res[keys].map((item: any) => {
317
+ let textShowText = item[mappingTextField]
318
+ if (mappingTextShowTextField) {
319
+ textShowText = []
320
+ if (Array.isArray(mappingTextShowTextField)) {
321
+ mappingTextShowTextField.forEach((r: any) => {
322
+ textShowText.push(item[r])
323
+ })
324
+ } else {
325
+ textShowText = item[mappingTextShowTextField]
326
+ }
327
+ }
328
+ return {
329
+ ...item,
330
+ text: item[mappingTextField],
331
+ textShowText,
332
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
333
+ value: item[mappingValueField],
334
+ baseUnitCode: item?.packingUnitList?.find((item: any) => item.baseUnit === true)?.unitCode
335
+ };
336
+ })
337
+ : Array.isArray(res) &&
338
+ res?.map((item: Record<string, any>) => {
339
+ let textShowText = item[mappingTextField]
340
+ if (mappingTextShowTextField) {
341
+ textShowText = []
342
+ if (Array.isArray(mappingTextShowTextField)) {
343
+ mappingTextShowTextField.forEach((r: any) => {
344
+ textShowText.push(item[r])
345
+ })
346
+ } else {
347
+ textShowText = item[mappingTextShowTextField]
348
+ }
349
+ }
350
+ return {
351
+ ...item,
352
+ text: item[mappingTextField],
353
+ textShowText,
354
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
355
+ value: item[mappingValueField],
356
+ baseUnitCode: item?.packingUnitList?.find((item: any) => item.baseUnit === true)?.unitCode
357
+ };
358
+ })
359
+ : [];
360
+ }
361
+ source = Array.isArray(source) ? source : []
362
+ if (type === 1) {
363
+ ctx?.form?.setFieldSource(resultSourceKey, source)
364
+ setItems(source)
365
+ setItemsTotal(Number(res?.total || res?.totalCount || source.length))
366
+ } else {
367
+ setTableData(source)
368
+ 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)) })
369
+ }
370
+ })
371
+ .catch((err) => { setFetching(false) });
372
+ }
373
+
374
+ const SelectScroll = e => {
375
+ e.persist();
376
+ const { target } = e;
377
+ const totalPage = Math.ceil(itemsTotal / pageSize)
378
+ // 判断是否滑动到底部
379
+ const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
380
+ // 判断数据是否还没有加载到了最后一页
381
+ const canPageAdd = scrollPage < totalPage
382
+ if (isTouchGround && canPageAdd) {
383
+ const nextScrollPage = scrollPage + 1;
384
+ setScrollPage(nextScrollPage);
385
+ getData({ currentPage: nextScrollPage }); // 调用api方法
386
+ }
387
+
388
+ //判断是否滑动到顶部
389
+ const isTouchTop = target.scrollTop === 0 // <=0
390
+ // 判断数据是否到第一页
391
+ const canPageJian = scrollPage > 1
392
+ if (isTouchTop && canPageJian) {
393
+ const preScrollPage = scrollPage - 1;
394
+ setScrollPage(preScrollPage);
395
+ getData({ currentPage: preScrollPage }); // 调用api方法
396
+ }
397
+ }
398
+
399
+ useEffect(() => {
400
+ Promise.all([
401
+ loadSelectSource(`/items/brand/queryBrandList`, {
402
+ pageSize: 5000,
403
+ currentPage: 1,
404
+ 'ctl-withAuth': true
405
+ }),
406
+ loadSelectSource(`/items/category/queryCategoryTree`, {
407
+ pageSize: 5000,
408
+ currentPage: 1,
409
+ }),
410
+ ]).then((x: any)=>{
411
+ formatSource(x,0, 2, tableSearchForm,['id','name'])
412
+ formatTreeDataSource(x,1, 3, tableSearchForm)
413
+ })
414
+ }, [])
415
+
416
+ useEffect(() => {
417
+ if (value) {
418
+ setPopValue(value);
419
+ }
420
+ }, [value]);
421
+
422
+ useEffect(() => {
423
+ makeUniqueValue();
424
+ }, [sourceName])
425
+
426
+ const showModal = () => {
427
+ // getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
428
+ setIsModalVisible(true);
429
+ // 回显
430
+ if (value) {
431
+ if (selectMode) {
432
+ setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
433
+ setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
434
+ setIndeterminate(!!value.length && value.length < itemsTotal);
435
+ setCheckedAll(itemsTotal && value.length === itemsTotal);
436
+ // 需清空数据
437
+ if (!value.length) {
438
+ setDoubleArr([])
439
+ }
440
+ } else {
441
+ setSelectedRowKeys(labelInValue ? [value.key] : [value])
442
+ setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
443
+ }
444
+ }
445
+
446
+ setTimeout(() => {
447
+ document.getElementById("first-query")?.focus()
448
+ }, 50)
449
+ };
450
+
451
+ const handleShowModal = () => {
452
+ if(beforeShowModal) {
453
+ beforeShowModal(popvalue).then(res => {
454
+ showModal()
455
+ }).catch(Error => {
456
+ message.warning(Error)
457
+ })
458
+ } else {
459
+ showModal()
460
+ }
461
+ }
462
+
463
+ const handleSelectOver = (selectedValue: any) => {
464
+ if (selectedValue?.length) {
465
+ formaData(selectedValue);
466
+ // 解决选择最后1页的sku,返回后,不显示名称问题
467
+ const source = _.uniqBy(items.concat(selectedValue), 'value')
468
+ ctx?.form?.setFieldSource(resultSourceKey, source)
469
+ setItems(source)
470
+ }
471
+ }
472
+
473
+ const handleLoading = (isContinue,flag) => {
474
+ isContinue ? setConfirmContinueLoading(flag) : setConfirmLoading(flag);
475
+ }
476
+
477
+ const handleOk = (isContinue) => {
478
+ if(!popvalue.length) {
479
+ message.warning('至少选中一条数据')
480
+ return;
481
+ }
482
+ // handleSelectOver(popvalue)
483
+ if(onSaveCallback) {
484
+ handleLoading(isContinue,true)
485
+ onSaveCallback(popvalue).then(res => {
486
+ if(true) {
487
+ message.success('保存成功')
488
+ deleteSelectRows();
489
+ document.getElementById('first-query')?.focus()
490
+ !isContinue && handleCancel();
491
+ } else {
492
+ }
493
+ handleLoading(isContinue,false)
494
+ }).catch(Error => {
495
+ message.error(Error);
496
+ handleLoading(isContinue,false)
497
+ })
498
+ } else {
499
+ !isContinue && handleCancel();
500
+ }
501
+ };
502
+
503
+ const formaData = (value) => {
504
+ if (labelInValue) {
505
+ const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
506
+ onChange(selectMode ? formatResult : formatResult[0])
507
+ } else {
508
+ const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
509
+ onChange(formatResult)
510
+ }
511
+ };
512
+
513
+ const handleCancel = () => {
514
+ form.resetFields();
515
+ setTableFormParams({});
516
+ setIsModalVisible(false);
517
+ setTableData([])
518
+ // if (selectMode) {
519
+ // run();
520
+ // }
521
+ };
522
+
523
+ const onSearchChange = (e) => {
524
+ setSearchValue(e.target.value);
525
+ run();
526
+ }
527
+
528
+ const onSearchBlur = () => {
529
+ setSearchValue('')
530
+ run();
531
+ }
532
+
533
+ const onSearchTable = () => {
534
+ const params = form.getFieldsValue();
535
+ setTableFormParams(params);
536
+ getData({ ...params, pageSize: tableInitPageSize }, 2)
537
+ if (selectMode) {
538
+ getData(params)
539
+ }
540
+ }
541
+
542
+ const onResetTable = () => {
543
+ form.resetFields();
544
+ setTableFormParams({});
545
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
546
+ }
547
+
548
+ const handleTableChange = (pagination) => {
549
+ getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
550
+ }
551
+
552
+ // 扁平化二维数组的方法
553
+ const mapRows = params => {
554
+ var res = [];
555
+ for (var i = 0; i < params.length; i++) {
556
+ if (Array.isArray(params[i])) {
557
+ // 去重
558
+ res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
559
+ } else {
560
+ res.push(params[i]);
561
+ // 去重
562
+ res = _.uniqBy(res, 'value')
563
+ }
564
+ }
565
+ return res.filter(Boolean); //去掉undefined的情况
566
+ };
567
+
568
+ const onChangeSelectedKeys = (selectKeys, selectRows) => {
569
+ if(selectKeys.length - selectedRowKeys.length > 0) {
570
+ if (selectKeys.length - selectedRowKeys.length === 1) {
571
+ selectRows[selectRows.length -1]['needFocus'] = true;
572
+ } else {
573
+ selectRows[selectedRowKeys.length]['needFocus'] = true;
574
+ }
575
+ }
576
+ setPopValue(selectRows);
577
+ setSelectedRowKeys(selectKeys)
578
+ // setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
579
+ // setCheckedAll(filterRows.length === tablePagination?.total);
580
+ }
581
+
582
+ // 生成唯一值
583
+ const makeUniqueValue = () => {
584
+ const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
585
+ setUniqueValue(generateUnitKey);
586
+ return generateUnitKey;
587
+ }
588
+
589
+ const rowSelection = {
590
+ type: 'checkbox',
591
+ selectedRowKeys,
592
+ preserveSelectedRowKeys: true,
593
+ onChange: (sks, srs) => {
594
+ onChangeSelectedKeys(sks, srs)
595
+ },
596
+ getCheckboxProps: () => ({
597
+ disabled: selectProps?.disabled || props?.disabled,
598
+ }),
599
+ };
600
+
601
+ const onDoubleClickSelect = (e, record) => {
602
+ if (!selectMode) {
603
+ const srs = [JSON.parse(JSON.stringify(record))]
604
+ const sks = srs.map((i: any) => i.value)
605
+ onChangeSelectedKeys(sks, srs)
606
+ }
607
+ }
608
+
609
+ const themeColor = { color: '#005CFF' }
610
+
611
+ const formItem = (list) => {
612
+ if (isModalVisible && list?.length) {
613
+ return list.map((i: any, index) => {
614
+ if (i?.type === 'select' || i?.field?.type === 'select') {
615
+ return (
616
+ <Form.Item name={i.name} label={i.label} key={i.name}>
617
+ <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}>
618
+ {i?.initialSource?.length && i?.initialSource.map((m: any) => (
619
+ <Option value={m.value} key={m.value}>{m.text}</Option>
620
+ ))}
621
+ </Select>
622
+ </Form.Item>
623
+ )
624
+ }
625
+
626
+ if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
627
+ return (
628
+ <Form.Item name={i.name} label={i.label} key={i.name}>
629
+ <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}></TreeSelect>
630
+ </Form.Item>
631
+ )
632
+ }
633
+
634
+ if (i?.type === 'BusinessSearchSelect' || i?.field?.type === 'BusinessSearchSelect') {
635
+ return (
636
+ <div>
637
+ <Form.Item name={i.name} label={i.label} key={i.name}>
638
+ <BusinessSearchSelect {...i.field.props} />
639
+ </Form.Item>
640
+ </div>
641
+ )
642
+ }
643
+
644
+ if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
645
+ return (
646
+ <div>
647
+ <Form.Item name={i.name} label={i.label} key={i.name}>
648
+ <QueryMutipleInput onValueChange={(value) => {
649
+ form.setFieldsValue({
650
+ [i.name]: value
651
+ })
652
+ }} />
653
+ </Form.Item>
654
+ </div>
655
+ );
656
+ }
657
+
658
+ // 默认type是input
659
+ return (
660
+ <Form.Item name={i.name} label={i.label} key={i.name}>
661
+ <Input id={index === 0 ? "first-query" : 'index'} style={{ width: '100%' }} onKeyDown={(e) => {
662
+ if (e.keyCode === 13) {
663
+ onSearchTable()
664
+ }
665
+ }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} />
666
+ </Form.Item>
667
+ )
668
+ })
669
+ } else {
670
+ return null
671
+ }
672
+ }
673
+
674
+ const maxTagPlaceholder = (selectedValues) => {
675
+ const onClose = (e: any, item: any) => {
676
+ e.preventDefault();
677
+ 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)
678
+ onChange(newValue);
679
+ }
680
+ return (
681
+ <Tooltip title={selectedValues.map((i: any) => (
682
+ <Tag
683
+ closable={true}
684
+ onClose={(e) => onClose(e, i)}
685
+ style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
686
+ >
687
+ {i.label}
688
+ </Tag>
689
+ ))}>
690
+ {`+ ${selectedValues?.length}`}
691
+ </Tooltip>
692
+ )
693
+ }
694
+
695
+ const deleteSelectRows = () => {
696
+ setPopValue([])
697
+ setSelectedRowKeys([])
698
+ }
699
+
700
+ const deleteRecord = (record) => {
701
+ setPopValue(popvalue.filter(item => item.skuCode !== record.skuCode))
702
+ setSelectedRowKeys([...selectedRowKeys.filter(item => item !== record.skuCode)])
703
+ }
704
+
705
+ let inputIndex = 0;
706
+ let selectColumns = [... modalTableProps.selectColumn.map(item => {
707
+ const inputLength = modalTableProps.selectColumn.filter(item => item.isInputItem).length
708
+ const currentIndex = inputIndex
709
+
710
+ if (item.isInputItem) {
711
+ inputIndex++;
712
+ return {
713
+ ...item,
714
+ render: (text, record, index) => {
715
+ // let
716
+ if(record.needFocus === true && currentIndex === 0) {
717
+
718
+ }
719
+ return (
720
+ <InputNumber
721
+ defaultValue={text || ''}
722
+ min={0}
723
+ autoFocus={record.needFocus}
724
+ keyboard={false}
725
+ onChange={(value) => {
726
+ record[item.dataIndex] = value
727
+ }}
728
+ // onFocus={(e)=> {
729
+ // let dom1 = e.currentTarget;
730
+ // dom1.setSelectionRange(100, 0);
731
+ // dom1.select(text);
732
+ // }}
733
+ onKeyDown={(e) => {
734
+ if(e.keyCode === 13 && e.ctrlKey) {
735
+ handleOk(true)
736
+ document.getElementById("first-query")?.focus()
737
+ }
738
+ if(e.keyCode === 8 && e.ctrlKey) {
739
+ message.success('删除当前行')
740
+ e.stopPropagation();
741
+ e.preventDefault();
742
+ let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
743
+ if (dom) {
744
+ dom.select();
745
+ dom.focus();
746
+ dom.scrollIntoView(false)
747
+ }
748
+ dom = null
749
+ deleteRecord(record, popvalue);
750
+ }
751
+ if (e.keyCode === 37 && e.shiftKey) { // 左滑动
752
+ e.stopPropagation();
753
+ e.preventDefault();
754
+ let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
755
+ if (dom) {
756
+ dom.select();
757
+ dom.focus();
758
+ dom.scrollIntoView(false)
759
+ }
760
+ dom = null
761
+ }
762
+ if (e.keyCode === 39 && e.shiftKey) { // 右滑
763
+ e.stopPropagation();
764
+ e.preventDefault();
765
+ let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
766
+ if (dom) {
767
+ dom.select();
768
+ dom.focus();
769
+ dom.scrollIntoView(false)
770
+ }
771
+ dom = null
772
+ }
773
+ if (e.keyCode === 40) {
774
+ e.stopPropagation();
775
+ e.preventDefault();
776
+ let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
777
+ if (dom) {
778
+ dom.select();
779
+ dom.focus();
780
+ dom.scrollIntoView(false)
781
+ }
782
+ dom = null
783
+ } else if (e.keyCode === 38) {
784
+ e.stopPropagation();
785
+ e.preventDefault();
786
+ let dom1 = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
787
+ if (dom1) {
788
+ // dom1.value=""
789
+ // dom1.setSelectionRange(100, 0);
790
+ dom1.select();
791
+ dom1.focus();
792
+ dom1.scrollIntoViewIfNeeded(false)
793
+ // dom1.value=record['count']
794
+ }
795
+ dom1 = null
796
+ } else if (e.keyCode === 9 && index === selectedRowKeys.length - 1 && currentIndex === inputLength - 1) {
797
+ e.stopPropagation();
798
+ e.preventDefault();
799
+ }
800
+ }}
801
+ />
802
+ );
803
+ },
804
+ }
805
+ }
806
+
807
+ return item
808
+ }), {
809
+ title: '操作',
810
+ width: 50,
811
+ fixed: 'right',
812
+ render: (text, record, index) => {
813
+ return (
814
+ <span style={{cursor: 'pointer', color: '#005CFF' }} onClick={() => {
815
+ deleteRecord(record)
816
+ }} type={"text"}>删除</span>
817
+ )
818
+ }
819
+ },]
820
+
821
+ const handleResize =
822
+ (index) =>
823
+ (e, { size }) => {
824
+ setTableColumns((columns: any) => {
825
+ let newColumns = [...columns];
826
+ newColumns[index] = {
827
+ ...newColumns[index],
828
+ width: size.width,
829
+ };
830
+ return [...newColumns];
831
+ });
832
+ };
833
+
834
+ return (
835
+ <div className={'add_select'}>
836
+ <div className="add_select_show" id={`add_select_div_${uniqueValue}`}>
837
+ <Button onClick={handleShowModal} type="primary">
838
+ {buttonText}
839
+ </Button>
840
+ </div>
841
+ {needModalTable && isModalVisible && (
842
+ <Modal
843
+ width='1200px'
844
+ style={{ top: 20 }}
845
+ bodyStyle={{ padding: '0px' }}
846
+ // title={modalTableProps?.modalTableTitle}
847
+ visible={isModalVisible}
848
+ closable={false}
849
+ onCancel={handleCancel}
850
+ footer={selectMode ? [
851
+ <Button key="back" onClick={handleCancel}>
852
+ 取消
853
+ </Button>,
854
+ <Button
855
+ key="submit"
856
+ style={{color: '#005CFF', borderColor: '#005CFF'}}
857
+ onClick={() => {handleOk(true)}}
858
+ loading={confirmContinueLoading}
859
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
860
+ >
861
+ 保存并继续
862
+ </Button>,
863
+ <Button
864
+ key="submit"
865
+ type="primary"
866
+ onClick={() => {handleOk(false)}}
867
+ loading={confirmLoading}
868
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
869
+ >
870
+ 确定
871
+ </Button>,
872
+ ] : null}
873
+ >
874
+ <div>
875
+ <div className='add_select_header'>
876
+ {modalTableProps?.modalTableTitle}
877
+ <span><span>*</span> &nbsp;快捷键:【Tab】-跳格切换;【Shift+←、→】-当前行左、右移动;【 ↑、↓】-当前列上、下移动;【ctrl+Enter】-保存并继续;【ctrl+Delete】-删除当前行;</span>
878
+ <span className='add_select_header_close'><CloseCircleOutlined style={{fontSize: '20px'}} onClick={handleCancel} /></span>
879
+ </div>
880
+ <div className={'add_select_wrapper'}>
881
+ <div className={caretLeftFlag ? 'add_select_wrapper_left' : 'add_select_wrapper_left1'}>
882
+ <div className={'select_list_columns'}>
883
+ <div className={'select_list_columns_formItems'}>
884
+ <Form form={form} layout='vertical' key='modalForm'>
885
+ {formItem(tableSearchForm)}
886
+ </Form>
887
+ </div>
888
+ </div>
889
+ <div className={'select_list_searchButton'}>
890
+ <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
891
+ <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
892
+ </div>
893
+ </div>
894
+ <div className={caretLeftFlag ? 'add_select_wrapper_right' : 'add_select_wrapper_right1'}>
895
+ <div>
896
+ <div className={'select_list_selectTips'}>
897
+ <div style={{ marginLeft: 8 }}>搜索结果共&nbsp;<span style={themeColor}>{tablePagination?.total || 0}</span>&nbsp;项{selectMode ? <span>, 本次已选&nbsp;<span style={themeColor}>{selectedRowKeys?.length || 0}</span>&nbsp;项</span> : ''}</div>
898
+ </div>
899
+ <Table
900
+ size='small'
901
+ rowSelection={rowSelection}
902
+ columns={tableColumns}
903
+ dataSource={tableData}
904
+ pagination={tablePagination}
905
+ loading={fetching}
906
+ onChange={handleTableChange}
907
+ rowKey={mappingValueField}
908
+ rowClassName={'row-class'}
909
+ scroll={{ y: 500 }}
910
+ components={{
911
+ header: {
912
+ cell: ResizeableTitle,
913
+ },
914
+ }}
915
+ />
916
+ </div>
917
+ </div>
918
+ {/* <div>
919
+ <Table
920
+ size='small'
921
+ columns={modalTableProps?.tableColumns}
922
+ dataSource={mapRows(doubleArr)}
923
+ rowKey={mappingValueField}
924
+ scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
925
+ onRow={record => {
926
+ return {
927
+ onDoubleClick: event => onDoubleClickSelect(event, record),
928
+ };
929
+ }}
930
+ />
931
+ </div> */}
932
+ </div>
933
+ <div className={'add_select_wrapper_select'}>
934
+ <div className={'select_list_selectTips'}>
935
+ <div style={{ marginLeft: 8 }}><span>本次已选&nbsp;<span style={themeColor}>{selectedRowKeys?.length || 0}</span>&nbsp;项</span></div>
936
+ <div style={{ marginRight: 8 }}><span onClick={deleteSelectRows} style={{ ...themeColor, cursor: 'pointer' }}>清空所选商品</span></div>
937
+ </div>
938
+ <Table
939
+ size='small'
940
+ // rowSelection={rowSelection}
941
+ columns={selectColumns}
942
+ dataSource={popvalue}
943
+ pagination={false}
944
+ // onChange={handleTableChange}
945
+ rowKey={mappingValueField}
946
+ rowClassName={'row-class'}
947
+ scroll={{ y: 500 }}
948
+ onRow={record => {
949
+ return {
950
+ onDoubleClick: event => onDoubleClickSelect(event, record),
951
+ };
952
+ }}
953
+ />
954
+ </div>
955
+ </div>
956
+ </Modal>
957
+ )}
958
+ </div>
959
+ );
960
+ };
961
+
962
+ export default AddSelect;