@bit-sun/business-component 2.2.26 → 2.2.28

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