@bit-sun/business-component 2.2.13 → 2.2.15

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