@bit-sun/business-component 2.1.17 → 2.1.18

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