@bit-sun/business-component 2.3.22-beta1 → 2.3.22-beta11

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 (235) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +179 -179
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/components/Business/AddSelectBusiness/index.d.ts +4 -3
  9. package/dist/components/Business/BsLayouts/Components/AllFunc/drawContent.d.ts +2 -1
  10. package/dist/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.d.ts +1 -1
  11. package/dist/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.d.ts +2 -2
  12. package/dist/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.d.ts +2 -1
  13. package/dist/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.d.ts +2 -1
  14. package/dist/components/Business/BsLayouts/Components/GlobalHeader/index.d.ts +2 -1
  15. package/dist/components/Business/BsLayouts/Components/RightContent/LoginModal.d.ts +2 -1
  16. package/dist/components/Business/BsLayouts/index.d.ts +1 -1
  17. package/dist/components/Business/BsLayouts/service.d.ts +1 -1
  18. package/dist/components/Business/BsSulaQueryTable/SearchItemSetting.d.ts +5 -5
  19. package/dist/components/Business/BsSulaQueryTable/index.d.ts +2 -1
  20. package/dist/components/Business/BsSulaQueryTable/setting.d.ts +5 -5
  21. package/dist/components/Business/BsSulaQueryTable/utils.d.ts +14 -13
  22. package/dist/components/Business/CommodityEntry/index.d.ts +2 -1
  23. package/dist/components/Business/CommonAlert/index.d.ts +2 -1
  24. package/dist/components/Business/CommonGuideWrapper/index.d.ts +3 -3
  25. package/dist/components/Business/DetailPageWrapper/index.d.ts +6 -5
  26. package/dist/components/Business/HomePageWrapper/index.d.ts +2 -1
  27. package/dist/components/Business/JsonQueryTable/components/FieldsModifyModal.d.ts +2 -1
  28. package/dist/components/Business/JsonQueryTable/components/FieldsSettingsTable.d.ts +2 -1
  29. package/dist/components/Business/JsonQueryTable/components/Formula.d.ts +2 -1
  30. package/dist/components/Business/JsonQueryTable/components/MaintainOptions.d.ts +2 -1
  31. package/dist/components/Business/JsonQueryTable/drawer/index.d.ts +2 -1
  32. package/dist/components/Business/StateFlow/index.d.ts +2 -1
  33. package/dist/components/Business/TreeSearchSelect/index.d.ts +1 -1
  34. package/dist/components/Business/columnSettingTable/columnSetting.d.ts +5 -5
  35. package/dist/components/Business/columnSettingTable/index.d.ts +2 -2
  36. package/dist/components/Business/columnSettingTable/sulaSettingTable.d.ts +2 -2
  37. package/dist/components/Business/columnSettingTable/utils.d.ts +2 -1
  38. package/dist/components/Functional/AddSelect/index.d.ts +2 -1
  39. package/dist/components/Functional/DataImport/index.d.ts +3 -3
  40. package/dist/components/Functional/DataValidation/index.d.ts +3 -3
  41. package/dist/components/Functional/ExportFunctions/ExportIcon/index.d.ts +2 -1
  42. package/dist/components/Functional/QueryMutipleInput/index.d.ts +2 -1
  43. package/dist/components/Functional/TreeSearchSelect/index.d.ts +2 -1
  44. package/dist/components/Solution/RuleComponent/Formula.d.ts +2 -1
  45. package/dist/components/Solution/RuleComponent/services.d.ts +1 -1
  46. package/dist/index.esm.js +78 -54
  47. package/dist/index.js +78 -54
  48. package/dist/plugin/TableColumnSetting/index.d.ts +5 -5
  49. package/dist/utils/LocalstorageUtils.d.ts +5 -0
  50. package/docs/index.md +21 -21
  51. package/lib/assets/drag.svg +17 -17
  52. package/lib/assets/exportFail.svg +37 -37
  53. package/lib/assets/exportProcessing.svg +28 -28
  54. package/lib/assets/exportSuccess.svg +34 -34
  55. package/lib/assets/label_icon_bottom.svg +25 -25
  56. package/lib/assets/upExport.svg +22 -22
  57. package/package.json +78 -78
  58. package/src/assets/32.svg +27 -27
  59. package/src/assets/addIcon.svg +17 -17
  60. package/src/assets/allfunc.svg +27 -27
  61. package/src/assets/arrowRight.svg +24 -24
  62. package/src/assets/btn-delete.svg +29 -29
  63. package/src/assets/btn-edit.svg +19 -19
  64. package/src/assets/btn-more.svg +17 -17
  65. package/src/assets/btn-submit.svg +19 -19
  66. package/src/assets/caidan.svg +11 -11
  67. package/src/assets/close.svg +26 -26
  68. package/src/assets/drag.svg +17 -17
  69. package/src/assets/exportFail.svg +37 -37
  70. package/src/assets/exportProcessing.svg +28 -28
  71. package/src/assets/exportSuccess.svg +34 -34
  72. package/src/assets/fixed-left-active.svg +11 -11
  73. package/src/assets/fixed-left.svg +15 -15
  74. package/src/assets/fixed-right-active.svg +11 -11
  75. package/src/assets/fixed-right.svg +15 -15
  76. package/src/assets/guanbi.svg +15 -15
  77. package/src/assets/icon-quanping.svg +15 -15
  78. package/src/assets/icon-shezhi.svg +17 -17
  79. package/src/assets/label_icon_bottom.svg +25 -25
  80. package/src/assets/list-no-img.svg +21 -21
  81. package/src/assets/morentouxiang-32.svg +23 -23
  82. package/src/assets/scanning.svg +24 -24
  83. package/src/assets/upExport.svg +22 -22
  84. package/src/common/ENUM.ts +41 -41
  85. package/src/components/Business/AddSelectBusiness/index.md +162 -162
  86. package/src/components/Business/AddSelectBusiness/index.tsx +1060 -1060
  87. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  88. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  89. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  90. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  91. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  92. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  93. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  94. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  95. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  96. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  97. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  98. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  99. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  100. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  101. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  102. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  103. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +155 -155
  104. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  105. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  106. package/src/components/Business/BsLayouts/index.less +79 -79
  107. package/src/components/Business/BsLayouts/index.tsx +1484 -1484
  108. package/src/components/Business/BsLayouts/service.ts +10 -10
  109. package/src/components/Business/BsLayouts/utils.tsx +203 -203
  110. package/src/components/Business/BsSulaQueryTable/SearchItemSetting.tsx +565 -564
  111. package/src/components/Business/BsSulaQueryTable/index.less +221 -221
  112. package/src/components/Business/BsSulaQueryTable/index.tsx +532 -535
  113. package/src/components/Business/BsSulaQueryTable/setting.tsx +855 -852
  114. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  115. package/src/components/Business/BsSulaQueryTable/utils.tsx +690 -690
  116. package/src/components/Business/CommodityEntry/index.md +70 -70
  117. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  118. package/src/components/Business/CommonAlert/index.tsx +23 -23
  119. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  120. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  121. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  122. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  123. package/src/components/Business/DetailPageWrapper/index.tsx +313 -313
  124. package/src/components/Business/DetailPageWrapper/utils.tsx +100 -100
  125. package/src/components/Business/HomePageWrapper/index.less +33 -33
  126. package/src/components/Business/HomePageWrapper/index.md +45 -45
  127. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  128. package/src/components/Business/JsonQueryTable/components/FieldsModifyModal.tsx +824 -824
  129. package/src/components/Business/JsonQueryTable/components/FieldsSettingsTable.tsx +205 -205
  130. package/src/components/Business/JsonQueryTable/components/Formula.tsx +205 -205
  131. package/src/components/Business/JsonQueryTable/components/MaintainOptions.tsx +127 -127
  132. package/src/components/Business/JsonQueryTable/configButton/index.js +20 -20
  133. package/src/components/Business/JsonQueryTable/configTree/component/compactArrayView.js +25 -25
  134. package/src/components/Business/JsonQueryTable/configTree/component/compactObjectView.js +30 -30
  135. package/src/components/Business/JsonQueryTable/configTree/index.js +82 -82
  136. package/src/components/Business/JsonQueryTable/configTree/index.less +44 -44
  137. package/src/components/Business/JsonQueryTable/configTree/parser/highlight.js +57 -57
  138. package/src/components/Business/JsonQueryTable/configTree/parser/index.js +124 -124
  139. package/src/components/Business/JsonQueryTable/configTree/render/iconRender.js +29 -29
  140. package/src/components/Business/JsonQueryTable/configTree/render/nameRender.js +22 -22
  141. package/src/components/Business/JsonQueryTable/configTree/treeNode.js +116 -116
  142. package/src/components/Business/JsonQueryTable/drawer/index.tsx +12 -12
  143. package/src/components/Business/JsonQueryTable/function.ts +62 -62
  144. package/src/components/Business/JsonQueryTable/index.less +16 -16
  145. package/src/components/Business/JsonQueryTable/index.md +328 -328
  146. package/src/components/Business/JsonQueryTable/index.tsx +535 -535
  147. package/src/components/Business/JsonQueryTable/jsonEditor/index.js +346 -346
  148. package/src/components/Business/JsonQueryTable/jsonEditor/index.less +22 -22
  149. package/src/components/Business/JsonQueryTable/jsonEditor/lint/basicType.js +147 -147
  150. package/src/components/Business/JsonQueryTable/jsonEditor/lint/index.js +389 -389
  151. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/actions.js +118 -118
  152. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/dependency.js +22 -22
  153. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/index.js +21 -21
  154. package/src/components/Business/JsonQueryTable/jsonEditor/suggestions/request.js +65 -65
  155. package/src/components/Business/JsonQueryTable/static.ts +390 -390
  156. package/src/components/Business/SearchSelect/BusinessUtils.ts +1762 -1762
  157. package/src/components/Business/SearchSelect/common.ts +75 -75
  158. package/src/components/Business/SearchSelect/index.md +1329 -1329
  159. package/src/components/Business/SearchSelect/index.tsx +55 -55
  160. package/src/components/Business/SearchSelect/utils.ts +100 -100
  161. package/src/components/Business/StateFlow/index.less +130 -130
  162. package/src/components/Business/StateFlow/index.md +60 -60
  163. package/src/components/Business/StateFlow/index.tsx +29 -29
  164. package/src/components/Business/TreeSearchSelect/index.md +156 -156
  165. package/src/components/Business/TreeSearchSelect/index.tsx +33 -33
  166. package/src/components/Business/TreeSearchSelect/utils.ts +75 -75
  167. package/src/components/Business/columnSettingTable/columnSetting.tsx +766 -764
  168. package/src/components/Business/columnSettingTable/index.less +247 -247
  169. package/src/components/Business/columnSettingTable/index.md +357 -357
  170. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  171. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  172. package/src/components/Business/columnSettingTable/utils.tsx +71 -71
  173. package/src/components/Business/moreTreeTable/FixedScrollBar.tsx +87 -87
  174. package/src/components/Business/moreTreeTable/hooks/useSticky.ts +21 -21
  175. package/src/components/Business/moreTreeTable/index.less +99 -99
  176. package/src/components/Business/moreTreeTable/index.md +448 -448
  177. package/src/components/Business/moreTreeTable/index.tsx +387 -387
  178. package/src/components/Business/moreTreeTable/utils.ts +126 -126
  179. package/src/components/Functional/AddSelect/helps.ts +79 -79
  180. package/src/components/Functional/AddSelect/index.less +367 -367
  181. package/src/components/Functional/AddSelect/index.md +155 -155
  182. package/src/components/Functional/AddSelect/index.tsx +1170 -1170
  183. package/src/components/Functional/BillEntry/index.less +371 -371
  184. package/src/components/Functional/BillEntry/index.md +39 -39
  185. package/src/components/Functional/BillEntry/index.tsx +772 -772
  186. package/src/components/Functional/BsAntdSula/BsCascader/index.md +62 -62
  187. package/src/components/Functional/BsAntdSula/BsCascader/index.tsx +178 -178
  188. package/src/components/Functional/BsAntdSula/index.ts +2 -2
  189. package/src/components/Functional/DataImport/index.less +63 -63
  190. package/src/components/Functional/DataImport/index.md +44 -44
  191. package/src/components/Functional/DataImport/index.tsx +695 -695
  192. package/src/components/Functional/DataValidation/index.less +63 -63
  193. package/src/components/Functional/DataValidation/index.md +39 -39
  194. package/src/components/Functional/DataValidation/index.tsx +687 -687
  195. package/src/components/Functional/EllipsisTooltip/index.d.ts +5 -5
  196. package/src/components/Functional/EllipsisTooltip/index.js +36 -36
  197. package/src/components/Functional/EllipsisTooltip/index.md +30 -30
  198. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  199. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  200. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  201. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  202. package/src/components/Functional/QueryMutipleInput/index.tsx +128 -128
  203. package/src/components/Functional/SearchSelect/index.less +115 -115
  204. package/src/components/Functional/SearchSelect/index.md +141 -141
  205. package/src/components/Functional/SearchSelect/index.tsx +879 -879
  206. package/src/components/Functional/SearchSelect/utils.ts +3 -3
  207. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  208. package/src/components/Functional/TreeSearchSelect/index.tsx +199 -199
  209. package/src/components/Solution/RuleComponent/Formula.tsx +335 -335
  210. package/src/components/Solution/RuleComponent/index.d.ts +29 -29
  211. package/src/components/Solution/RuleComponent/index.js +2032 -2032
  212. package/src/components/Solution/RuleComponent/index.less +230 -230
  213. package/src/components/Solution/RuleComponent/renderSpecificAction.js +99 -99
  214. package/src/components/Solution/RuleComponent/ruleFiled.js +2107 -2107
  215. package/src/components/Solution/RuleComponent/services.ts +13 -13
  216. package/src/components/Solution/RuleComponent/util.js +139 -139
  217. package/src/index.ts +38 -38
  218. package/src/plugin/TableColumnSetting/index.less +247 -247
  219. package/src/plugin/TableColumnSetting/index.md +50 -50
  220. package/src/plugin/TableColumnSetting/index.tsx +726 -724
  221. package/src/plugin/TableColumnSetting/utils.ts +19 -19
  222. package/src/styles/bsDefault.less +1890 -1912
  223. package/src/utils/CheckOneUser/index.md +39 -39
  224. package/src/utils/CheckOneUser/index.ts +51 -51
  225. package/src/utils/LocalstorageUtils.ts +114 -95
  226. package/src/utils/TableUtils.tsx +18 -18
  227. package/src/utils/checkUtils.ts +39 -39
  228. package/src/utils/enumConfig.ts +11 -11
  229. package/src/utils/getFormMode.js +12 -12
  230. package/src/utils/index.ts +4 -4
  231. package/src/utils/requestUtils.ts +42 -34
  232. package/src/utils/serialize.js +7 -7
  233. package/src/utils/utils.ts +212 -212
  234. package/tsconfig.json +29 -29
  235. package/typings.d.ts +4 -4
@@ -1,1170 +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, 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;
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: '#02B56E' }} 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: '#02B56E' }
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: '#02B56E', borderColor: '#02B56E'}}
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;