@bit-sun/business-component 2.2.35 → 2.2.36

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