@bit-sun/business-component 2.1.22 → 2.1.24

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