@bit-sun/business-component 2.0.37 → 2.0.39-alpha.0

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 (153) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -4
  3. package/.gitlab-ci.yml +174 -174
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +77 -74
  7. package/README.md +27 -27
  8. package/dist/components/Business/BsLayouts/Components/AllFunc/drawContent.d.ts +4 -0
  9. package/dist/components/Business/BsLayouts/Components/AllFunc/index.d.ts +4 -0
  10. package/dist/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.d.ts +4 -0
  11. package/dist/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.d.ts +17 -0
  12. package/dist/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.d.ts +30 -0
  13. package/dist/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.d.ts +3 -0
  14. package/dist/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.d.ts +2 -0
  15. package/dist/components/Business/BsLayouts/Components/CustomerMenu/index.d.ts +4 -0
  16. package/dist/components/Business/BsLayouts/Components/GlobalHeader/index.d.ts +4 -0
  17. package/dist/components/Business/BsLayouts/Components/RightContent/LoginModal.d.ts +2 -0
  18. package/dist/components/Business/BsLayouts/Components/RightContent/index.d.ts +8 -0
  19. package/dist/components/Business/BsLayouts/Components/SearchFunc/index.d.ts +8 -0
  20. package/dist/components/Business/BsLayouts/index.d.ts +18 -0
  21. package/dist/components/Business/BsLayouts/service.d.ts +1 -0
  22. package/dist/components/Business/BsLayouts/utils.d.ts +22 -0
  23. package/dist/components/Business/DetailPageWrapper/utils.d.ts +1 -2
  24. package/dist/index.d.ts +4 -0
  25. package/dist/index.esm.js +11703 -44
  26. package/dist/index.js +11678 -11
  27. package/dist/utils/enumConfig.d.ts +10 -0
  28. package/dist/utils/utils.d.ts +2 -1
  29. package/docs/index.md +21 -21
  30. package/lib/assets/drag.svg +17 -17
  31. package/lib/assets/exportFail.svg +37 -37
  32. package/lib/assets/exportProcessing.svg +28 -28
  33. package/lib/assets/exportSuccess.svg +34 -34
  34. package/lib/assets/label_icon_bottom.svg +25 -25
  35. package/lib/assets/upExport.svg +22 -22
  36. package/package.json +70 -66
  37. package/src/assets/32.svg +28 -0
  38. package/src/assets/addIcon.svg +18 -0
  39. package/src/assets/allfunc.svg +28 -0
  40. package/src/assets/arrowRight.svg +25 -0
  41. package/src/assets/btn-delete.svg +29 -29
  42. package/src/assets/btn-edit.svg +19 -19
  43. package/src/assets/btn-more.svg +17 -17
  44. package/src/assets/btn-submit.svg +19 -19
  45. package/src/assets/caidan.svg +12 -0
  46. package/src/assets/close.svg +26 -26
  47. package/src/assets/closeicon.png +0 -0
  48. package/src/assets/drag.svg +17 -17
  49. package/src/assets/exportFail.svg +37 -37
  50. package/src/assets/exportProcessing.svg +28 -28
  51. package/src/assets/exportSuccess.svg +34 -34
  52. package/src/assets/fixed-left-active.svg +11 -11
  53. package/src/assets/fixed-left.svg +15 -15
  54. package/src/assets/fixed-right-active.svg +11 -11
  55. package/src/assets/fixed-right.svg +15 -15
  56. package/src/assets/guanbi.svg +16 -0
  57. package/src/assets/icon-quanping.svg +15 -15
  58. package/src/assets/icon-shezhi.svg +17 -17
  59. package/src/assets/label_icon_bottom.svg +25 -25
  60. package/src/assets/morentouxiang-32.svg +24 -0
  61. package/src/assets/right.png +0 -0
  62. package/src/assets/scanning.svg +24 -24
  63. package/src/assets/upExport.svg +22 -22
  64. package/src/assets/xinglan-icon-out.png +0 -0
  65. package/src/components/Business/AddSelectBusiness/index.md +41 -41
  66. package/src/components/Business/AddSelectBusiness/index.tsx +290 -290
  67. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +112 -0
  68. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -0
  69. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -0
  70. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -0
  71. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +38 -0
  72. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +243 -0
  73. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +385 -0
  74. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +286 -0
  75. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +75 -0
  76. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +171 -0
  77. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +65 -0
  78. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +154 -0
  79. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +73 -0
  80. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +158 -0
  81. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -0
  82. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -0
  83. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +156 -0
  84. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +162 -0
  85. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +76 -0
  86. package/src/components/Business/BsLayouts/index.less +80 -0
  87. package/src/components/Business/BsLayouts/index.tsx +1495 -0
  88. package/src/components/Business/BsLayouts/service.ts +11 -0
  89. package/src/components/Business/BsLayouts/utils.tsx +350 -0
  90. package/src/components/Business/BsSulaQueryTable/index.less +219 -219
  91. package/src/components/Business/BsSulaQueryTable/index.tsx +535 -534
  92. package/src/components/Business/BsSulaQueryTable/setting.tsx +818 -817
  93. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  94. package/src/components/Business/BsSulaQueryTable/utils.tsx +691 -690
  95. package/src/components/Business/CommodityEntry/index.md +70 -70
  96. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  97. package/src/components/Business/CommonAlert/index.tsx +23 -23
  98. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  99. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  100. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  101. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  102. package/src/components/Business/DetailPageWrapper/index.tsx +335 -324
  103. package/src/components/Business/DetailPageWrapper/utils.tsx +101 -111
  104. package/src/components/Business/HomePageWrapper/index.less +33 -33
  105. package/src/components/Business/HomePageWrapper/index.md +45 -45
  106. package/src/components/Business/HomePageWrapper/index.tsx +162 -150
  107. package/src/components/Business/SearchSelect/BusinessUtils.ts +1458 -1457
  108. package/src/components/Business/SearchSelect/common.ts +53 -53
  109. package/src/components/Business/SearchSelect/index.md +1137 -1137
  110. package/src/components/Business/SearchSelect/index.tsx +51 -51
  111. package/src/components/Business/SearchSelect/utils.ts +100 -99
  112. package/src/components/Business/StateFlow/index.less +130 -130
  113. package/src/components/Business/StateFlow/index.md +60 -60
  114. package/src/components/Business/StateFlow/index.tsx +29 -29
  115. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  116. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  117. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  118. package/src/components/Business/columnSettingTable/columnSetting.tsx +763 -762
  119. package/src/components/Business/columnSettingTable/index.less +247 -247
  120. package/src/components/Business/columnSettingTable/index.md +357 -357
  121. package/src/components/Business/columnSettingTable/index.tsx +226 -225
  122. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +234 -233
  123. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  124. package/src/components/Functional/AddSelect/index.less +367 -367
  125. package/src/components/Functional/AddSelect/index.md +122 -122
  126. package/src/components/Functional/AddSelect/index.tsx +962 -962
  127. package/src/components/Functional/BillEntry/index.less +371 -371
  128. package/src/components/Functional/BillEntry/index.md +39 -39
  129. package/src/components/Functional/BillEntry/index.tsx +613 -607
  130. package/src/components/Functional/DataImport/index.less +63 -63
  131. package/src/components/Functional/DataImport/index.md +44 -44
  132. package/src/components/Functional/DataImport/index.tsx +689 -689
  133. package/src/components/Functional/DataValidation/index.less +63 -63
  134. package/src/components/Functional/DataValidation/index.md +38 -38
  135. package/src/components/Functional/DataValidation/index.tsx +681 -681
  136. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  137. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  138. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  139. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  140. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  141. package/src/components/Functional/SearchSelect/index.less +115 -115
  142. package/src/components/Functional/SearchSelect/index.md +141 -141
  143. package/src/components/Functional/SearchSelect/index.tsx +812 -812
  144. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  145. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  146. package/src/index.ts +31 -30
  147. package/src/utils/CheckOneUser/index.md +39 -39
  148. package/src/utils/CheckOneUser/index.ts +51 -51
  149. package/src/utils/enumConfig.ts +10 -0
  150. package/src/utils/requestUtils.ts +33 -32
  151. package/src/utils/utils.ts +52 -22
  152. package/tsconfig.json +29 -29
  153. package/typings.d.ts +4 -4
@@ -1,962 +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
- 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;
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;