@bit-sun/business-component 2.4.13 → 2.4.15-beta

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