@bit-sun/business-component 2.3.19 → 2.3.21

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