@bit-sun/business-component 2.2.21 → 2.2.23

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