@bit-sun/business-component 2.3.21 → 2.3.23

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