@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,896 +1,896 @@
1
- // @ts-nocheck
2
- import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
- import { useDebounceFn } from 'ahooks';
4
- import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
- import { SearchOutlined, CopyOutlined, CaretLeftOutlined } 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 { handleSourceName } from './utils';
12
- import { judgeIsRequestError } from '@/utils/requestUtils';
13
-
14
- const { Option } = Select;
15
-
16
- const SearchSelect = forwardRef((props: any, ref: any) => {
17
- const {
18
- value, // 必传
19
- onChange: onChangeTemp,
20
- selectProps = {},
21
- modalTableProps = {},
22
- labelInValue = false,
23
- requestConfig,
24
- ctx,
25
- sourceName,
26
- needModalTable = true,
27
- getPopupContainer = undefined,
28
- fieldComponent,
29
- selectBusinessType,
30
- } = props;
31
- const {
32
- url,
33
- otherParams,// 默认参数
34
- isMap,
35
- fixedparameter,
36
- fieldValToParam,
37
- fixedparamsDisabled = false,
38
- mappingTextField = 'name',
39
- mappingTextShowKeyField,
40
- mappingValueField = 'code',
41
- mappingTextShowTextField,
42
- init = true,// 是否初始请求
43
- extralHeaders = {},// 额外请求头参数
44
- specialBracket = false,// 是否使用特殊括弧显示选项 【value】text
45
- noNeedSplit = false,// label显示不需要任何特殊化
46
- } = requestConfig || {};
47
- const resultSourceKey = handleSourceName(sourceName || requestConfig?.sourceName || 'supplierCode')
48
-
49
- const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
50
- const initVal = value || (selectMode ? [] : null);
51
- const pageSize = 100 // 下拉框默认分页 条数
52
- const tableInitPageSize = 10 // 弹框默认分页 条数
53
- const currentPage = 1
54
- const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
55
- const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
56
- const currentSelectProps = {
57
- ...selectProps,
58
- // 以下属性不可更改----设计配置项
59
- showSearch: false,
60
- filterOption: false,
61
- allowClear: true,
62
- listHeight: 160,
63
- optionLabelProp: "label",
64
- autoClearSearchValue: false
65
- }
66
- const tableInitPagination = { showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize }
67
-
68
- const [items, setItems] = useState([]);
69
- const [scrollPage, setScrollPage] = useState(1);
70
- const [itemsTotal, setItemsTotal] = useState(0);
71
- const [fetching, setFetching] = useState(false);
72
- const [searchValue, setSearchValue] = useState('');
73
- const [isModalVisible, setIsModalVisible] = useState(false);
74
- const [popvalue, setPopValue] = useState(initVal);
75
- const [uniqueValue, setUniqueValue] = useState(resultSourceKey)
76
- const { run } = useDebounceFn(
77
- (v?: any) => {
78
- // 优化搜索参数 支持传多个
79
- let searchParams = {};
80
- if (typeof selectParamsKey === 'string') {
81
- let selectParamsInitValue = initVal
82
- if (labelInValue) {
83
- selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
84
- } else {
85
- selectParamsInitValue = Array.isArray(initVal) ? initVal.join(',') : initVal
86
- }
87
- searchParams = v ? { [selectParamsInitKey]: selectParamsInitValue } : { [selectParamsKey]: searchValue }
88
- }
89
- if (Array.isArray(selectParamsKey)) {
90
- selectParamsKey.forEach((i: any) => {
91
- searchParams = { ...searchParams, [i]: searchValue }
92
- })
93
- }
94
- // 防抖函数 待定
95
- getData(searchParams)
96
- },
97
- {
98
- wait: 1000,
99
- },
100
- );
101
-
102
- const [form] = Form.useForm();
103
- const [caretLeftFlag, setCaretLeftFlag] = useState(true);
104
- const [tableData, setTableData] = useState([]);
105
- const [tablePagination, setTablePagination] = useState(tableInitPagination)
106
- const [selectedRowKeys, setSelectedRowKeys] = useState([]);
107
- const [selectedRows, setSelectedRows] = useState([]);
108
- const [checkedAll, setCheckedAll] = useState(false)
109
- const [indeterminate, setIndeterminate] = useState(false)
110
- const [tableFormParams, setTableFormParams] = useState({});
111
- const [tooltipVisible, setTooltipVisible] = useState(false);
112
-
113
- useImperativeHandle(ref, () => ({
114
- refreshDataSource: (reset: boolean = false) => {
115
- if (reset) {
116
- if (init) {
117
- run('init');
118
- } else {
119
- setItems([]);
120
- setItemsTotal(0);
121
- }
122
- } else {
123
- run();
124
- }
125
- },
126
- clearDataSource: () => {
127
- setItems([]);
128
- setItemsTotal(0);
129
- },
130
- getTableFormRef: () => form,
131
- // 解决下拉框数据源的问题
132
- getSelectDataSource: () => items,
133
- setSelectDataSource: (list: any, listTotal: number) => {
134
- setItems(list);
135
- setItemsTotal(listTotal);
136
- },
137
- refreshSelectDataSource: () => {
138
- refreshItems()
139
- }
140
- }))
141
-
142
- // 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
143
- const getData = (params = {}, type = 1,callback?: any) => {
144
- if (!requestConfig) return;
145
-
146
- setFetching(true)
147
-
148
- // 处理dependence参数
149
- const fixedParam = {};
150
- if (fixedparameter && fieldValToParam && ctx) {
151
- fixedparameter.forEach((item: any, index: any) => {
152
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
153
- if(fixedParamVal) {
154
- fixedParam[item] = fixedParamVal;
155
- // 解决依赖项在弹窗中回显/更改(如果不能更改,传参fixedparamsDisabled为true即可)
156
- if(type == 2 || type == 3) {
157
- const fixedChangeParamVal = form.getFieldValue(item);
158
- let isDependenceValueChange = false;
159
- let dependenceValue = fixedParamVal;
160
- // 依赖项在弹窗form中更改--①更换依赖值;②去掉依赖值
161
- if(!fixedparamsDisabled) {
162
- isDependenceValueChange =
163
- (fixedChangeParamVal && fixedChangeParamVal !== fixedParamVal)
164
- || (type == 2 && !fixedChangeParamVal);
165
- dependenceValue = isDependenceValueChange ? fixedChangeParamVal : fixedParamVal;
166
- }
167
- fixedParam[item] = dependenceValue;
168
- form.setFieldsValue({ ...form?.getFieldsValue(), [item]: dependenceValue })
169
- if(isDependenceValueChange) {
170
- ctx.form.setFieldValue(fieldValToParam[index],fixedChangeParamVal) // 更改依赖项
171
- ctx.form.setFieldValue(resultSourceKey,null) // 同时清空之前依赖项对应的选择项
172
- refreshItems()
173
- }
174
- }
175
- }
176
- });
177
- }
178
-
179
- // 数组对象处理,对带有特殊标记的name进行处理
180
- for (const key in params) {
181
- if (Object.prototype.hasOwnProperty.call(params, key)) {
182
- const element = params[key];
183
- if (element && key.indexOf('*number*') >= 0) {
184
- const dataParams = key.split('*number*');
185
- dataParams.forEach((value, index) => {
186
- params[value] = element[index];
187
- });
188
- delete params[key];
189
- } else if (element && key.indexOf('*address*') >= 0) {
190
- const dataParams = key.split('*address*');
191
- dataParams.forEach((value, index) => {
192
- params[value] = element.PCDCode[index];
193
- });
194
- delete params[key];
195
- } else if (element && key.indexOf('*costType*') >= 0) {
196
- const dataParams = key.split('*costType*');
197
- // eslint-disable-next-line prefer-destructuring
198
- params[dataParams[0]] = element[1];
199
- delete params[key];
200
- } else if (element && key.indexOf('*fullDate*') >= 0) {
201
- const dataParams = key.split('*fullDate*');
202
- dataParams.forEach((value, index) => {
203
- if (index === 0) {
204
- params[value] = moment(element[index])
205
- .millisecond(0)
206
- .second(0)
207
- .minute(0)
208
- .hour(0)
209
- .format('YYYY-MM-DD HH:mm:ss');
210
- } else {
211
- params[value] = moment(element[index])
212
- .millisecond(59)
213
- .second(59)
214
- .minute(59)
215
- .hour(23)
216
- .format('YYYY-MM-DD HH:mm:ss');
217
- }
218
- });
219
- delete params[key];
220
- } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
221
- const dataParams = key.split('*checkBox*');
222
- if (element) {
223
- params[dataParams[0]] = 0
224
- }
225
- delete params[key];
226
- } else if (element && key.indexOf('*cascader*') >= 0) {
227
- const dataParams = key.split('*cascader*');
228
- params[dataParams[0]] = element[element.length - 1]
229
- delete params[key];
230
- } else if (element && key.indexOf('*date*') >= 0) {
231
- const dataParams = key.split('*date*')
232
- dataParams.forEach((value, index) => {
233
- if (index === 0) {
234
- params[value] = moment(element[index])
235
- .format('YYYY-MM-DD');
236
- } else {
237
- params[value] = moment(element[index])
238
- .format('YYYY-MM-DD');
239
- }
240
- });
241
- delete params[key];
242
- }
243
- else if (element && key.indexOf('*') >= 0) {
244
- const dataParams = key.split('*');
245
- dataParams.forEach((value, index) => {
246
- params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
247
- });
248
- delete params[key];
249
- } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
250
- const dataParams = key.split('_selectNumberRange')[0]
251
- if (params[key][0] === 'range') {
252
- if (params[key][1][0]) {
253
- params[`qp-${dataParams}-ge`] = params[key][1][0]
254
- }
255
- if (params[key][1][1]) {
256
- params[`qp-${dataParams}-le`] = params[key][1][1]
257
- }
258
- } else {
259
- params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
260
- }
261
- delete params[key]
262
- } else if (Array.isArray(element)) {
263
- params[key] = element.join(',');
264
- } else if (element == null || element === undefined || String(element).trim() === '') {
265
- delete params[key]
266
- }
267
- }
268
- }
269
-
270
- const queryParams = {
271
- pageSize,
272
- currentPage,
273
- ...otherParams, // 默认参数
274
- ...fixedParam,
275
- ...params,
276
- }
277
-
278
- axios
279
- .get(
280
- `${url}?${stringify(queryParams)}`,
281
- {
282
- headers: { ...extralHeaders }
283
- })
284
- .then((result: any) => {
285
- setFetching(false)
286
- result = result.data;
287
- if (judgeIsRequestError(result)) {
288
- message.error(result.msg);
289
- return;
290
- }
291
- const res = result.data;
292
- let source = [];
293
- if (isMap) {
294
- source = Object.keys(res).map((d, i) => {
295
- return {
296
- text: Object.values(res)[i],
297
- value: d,
298
- };
299
- });
300
- } else {
301
- const keys = res.list ? 'list' : 'items';
302
- source = res
303
- ? res[keys]
304
- ? res[keys].map((item: any) => {
305
- let textShowText = item[mappingTextField]
306
- if (mappingTextShowTextField) {
307
- textShowText = []
308
- if (Array.isArray(mappingTextShowTextField)) {
309
- mappingTextShowTextField.forEach((r: any) => {
310
- textShowText.push(item[r])
311
- })
312
- } else {
313
- textShowText = item[mappingTextShowTextField]
314
- }
315
- }
316
- return {
317
- ...item,
318
- text: specialBracket
319
- ? `【${item[mappingValueField]}】${item[mappingTextField]}`
320
- : item[mappingTextField],
321
- textShowText,
322
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
323
- value: item[mappingValueField],
324
- };
325
- })
326
- : Array.isArray(res) &&
327
- res?.map((item: Record<string, any>) => {
328
- let textShowText = item[mappingTextField]
329
- if (mappingTextShowTextField) {
330
- textShowText = []
331
- if (Array.isArray(mappingTextShowTextField)) {
332
- mappingTextShowTextField.forEach((r: any) => {
333
- textShowText.push(item[r])
334
- })
335
- } else {
336
- textShowText = item[mappingTextShowTextField]
337
- }
338
- }
339
- return {
340
- ...item,
341
- text: specialBracket
342
- ? `【${item[mappingValueField]}】${item[mappingTextField]}`
343
- : item[mappingTextField],
344
- textShowText,
345
- textShowKey: item[mappingTextShowKeyField || mappingValueField],
346
- value: item[mappingValueField],
347
- };
348
- })
349
- : [];
350
- }
351
- source = Array.isArray(source) ? source : []
352
- if(callback) {
353
- callback(source)
354
- } else {
355
- if (type === 1) {
356
- ctx?.form?.setFieldSource(resultSourceKey, source)
357
- setItems(source)
358
- setItemsTotal(Number(res?.total || res?.totalCount || source.length))
359
- } else {
360
- setTableData(source)
361
- 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)) })
362
- }
363
- }
364
- })
365
- .catch((err) => { setFetching(false) });
366
- }
367
-
368
- const SelectScroll = e => {
369
- e.persist();
370
- const { target } = e;
371
- const totalPage = Math.ceil(itemsTotal / pageSize)
372
- // 判断是否滑动到底部
373
- const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
374
- // 判断数据是否还没有加载到了最后一页
375
- const canPageAdd = scrollPage < totalPage
376
- if (isTouchGround && canPageAdd) {
377
- const nextScrollPage = scrollPage + 1;
378
- setScrollPage(nextScrollPage);
379
- getData({ currentPage: nextScrollPage }); // 调用api方法
380
- }
381
-
382
- //判断是否滑动到顶部
383
- const isTouchTop = target.scrollTop === 0 // <=0
384
- // 判断数据是否到第一页
385
- const canPageJian = scrollPage > 1
386
- if (isTouchTop && canPageJian) {
387
- const preScrollPage = scrollPage - 1;
388
- setScrollPage(preScrollPage);
389
- getData({ currentPage: preScrollPage }); // 调用api方法
390
- }
391
- }
392
-
393
- // 下拉框改变事件
394
- const onChange = (...arg) => {
395
- onChangeTemp(...arg)
396
- if(props?.selectChangeCallback){
397
- props.selectChangeCallback(...arg)
398
- }
399
- if(props?.selectProps?.selectChangeCallback) {
400
- props.selectProps.selectChangeCallback(...arg)
401
- }
402
- }
403
-
404
- useEffect(() => {
405
- if (init) {
406
- run('init')
407
- }
408
- }, [])
409
-
410
- useEffect(() => {
411
- if (value) {
412
- setPopValue(value);
413
- }
414
- }, [value]);
415
-
416
- useEffect(() => {
417
- makeUniqueValue();
418
- }, [resultSourceKey])
419
-
420
- useEffect(() => {
421
- if (init) {
422
- setItems([]);
423
- setItemsTotal(0);
424
- run('init')
425
- }
426
- },[selectBusinessType])
427
-
428
- const showModal = () => {
429
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 3)
430
- setIsModalVisible(true);
431
- // 回显
432
- if (value) {
433
- if (selectMode) {
434
- setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
435
- setSelectedRows(labelInValue ? value.map(i => ({ [mappingValueField]: i.key, value: i.key, text: i.label })) : value.map(i => ({ [mappingValueField]: i, value: i })))
436
- setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
437
- setIndeterminate(!!value.length && value.length < itemsTotal);
438
- setCheckedAll(itemsTotal && value.length === itemsTotal);
439
- } else {
440
- setSelectedRowKeys(labelInValue ? [value.key] : [value])
441
- setSelectedRows(labelInValue ? [{ [mappingValueField]: value.key, value: value.key, text: value.label }] : [{ [mappingValueField]: value, value: value }])
442
- setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
443
- }
444
- }
445
- };
446
-
447
- const handleSelectOver = (selectedValue: any) => {
448
- if (selectedValue?.length) {
449
- // 解决选择最后1页的sku,返回后,不显示名称问题
450
- const source = _.uniqBy(items.concat(selectedValue), 'value')
451
- ctx?.form?.setFieldSource(resultSourceKey, source)
452
- setItems(source)
453
- formaData(selectedValue, source);
454
- } else {
455
- const formatResult = selectMode ? [] : null
456
- onChange(formatResult, selectedValue)
457
- }
458
- }
459
-
460
- const handleOk = () => {
461
- handleSelectOver(popvalue)
462
- handleCancel();
463
- };
464
-
465
- const formaData = (value: any, source: any) => {
466
- if (labelInValue) {
467
- const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
468
- onChange(selectMode ? formatResult : formatResult[0], value,source)
469
- } else {
470
- const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
471
- onChange(formatResult, value,source)
472
- }
473
- };
474
-
475
- const clearModalTable = () => {
476
- form.resetFields();
477
- setTableFormParams({});
478
- setTableData([]);
479
- setTablePagination(tableInitPagination);
480
- setSelectedRowKeys([]);
481
- setSelectedRows([]);
482
- setCheckedAll(false);
483
- setIndeterminate(false);
484
- };
485
-
486
- const handleCancel = () => {
487
- clearModalTable();
488
- setIsModalVisible(false);
489
- if (selectMode) {
490
- run();
491
- }
492
- };
493
-
494
- const refreshItems = () => {
495
- // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
496
- if (fieldValToParam && ctx && fixedparamsDisabled) {
497
- let formValueList = [];
498
- fieldValToParam.forEach((item: any, index: any) => {
499
- const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
500
- formValueList.push(fixedParamVal);
501
- });
502
- if (formValueList.filter((item: any) => item).length > 0) {
503
- run();
504
- } else {
505
- setItems([]);
506
- setItemsTotal(0);
507
- }
508
- } else {
509
- run();
510
- }
511
- }
512
-
513
- const onSearchChange = (e) => {
514
- setSearchValue(e.target.value);
515
- refreshItems();
516
- }
517
-
518
- const onSearchBlur = () => {
519
- setSearchValue('');
520
- refreshItems();
521
- }
522
-
523
- const onSearchTable = () => {
524
- const params = form.getFieldsValue();
525
- setTableFormParams(params);
526
- getData({ ...params, pageSize: tableInitPageSize }, 2)
527
- if (selectMode) {
528
- getData(params)
529
- }
530
- }
531
-
532
- const onResetTable = () => {
533
- form.resetFields();
534
- setTableFormParams({});
535
- getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
536
- }
537
-
538
- const handleTableChange = (pagination) => {
539
- getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
540
- }
541
-
542
- const onCheckAllData = (pSize) => {
543
- getData({ ...tableFormParams, pageSize: pSize, currentPage: 1 }, 2,(source) => {
544
- const currentItemsData = JSON.parse(JSON.stringify(source))
545
- setSelectedRowKeys(currentItemsData.map(i => i.value))
546
- setPopValue(currentItemsData);
547
- setSelectedRows(currentItemsData)
548
- })
549
- }
550
- const onChangeCheckAll = (e) => {
551
- if (e.target.checked) {
552
- // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
553
- // 如果超过100条 就默认查出所有数据
554
- if (items.length < itemsTotal) {
555
- const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize);
556
- const allPageSize = totalPage * tablePagination?.pageSize;
557
- onCheckAllData(allPageSize)
558
- } else {
559
- const currentItemsData = JSON.parse(JSON.stringify(items))
560
- setSelectedRowKeys(currentItemsData.map(i => i.value))
561
- setPopValue(currentItemsData);
562
- setSelectedRows(currentItemsData)
563
- }
564
- } else {
565
- setSelectedRowKeys([])
566
- setPopValue([]);
567
- setSelectedRows([])
568
- }
569
- setIndeterminate(false);
570
- setCheckedAll(e.target.checked);
571
- }
572
-
573
- const LightHeightOption = (props) => {
574
- const {
575
- filterTxt, text,
576
- } = props
577
- const heightLightTxt = (text, heightTxt) => {
578
- if (heightTxt === '') {
579
- return text
580
- }
581
- // 前面filterOption 不区分大小写,这里用i
582
- const regexp = new RegExp(heightTxt, 'gi')
583
- return text.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
584
- }
585
- return (
586
- <Tooltip title={text}>
587
- <div ref={(nodeElement) => {
588
- if (nodeElement) {
589
- nodeElement.innerHTML = heightLightTxt(text, filterTxt)
590
- }
591
- }}
592
- />
593
- </Tooltip>
594
- )
595
- }
596
-
597
- // 扁平化二维数组的方法
598
- const mapRows = params => {
599
- var res = [];
600
- for (var i = 0; i < params.length; i++) {
601
- if (Array.isArray(params[i])) {
602
- // 去重
603
- res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
604
- } else {
605
- res.push(params[i]);
606
- // 去重
607
- res = _.uniqBy(res, 'value')
608
- }
609
- }
610
- return res.filter(Boolean); //去掉undefined的情况
611
- };
612
-
613
- const onChangeSelectedKeys = (selectKeys, selectRows) => {
614
- let sksResult = selectRows.map((i) => i.value);
615
-
616
- // 单选 默认直接选中 不需要确定 配置了modalRadioNeedFooter就需要确定
617
- if(!selectMode && !modalTableProps?.modalRadioNeedFooter) {
618
- handleSelectOver(selectRows)
619
- handleCancel();
620
- }
621
-
622
- setSelectedRowKeys(sksResult)
623
- setSelectedRows(selectRows)
624
- setPopValue(selectRows);
625
- setIndeterminate(!!selectRows.length && selectRows.length < tablePagination?.total);
626
- setCheckedAll(selectRows.length === tablePagination?.total);
627
- }
628
-
629
- // 生成唯一值
630
- const makeUniqueValue = () => {
631
- const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
632
- setUniqueValue(generateUnitKey);
633
- return generateUnitKey;
634
- }
635
-
636
- const rowSelection = {
637
- type: selectMode ? 'checkbox' : 'radio',
638
- selectedRowKeys,
639
- preserveSelectedRowKeys: true,
640
- onChange: (sks, srs) => {
641
- // 处理翻页后,之前存储的selectedRows变为undefined
642
- // selectedRows合并新数组,过滤undefined,过滤留下对应selectedRowKeys的集合
643
- let tmpSelectedRows = selectedRows.concat(srs).filter(item => item != undefined);
644
- let totalSelectedRows = sks.map(key => tmpSelectedRows.filter(item => item[mappingValueField] == key)[0]).filter(item => item != undefined)
645
- onChangeSelectedKeys(sks, totalSelectedRows)
646
- },
647
- getCheckboxProps: () => {
648
- return ({
649
- disabled: selectProps?.disabled || props?.disabled || (!items.length && !tableData.length),
650
- })
651
- },
652
- };
653
-
654
- const onDoubleClickSelect = (e, record) => {
655
- if (!selectMode && !(selectProps?.disabled || props?.disabled || (!items.length && !tableData.length))) {
656
- const srs = [JSON.parse(JSON.stringify(record))]
657
- const sks = srs.map((i: any) => i.value)
658
- onChangeSelectedKeys(sks, srs)
659
- }
660
- }
661
-
662
- const themeColor = { color: '#1890ff' }
663
-
664
- const formItem = (list) => {
665
- if (isModalVisible && list?.length) {
666
- const setDisabled = (name: any) => {
667
- if (fixedparamsDisabled && fixedparameter?.length && fixedparameter.find((item: any) => item === name)) {
668
- return true
669
- } else {
670
- return false
671
- }
672
- };
673
- return list.map((i: any) => {
674
- if (i?.type === 'select' || i?.field?.type === 'select') {
675
- return (
676
- <Form.Item name={i.name} label={i.label} key={i.name}>
677
- <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}>
678
- {i?.initialSource?.length && i?.initialSource.map((m: any) => (
679
- <Option value={m.value} key={m.value}>{m.text}</Option>
680
- ))}
681
- </Select>
682
- </Form.Item>
683
- )
684
- }
685
-
686
- if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
687
- return (
688
- <Form.Item name={i.name} label={i.label} key={i.name}>
689
- <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></TreeSelect>
690
- </Form.Item>
691
- )
692
- }
693
-
694
- if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
695
- return (
696
- <div>
697
- <Form.Item name={i.name} label={i.label} key={i.name}>
698
- <BusinessSearchSelect {...i.field.props} disabled={setDisabled(i.name)} />
699
- </Form.Item>
700
- </div>
701
- )
702
- }
703
-
704
- if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
705
- return (
706
- <div>
707
- <Form.Item name={i.name} label={i.label} key={i.name}>
708
- <QueryMutipleInput onValueChange={(value) => {
709
- form.setFieldsValue({
710
- [i.name]: value
711
- })
712
- }} />
713
- </Form.Item>
714
- </div>
715
- );
716
- }
717
-
718
- // 默认type是input
719
- return (
720
- <Form.Item name={i.name} label={i.label} key={i.name}>
721
- <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} disabled={setDisabled(i.name)} />
722
- </Form.Item>
723
- )
724
- })
725
- } else {
726
- return null
727
- }
728
- }
729
-
730
- const maxTagPlaceholder = (selectedValues) => {
731
- const onClose = (e: any, item: any) => {
732
- e.preventDefault();
733
- 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)
734
- onChange(newValue);
735
- }
736
- return (
737
- <Tooltip title={selectedValues.map((i: any) => (
738
- <Tag
739
- closable={true}
740
- onClose={(e) => onClose(e, i)}
741
- style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
742
- >
743
- {i.label}
744
- </Tag>
745
- ))}>
746
- {`+ ${selectedValues?.length}`}
747
- </Tooltip>
748
- )
749
- }
750
-
751
- const handleSelectOptionsShowValue = (specialBracket: boolean, noNeedSplit: boolean, item: object) => {
752
- let showText = Array.isArray(item.textShowText) &&
753
- item.textShowText.join(' ') || item.textShowText;
754
- if (noNeedSplit) {
755
- return item.text;
756
- } else {
757
- return specialBracket
758
- ? `【${item.textShowKey}】${showText}`
759
- : `${item.textShowKey} ${showText}`
760
- }
761
- };
762
-
763
- return (
764
- <div className={'search_select'}>
765
- {fieldComponent ?
766
- (<div onClick={() => {
767
- fieldComponent.props?.onClick?.()
768
- showModal()
769
- }}>{fieldComponent}</div>) :
770
- (<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
771
- <Select
772
- virtual
773
- labelInValue={labelInValue}
774
- value={value}
775
- onChange={onChange}
776
- disabled={props.disabled}
777
- dropdownRender={menu => (
778
- <>
779
- <Input
780
- value={searchValue}
781
- style={{ width: '98%', marginLeft: '1%' }}
782
- placeholder="请输入"
783
- onChange={e => onSearchChange(e)}
784
- onBlur={onSearchBlur}
785
- onKeyDown={(e) => {
786
- // 阻止多选的冒泡
787
- e.stopPropagation()
788
- }}
789
- />
790
- <Divider style={{ margin: '8px 0' }} />
791
- {menu}
792
- </>
793
- )}
794
- notFoundContent={
795
- fetching ? <Spin size="small" /> :
796
- <div style={{ textAlign: 'center' }}>
797
- <div style={{ marginBottom: 16 }}>
798
- <CopyOutlined style={{ fontSize: '50px' }} />
799
- </div>
800
- <div>无匹配结果,请更换其他内容再试</div>
801
- </div>
802
- }
803
- onPopupScroll={SelectScroll}
804
- style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
805
- placeholder="请选择"
806
- maxTagPlaceholder={maxTagPlaceholder}
807
- {...currentSelectProps}
808
- getPopupContainer={(triggerNode) => (getPopupContainer && getPopupContainer(triggerNode)) || triggerNode.parentElement}
809
- >
810
- {items.map(item => (
811
- <Option key={item.value} label={item.text}>
812
- {LightHeightOption({
813
- text: handleSelectOptionsShowValue(specialBracket, noNeedSplit, item),
814
- filterTxt: searchValue
815
- })}
816
- </Option>
817
- ))}
818
- </Select>
819
- {needModalTable && (
820
- <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
821
- <SearchOutlined />
822
- </Button>
823
- )}
824
- </div>)}
825
- {needModalTable && isModalVisible && (
826
- <Modal
827
- width='80%'
828
- title={modalTableProps?.modalTableTitle}
829
- visible={isModalVisible}
830
- onOk={handleOk}
831
- onCancel={handleCancel}
832
- footer={(selectMode || modalTableProps?.modalRadioNeedFooter) ? [
833
- <Button key="back" onClick={handleCancel}>
834
- 取消
835
- </Button>,
836
- <Button
837
- key="submit"
838
- type="primary"
839
- onClick={handleOk}
840
- disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
841
- >
842
- 确定
843
- </Button>,
844
- ] : null}
845
- {...(modalTableProps?.modalProps || {})}
846
- >
847
- <div className={'search_select_wrapper'}>
848
- <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
849
- <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
850
- </div>
851
- <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
852
- <div className={'select_list_columns'}>
853
- <div className={'select_list_columns_tips'}>搜索</div>
854
- <div className={'select_list_columns_formItems'}>
855
- <Form form={form} layout='vertical' key='modalForm'>
856
- {formItem(modalTableProps?.tableSearchForm)}
857
- </Form>
858
- </div>
859
- </div>
860
- <div className={'select_list_searchButton'}>
861
- <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
862
- <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
863
- </div>
864
- </div>
865
- <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
866
- <div>
867
- <div className={'select_list_selectTips'}>
868
- <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
869
- <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
870
- </div>
871
- <Table
872
- size='small'
873
- rowSelection={rowSelection}
874
- columns={modalTableProps?.tableColumns}
875
- dataSource={tableData}
876
- pagination={tablePagination}
877
- onChange={handleTableChange}
878
- rowKey={mappingValueField}
879
- scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
880
- onRow={record => {
881
- return {
882
- onDoubleClick: event => onDoubleClickSelect(event, record),
883
- };
884
- }}
885
- />
886
- {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
887
- </div>
888
- </div>
889
- </div>
890
- </Modal>
891
- )}
892
- </div>
893
- );
894
- });
895
-
896
- export default SearchSelect;
1
+ // @ts-nocheck
2
+ import React, { useState, useEffect, forwardRef, useImperativeHandle } from 'react';
3
+ import { useDebounceFn } from 'ahooks';
4
+ import { Input, Button, Modal, Select, Divider, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
+ import { SearchOutlined, CopyOutlined, CaretLeftOutlined } 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 { handleSourceName } from './utils';
12
+ import { judgeIsRequestError } from '@/utils/requestUtils';
13
+
14
+ const { Option } = Select;
15
+
16
+ const SearchSelect = forwardRef((props: any, ref: any) => {
17
+ const {
18
+ value, // 必传
19
+ onChange: onChangeTemp,
20
+ selectProps = {},
21
+ modalTableProps = {},
22
+ labelInValue = false,
23
+ requestConfig,
24
+ ctx,
25
+ sourceName,
26
+ needModalTable = true,
27
+ getPopupContainer = undefined,
28
+ fieldComponent,
29
+ selectBusinessType,
30
+ } = props;
31
+ const {
32
+ url,
33
+ otherParams,// 默认参数
34
+ isMap,
35
+ fixedparameter,
36
+ fieldValToParam,
37
+ fixedparamsDisabled = false,
38
+ mappingTextField = 'name',
39
+ mappingTextShowKeyField,
40
+ mappingValueField = 'code',
41
+ mappingTextShowTextField,
42
+ init = true,// 是否初始请求
43
+ extralHeaders = {},// 额外请求头参数
44
+ specialBracket = false,// 是否使用特殊括弧显示选项 【value】text
45
+ noNeedSplit = false,// label显示不需要任何特殊化
46
+ } = requestConfig || {};
47
+ const resultSourceKey = handleSourceName(sourceName || requestConfig?.sourceName || 'supplierCode')
48
+
49
+ const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
50
+ const initVal = value || (selectMode ? [] : null);
51
+ const pageSize = 100 // 下拉框默认分页 条数
52
+ const tableInitPageSize = 10 // 弹框默认分页 条数
53
+ const currentPage = 1
54
+ const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
55
+ const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
56
+ const currentSelectProps = {
57
+ ...selectProps,
58
+ // 以下属性不可更改----设计配置项
59
+ showSearch: false,
60
+ filterOption: false,
61
+ allowClear: true,
62
+ listHeight: 160,
63
+ optionLabelProp: "label",
64
+ autoClearSearchValue: false
65
+ }
66
+ const tableInitPagination = { showQuickJumper: true, total: 0, current: 1, pageSize: tableInitPageSize }
67
+
68
+ const [items, setItems] = useState([]);
69
+ const [scrollPage, setScrollPage] = useState(1);
70
+ const [itemsTotal, setItemsTotal] = useState(0);
71
+ const [fetching, setFetching] = useState(false);
72
+ const [searchValue, setSearchValue] = useState('');
73
+ const [isModalVisible, setIsModalVisible] = useState(false);
74
+ const [popvalue, setPopValue] = useState(initVal);
75
+ const [uniqueValue, setUniqueValue] = useState(resultSourceKey)
76
+ const { run } = useDebounceFn(
77
+ (v?: any) => {
78
+ // 优化搜索参数 支持传多个
79
+ let searchParams = {};
80
+ if (typeof selectParamsKey === 'string') {
81
+ let selectParamsInitValue = initVal
82
+ if (labelInValue) {
83
+ selectParamsInitValue = Array.isArray(initVal) ? initVal.map((i: any) => i.value || i.key).join(',') : initVal
84
+ } else {
85
+ selectParamsInitValue = Array.isArray(initVal) ? initVal.join(',') : initVal
86
+ }
87
+ searchParams = v ? { [selectParamsInitKey]: selectParamsInitValue } : { [selectParamsKey]: searchValue }
88
+ }
89
+ if (Array.isArray(selectParamsKey)) {
90
+ selectParamsKey.forEach((i: any) => {
91
+ searchParams = { ...searchParams, [i]: searchValue }
92
+ })
93
+ }
94
+ // 防抖函数 待定
95
+ getData(searchParams)
96
+ },
97
+ {
98
+ wait: 1000,
99
+ },
100
+ );
101
+
102
+ const [form] = Form.useForm();
103
+ const [caretLeftFlag, setCaretLeftFlag] = useState(true);
104
+ const [tableData, setTableData] = useState([]);
105
+ const [tablePagination, setTablePagination] = useState(tableInitPagination)
106
+ const [selectedRowKeys, setSelectedRowKeys] = useState([]);
107
+ const [selectedRows, setSelectedRows] = useState([]);
108
+ const [checkedAll, setCheckedAll] = useState(false)
109
+ const [indeterminate, setIndeterminate] = useState(false)
110
+ const [tableFormParams, setTableFormParams] = useState({});
111
+ const [tooltipVisible, setTooltipVisible] = useState(false);
112
+
113
+ useImperativeHandle(ref, () => ({
114
+ refreshDataSource: (reset: boolean = false) => {
115
+ if (reset) {
116
+ if (init) {
117
+ run('init');
118
+ } else {
119
+ setItems([]);
120
+ setItemsTotal(0);
121
+ }
122
+ } else {
123
+ run();
124
+ }
125
+ },
126
+ clearDataSource: () => {
127
+ setItems([]);
128
+ setItemsTotal(0);
129
+ },
130
+ getTableFormRef: () => form,
131
+ // 解决下拉框数据源的问题
132
+ getSelectDataSource: () => items,
133
+ setSelectDataSource: (list: any, listTotal: number) => {
134
+ setItems(list);
135
+ setItemsTotal(listTotal);
136
+ },
137
+ refreshSelectDataSource: () => {
138
+ refreshItems()
139
+ }
140
+ }))
141
+
142
+ // 获取数据源 (type: 1下拉框 2/3弹框 不传值默认为下拉框)
143
+ const getData = (params = {}, type = 1,callback?: any) => {
144
+ if (!requestConfig) return;
145
+
146
+ setFetching(true)
147
+
148
+ // 处理dependence参数
149
+ const fixedParam = {};
150
+ if (fixedparameter && fieldValToParam && ctx) {
151
+ fixedparameter.forEach((item: any, index: any) => {
152
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
153
+ if(fixedParamVal) {
154
+ fixedParam[item] = fixedParamVal;
155
+ // 解决依赖项在弹窗中回显/更改(如果不能更改,传参fixedparamsDisabled为true即可)
156
+ if(type == 2 || type == 3) {
157
+ const fixedChangeParamVal = form.getFieldValue(item);
158
+ let isDependenceValueChange = false;
159
+ let dependenceValue = fixedParamVal;
160
+ // 依赖项在弹窗form中更改--①更换依赖值;②去掉依赖值
161
+ if(!fixedparamsDisabled) {
162
+ isDependenceValueChange =
163
+ (fixedChangeParamVal && fixedChangeParamVal !== fixedParamVal)
164
+ || (type == 2 && !fixedChangeParamVal);
165
+ dependenceValue = isDependenceValueChange ? fixedChangeParamVal : fixedParamVal;
166
+ }
167
+ fixedParam[item] = dependenceValue;
168
+ form.setFieldsValue({ ...form?.getFieldsValue(), [item]: dependenceValue })
169
+ if(isDependenceValueChange) {
170
+ ctx.form.setFieldValue(fieldValToParam[index],fixedChangeParamVal) // 更改依赖项
171
+ ctx.form.setFieldValue(resultSourceKey,null) // 同时清空之前依赖项对应的选择项
172
+ refreshItems()
173
+ }
174
+ }
175
+ }
176
+ });
177
+ }
178
+
179
+ // 数组对象处理,对带有特殊标记的name进行处理
180
+ for (const key in params) {
181
+ if (Object.prototype.hasOwnProperty.call(params, key)) {
182
+ const element = params[key];
183
+ if (element && key.indexOf('*number*') >= 0) {
184
+ const dataParams = key.split('*number*');
185
+ dataParams.forEach((value, index) => {
186
+ params[value] = element[index];
187
+ });
188
+ delete params[key];
189
+ } else if (element && key.indexOf('*address*') >= 0) {
190
+ const dataParams = key.split('*address*');
191
+ dataParams.forEach((value, index) => {
192
+ params[value] = element.PCDCode[index];
193
+ });
194
+ delete params[key];
195
+ } else if (element && key.indexOf('*costType*') >= 0) {
196
+ const dataParams = key.split('*costType*');
197
+ // eslint-disable-next-line prefer-destructuring
198
+ params[dataParams[0]] = element[1];
199
+ delete params[key];
200
+ } else if (element && key.indexOf('*fullDate*') >= 0) {
201
+ const dataParams = key.split('*fullDate*');
202
+ dataParams.forEach((value, index) => {
203
+ if (index === 0) {
204
+ params[value] = moment(element[index])
205
+ .millisecond(0)
206
+ .second(0)
207
+ .minute(0)
208
+ .hour(0)
209
+ .format('YYYY-MM-DD HH:mm:ss');
210
+ } else {
211
+ params[value] = moment(element[index])
212
+ .millisecond(59)
213
+ .second(59)
214
+ .minute(59)
215
+ .hour(23)
216
+ .format('YYYY-MM-DD HH:mm:ss');
217
+ }
218
+ });
219
+ delete params[key];
220
+ } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
221
+ const dataParams = key.split('*checkBox*');
222
+ if (element) {
223
+ params[dataParams[0]] = 0
224
+ }
225
+ delete params[key];
226
+ } else if (element && key.indexOf('*cascader*') >= 0) {
227
+ const dataParams = key.split('*cascader*');
228
+ params[dataParams[0]] = element[element.length - 1]
229
+ delete params[key];
230
+ } else if (element && key.indexOf('*date*') >= 0) {
231
+ const dataParams = key.split('*date*')
232
+ dataParams.forEach((value, index) => {
233
+ if (index === 0) {
234
+ params[value] = moment(element[index])
235
+ .format('YYYY-MM-DD');
236
+ } else {
237
+ params[value] = moment(element[index])
238
+ .format('YYYY-MM-DD');
239
+ }
240
+ });
241
+ delete params[key];
242
+ }
243
+ else if (element && key.indexOf('*') >= 0) {
244
+ const dataParams = key.split('*');
245
+ dataParams.forEach((value, index) => {
246
+ params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
247
+ });
248
+ delete params[key];
249
+ } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
250
+ const dataParams = key.split('_selectNumberRange')[0]
251
+ if (params[key][0] === 'range') {
252
+ if (params[key][1][0]) {
253
+ params[`qp-${dataParams}-ge`] = params[key][1][0]
254
+ }
255
+ if (params[key][1][1]) {
256
+ params[`qp-${dataParams}-le`] = params[key][1][1]
257
+ }
258
+ } else {
259
+ params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
260
+ }
261
+ delete params[key]
262
+ } else if (Array.isArray(element)) {
263
+ params[key] = element.join(',');
264
+ } else if (element == null || element === undefined || String(element).trim() === '') {
265
+ delete params[key]
266
+ }
267
+ }
268
+ }
269
+
270
+ const queryParams = {
271
+ pageSize,
272
+ currentPage,
273
+ ...otherParams, // 默认参数
274
+ ...fixedParam,
275
+ ...params,
276
+ }
277
+
278
+ axios
279
+ .get(
280
+ `${url}?${stringify(queryParams)}`,
281
+ {
282
+ headers: { ...extralHeaders }
283
+ })
284
+ .then((result: any) => {
285
+ setFetching(false)
286
+ result = result.data;
287
+ if (judgeIsRequestError(result)) {
288
+ message.error(result.msg);
289
+ return;
290
+ }
291
+ const res = result.data;
292
+ let source = [];
293
+ if (isMap) {
294
+ source = Object.keys(res).map((d, i) => {
295
+ return {
296
+ text: Object.values(res)[i],
297
+ value: d,
298
+ };
299
+ });
300
+ } else {
301
+ const keys = res.list ? 'list' : 'items';
302
+ source = res
303
+ ? res[keys]
304
+ ? res[keys].map((item: any) => {
305
+ let textShowText = item[mappingTextField]
306
+ if (mappingTextShowTextField) {
307
+ textShowText = []
308
+ if (Array.isArray(mappingTextShowTextField)) {
309
+ mappingTextShowTextField.forEach((r: any) => {
310
+ textShowText.push(item[r])
311
+ })
312
+ } else {
313
+ textShowText = item[mappingTextShowTextField]
314
+ }
315
+ }
316
+ return {
317
+ ...item,
318
+ text: specialBracket
319
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
320
+ : item[mappingTextField],
321
+ textShowText,
322
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
323
+ value: item[mappingValueField],
324
+ };
325
+ })
326
+ : Array.isArray(res) &&
327
+ res?.map((item: Record<string, any>) => {
328
+ let textShowText = item[mappingTextField]
329
+ if (mappingTextShowTextField) {
330
+ textShowText = []
331
+ if (Array.isArray(mappingTextShowTextField)) {
332
+ mappingTextShowTextField.forEach((r: any) => {
333
+ textShowText.push(item[r])
334
+ })
335
+ } else {
336
+ textShowText = item[mappingTextShowTextField]
337
+ }
338
+ }
339
+ return {
340
+ ...item,
341
+ text: specialBracket
342
+ ? `【${item[mappingValueField]}】${item[mappingTextField]}`
343
+ : item[mappingTextField],
344
+ textShowText,
345
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
346
+ value: item[mappingValueField],
347
+ };
348
+ })
349
+ : [];
350
+ }
351
+ source = Array.isArray(source) ? source : []
352
+ if(callback) {
353
+ callback(source)
354
+ } else {
355
+ if (type === 1) {
356
+ ctx?.form?.setFieldSource(resultSourceKey, source)
357
+ setItems(source)
358
+ setItemsTotal(Number(res?.total || res?.totalCount || source.length))
359
+ } else {
360
+ setTableData(source)
361
+ 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)) })
362
+ }
363
+ }
364
+ })
365
+ .catch((err) => { setFetching(false) });
366
+ }
367
+
368
+ const SelectScroll = e => {
369
+ e.persist();
370
+ const { target } = e;
371
+ const totalPage = Math.ceil(itemsTotal / pageSize)
372
+ // 判断是否滑动到底部
373
+ const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
374
+ // 判断数据是否还没有加载到了最后一页
375
+ const canPageAdd = scrollPage < totalPage
376
+ if (isTouchGround && canPageAdd) {
377
+ const nextScrollPage = scrollPage + 1;
378
+ setScrollPage(nextScrollPage);
379
+ getData({ currentPage: nextScrollPage }); // 调用api方法
380
+ }
381
+
382
+ //判断是否滑动到顶部
383
+ const isTouchTop = target.scrollTop === 0 // <=0
384
+ // 判断数据是否到第一页
385
+ const canPageJian = scrollPage > 1
386
+ if (isTouchTop && canPageJian) {
387
+ const preScrollPage = scrollPage - 1;
388
+ setScrollPage(preScrollPage);
389
+ getData({ currentPage: preScrollPage }); // 调用api方法
390
+ }
391
+ }
392
+
393
+ // 下拉框改变事件
394
+ const onChange = (...arg) => {
395
+ onChangeTemp(...arg)
396
+ if(props?.selectChangeCallback){
397
+ props.selectChangeCallback(...arg)
398
+ }
399
+ if(props?.selectProps?.selectChangeCallback) {
400
+ props.selectProps.selectChangeCallback(...arg)
401
+ }
402
+ }
403
+
404
+ useEffect(() => {
405
+ if (init) {
406
+ run('init')
407
+ }
408
+ }, [])
409
+
410
+ useEffect(() => {
411
+ if (value) {
412
+ setPopValue(value);
413
+ }
414
+ }, [value]);
415
+
416
+ useEffect(() => {
417
+ makeUniqueValue();
418
+ }, [resultSourceKey])
419
+
420
+ useEffect(() => {
421
+ if (init) {
422
+ setItems([]);
423
+ setItemsTotal(0);
424
+ run('init')
425
+ }
426
+ },[selectBusinessType])
427
+
428
+ const showModal = () => {
429
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 3)
430
+ setIsModalVisible(true);
431
+ // 回显
432
+ if (value) {
433
+ if (selectMode) {
434
+ setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
435
+ setSelectedRows(labelInValue ? value.map(i => ({ [mappingValueField]: i.key, value: i.key, text: i.label })) : value.map(i => ({ [mappingValueField]: i, value: i })))
436
+ setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
437
+ setIndeterminate(!!value.length && value.length < itemsTotal);
438
+ setCheckedAll(itemsTotal && value.length === itemsTotal);
439
+ } else {
440
+ setSelectedRowKeys(labelInValue ? [value.key] : [value])
441
+ setSelectedRows(labelInValue ? [{ [mappingValueField]: value.key, value: value.key, text: value.label }] : [{ [mappingValueField]: value, value: value }])
442
+ setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
443
+ }
444
+ }
445
+ };
446
+
447
+ const handleSelectOver = (selectedValue: any) => {
448
+ if (selectedValue?.length) {
449
+ // 解决选择最后1页的sku,返回后,不显示名称问题
450
+ const source = _.uniqBy(items.concat(selectedValue), 'value')
451
+ ctx?.form?.setFieldSource(resultSourceKey, source)
452
+ setItems(source)
453
+ formaData(selectedValue, source);
454
+ } else {
455
+ const formatResult = selectMode ? [] : null
456
+ onChange(formatResult, selectedValue)
457
+ }
458
+ }
459
+
460
+ const handleOk = () => {
461
+ handleSelectOver(popvalue)
462
+ handleCancel();
463
+ };
464
+
465
+ const formaData = (value: any, source: any) => {
466
+ if (labelInValue) {
467
+ const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
468
+ onChange(selectMode ? formatResult : formatResult[0], value,source)
469
+ } else {
470
+ const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
471
+ onChange(formatResult, value,source)
472
+ }
473
+ };
474
+
475
+ const clearModalTable = () => {
476
+ form.resetFields();
477
+ setTableFormParams({});
478
+ setTableData([]);
479
+ setTablePagination(tableInitPagination);
480
+ setSelectedRowKeys([]);
481
+ setSelectedRows([]);
482
+ setCheckedAll(false);
483
+ setIndeterminate(false);
484
+ };
485
+
486
+ const handleCancel = () => {
487
+ clearModalTable();
488
+ setIsModalVisible(false);
489
+ if (selectMode) {
490
+ run();
491
+ }
492
+ };
493
+
494
+ const refreshItems = () => {
495
+ // 查看是否存在关联值 如果有关联值 就查询 没有就不能查询
496
+ if (fieldValToParam && ctx && fixedparamsDisabled) {
497
+ let formValueList = [];
498
+ fieldValToParam.forEach((item: any, index: any) => {
499
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
500
+ formValueList.push(fixedParamVal);
501
+ });
502
+ if (formValueList.filter((item: any) => item).length > 0) {
503
+ run();
504
+ } else {
505
+ setItems([]);
506
+ setItemsTotal(0);
507
+ }
508
+ } else {
509
+ run();
510
+ }
511
+ }
512
+
513
+ const onSearchChange = (e) => {
514
+ setSearchValue(e.target.value);
515
+ refreshItems();
516
+ }
517
+
518
+ const onSearchBlur = () => {
519
+ setSearchValue('');
520
+ refreshItems();
521
+ }
522
+
523
+ const onSearchTable = () => {
524
+ const params = form.getFieldsValue();
525
+ setTableFormParams(params);
526
+ getData({ ...params, pageSize: tableInitPageSize }, 2)
527
+ if (selectMode) {
528
+ getData(params)
529
+ }
530
+ }
531
+
532
+ const onResetTable = () => {
533
+ form.resetFields();
534
+ setTableFormParams({});
535
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
536
+ }
537
+
538
+ const handleTableChange = (pagination) => {
539
+ getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
540
+ }
541
+
542
+ const onCheckAllData = (pSize) => {
543
+ getData({ ...tableFormParams, pageSize: pSize, currentPage: 1 }, 2,(source) => {
544
+ const currentItemsData = JSON.parse(JSON.stringify(source))
545
+ setSelectedRowKeys(currentItemsData.map(i => i.value))
546
+ setPopValue(currentItemsData);
547
+ setSelectedRows(currentItemsData)
548
+ })
549
+ }
550
+ const onChangeCheckAll = (e) => {
551
+ if (e.target.checked) {
552
+ // 如果下拉框有所有数据就处理选中所有【items.length === itemsTotal】(最多可选100条)
553
+ // 如果超过100条 就默认查出所有数据
554
+ if (items.length < itemsTotal) {
555
+ const totalPage = Math.ceil(itemsTotal / tablePagination?.pageSize);
556
+ const allPageSize = totalPage * tablePagination?.pageSize;
557
+ onCheckAllData(allPageSize)
558
+ } else {
559
+ const currentItemsData = JSON.parse(JSON.stringify(items))
560
+ setSelectedRowKeys(currentItemsData.map(i => i.value))
561
+ setPopValue(currentItemsData);
562
+ setSelectedRows(currentItemsData)
563
+ }
564
+ } else {
565
+ setSelectedRowKeys([])
566
+ setPopValue([]);
567
+ setSelectedRows([])
568
+ }
569
+ setIndeterminate(false);
570
+ setCheckedAll(e.target.checked);
571
+ }
572
+
573
+ const LightHeightOption = (props) => {
574
+ const {
575
+ filterTxt, text,
576
+ } = props
577
+ const heightLightTxt = (text, heightTxt) => {
578
+ if (heightTxt === '') {
579
+ return text
580
+ }
581
+ // 前面filterOption 不区分大小写,这里用i
582
+ const regexp = new RegExp(heightTxt, 'gi')
583
+ return text.replace(regexp, `<span style="color:red">${heightTxt}</span>`)
584
+ }
585
+ return (
586
+ <Tooltip title={text}>
587
+ <div ref={(nodeElement) => {
588
+ if (nodeElement) {
589
+ nodeElement.innerHTML = heightLightTxt(text, filterTxt)
590
+ }
591
+ }}
592
+ />
593
+ </Tooltip>
594
+ )
595
+ }
596
+
597
+ // 扁平化二维数组的方法
598
+ const mapRows = params => {
599
+ var res = [];
600
+ for (var i = 0; i < params.length; i++) {
601
+ if (Array.isArray(params[i])) {
602
+ // 去重
603
+ res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
604
+ } else {
605
+ res.push(params[i]);
606
+ // 去重
607
+ res = _.uniqBy(res, 'value')
608
+ }
609
+ }
610
+ return res.filter(Boolean); //去掉undefined的情况
611
+ };
612
+
613
+ const onChangeSelectedKeys = (selectKeys, selectRows) => {
614
+ let sksResult = selectRows.map((i) => i.value);
615
+
616
+ // 单选 默认直接选中 不需要确定 配置了modalRadioNeedFooter就需要确定
617
+ if(!selectMode && !modalTableProps?.modalRadioNeedFooter) {
618
+ handleSelectOver(selectRows)
619
+ handleCancel();
620
+ }
621
+
622
+ setSelectedRowKeys(sksResult)
623
+ setSelectedRows(selectRows)
624
+ setPopValue(selectRows);
625
+ setIndeterminate(!!selectRows.length && selectRows.length < tablePagination?.total);
626
+ setCheckedAll(selectRows.length === tablePagination?.total);
627
+ }
628
+
629
+ // 生成唯一值
630
+ const makeUniqueValue = () => {
631
+ const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
632
+ setUniqueValue(generateUnitKey);
633
+ return generateUnitKey;
634
+ }
635
+
636
+ const rowSelection = {
637
+ type: selectMode ? 'checkbox' : 'radio',
638
+ selectedRowKeys,
639
+ preserveSelectedRowKeys: true,
640
+ onChange: (sks, srs) => {
641
+ // 处理翻页后,之前存储的selectedRows变为undefined
642
+ // selectedRows合并新数组,过滤undefined,过滤留下对应selectedRowKeys的集合
643
+ let tmpSelectedRows = selectedRows.concat(srs).filter(item => item != undefined);
644
+ let totalSelectedRows = sks.map(key => tmpSelectedRows.filter(item => item[mappingValueField] == key)[0]).filter(item => item != undefined)
645
+ onChangeSelectedKeys(sks, totalSelectedRows)
646
+ },
647
+ getCheckboxProps: () => {
648
+ return ({
649
+ disabled: selectProps?.disabled || props?.disabled || (!items.length && !tableData.length),
650
+ })
651
+ },
652
+ };
653
+
654
+ const onDoubleClickSelect = (e, record) => {
655
+ if (!selectMode && !(selectProps?.disabled || props?.disabled || (!items.length && !tableData.length))) {
656
+ const srs = [JSON.parse(JSON.stringify(record))]
657
+ const sks = srs.map((i: any) => i.value)
658
+ onChangeSelectedKeys(sks, srs)
659
+ }
660
+ }
661
+
662
+ const themeColor = { color: '#1890ff' }
663
+
664
+ const formItem = (list) => {
665
+ if (isModalVisible && list?.length) {
666
+ const setDisabled = (name: any) => {
667
+ if (fixedparamsDisabled && fixedparameter?.length && fixedparameter.find((item: any) => item === name)) {
668
+ return true
669
+ } else {
670
+ return false
671
+ }
672
+ };
673
+ return list.map((i: any) => {
674
+ if (i?.type === 'select' || i?.field?.type === 'select') {
675
+ return (
676
+ <Form.Item name={i.name} label={i.label} key={i.name}>
677
+ <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}>
678
+ {i?.initialSource?.length && i?.initialSource.map((m: any) => (
679
+ <Option value={m.value} key={m.value}>{m.text}</Option>
680
+ ))}
681
+ </Select>
682
+ </Form.Item>
683
+ )
684
+ }
685
+
686
+ if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
687
+ return (
688
+ <Form.Item name={i.name} label={i.label} key={i.name}>
689
+ <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props} disabled={setDisabled(i.name)}></TreeSelect>
690
+ </Form.Item>
691
+ )
692
+ }
693
+
694
+ if (i?.type === 'businessSearchSelect' || i?.field?.type === 'businessSearchSelect') {
695
+ return (
696
+ <div>
697
+ <Form.Item name={i.name} label={i.label} key={i.name}>
698
+ <BusinessSearchSelect {...i.field.props} disabled={setDisabled(i.name)} />
699
+ </Form.Item>
700
+ </div>
701
+ )
702
+ }
703
+
704
+ if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
705
+ return (
706
+ <div>
707
+ <Form.Item name={i.name} label={i.label} key={i.name}>
708
+ <QueryMutipleInput onValueChange={(value) => {
709
+ form.setFieldsValue({
710
+ [i.name]: value
711
+ })
712
+ }} />
713
+ </Form.Item>
714
+ </div>
715
+ );
716
+ }
717
+
718
+ // 默认type是input
719
+ return (
720
+ <Form.Item name={i.name} label={i.label} key={i.name}>
721
+ <Input style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} disabled={setDisabled(i.name)} />
722
+ </Form.Item>
723
+ )
724
+ })
725
+ } else {
726
+ return null
727
+ }
728
+ }
729
+
730
+ const maxTagPlaceholder = (selectedValues) => {
731
+ const onClose = (e: any, item: any) => {
732
+ e.preventDefault();
733
+ 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)
734
+ onChange(newValue);
735
+ }
736
+ return (
737
+ <Tooltip title={selectedValues.map((i: any) => (
738
+ <Tag
739
+ closable={true}
740
+ onClose={(e) => onClose(e, i)}
741
+ style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
742
+ >
743
+ {i.label}
744
+ </Tag>
745
+ ))}>
746
+ {`+ ${selectedValues?.length}`}
747
+ </Tooltip>
748
+ )
749
+ }
750
+
751
+ const handleSelectOptionsShowValue = (specialBracket: boolean, noNeedSplit: boolean, item: object) => {
752
+ let showText = Array.isArray(item.textShowText) &&
753
+ item.textShowText.join(' ') || item.textShowText;
754
+ if (noNeedSplit) {
755
+ return item.text;
756
+ } else {
757
+ return specialBracket
758
+ ? `【${item.textShowKey}】${showText}`
759
+ : `${item.textShowKey} ${showText}`
760
+ }
761
+ };
762
+
763
+ return (
764
+ <div className={'search_select'}>
765
+ {fieldComponent ?
766
+ (<div onClick={() => {
767
+ fieldComponent.props?.onClick?.()
768
+ showModal()
769
+ }}>{fieldComponent}</div>) :
770
+ (<div className="search_select_show" id={`search_select_div_${uniqueValue}`}>
771
+ <Select
772
+ virtual
773
+ labelInValue={labelInValue}
774
+ value={value}
775
+ onChange={onChange}
776
+ disabled={props.disabled}
777
+ dropdownRender={menu => (
778
+ <>
779
+ <Input
780
+ value={searchValue}
781
+ style={{ width: '98%', marginLeft: '1%' }}
782
+ placeholder="请输入"
783
+ onChange={e => onSearchChange(e)}
784
+ onBlur={onSearchBlur}
785
+ onKeyDown={(e) => {
786
+ // 阻止多选的冒泡
787
+ e.stopPropagation()
788
+ }}
789
+ />
790
+ <Divider style={{ margin: '8px 0' }} />
791
+ {menu}
792
+ </>
793
+ )}
794
+ notFoundContent={
795
+ fetching ? <Spin size="small" /> :
796
+ <div style={{ textAlign: 'center' }}>
797
+ <div style={{ marginBottom: 16 }}>
798
+ <CopyOutlined style={{ fontSize: '50px' }} />
799
+ </div>
800
+ <div>无匹配结果,请更换其他内容再试</div>
801
+ </div>
802
+ }
803
+ onPopupScroll={SelectScroll}
804
+ style={{ width: needModalTable ? 'calc(100% - 30px)' : 'calc(100%)' }}
805
+ placeholder="请选择"
806
+ maxTagPlaceholder={maxTagPlaceholder}
807
+ {...currentSelectProps}
808
+ getPopupContainer={(triggerNode) => (getPopupContainer && getPopupContainer(triggerNode)) || triggerNode.parentElement}
809
+ >
810
+ {items.map(item => (
811
+ <Option key={item.value} label={item.text}>
812
+ {LightHeightOption({
813
+ text: handleSelectOptionsShowValue(specialBracket, noNeedSplit, item),
814
+ filterTxt: searchValue
815
+ })}
816
+ </Option>
817
+ ))}
818
+ </Select>
819
+ {needModalTable && (
820
+ <Button style={{ width: '30px', padding: '2px', height: 'auto' }} onClick={showModal} type="primary">
821
+ <SearchOutlined />
822
+ </Button>
823
+ )}
824
+ </div>)}
825
+ {needModalTable && isModalVisible && (
826
+ <Modal
827
+ width='80%'
828
+ title={modalTableProps?.modalTableTitle}
829
+ visible={isModalVisible}
830
+ onOk={handleOk}
831
+ onCancel={handleCancel}
832
+ footer={(selectMode || modalTableProps?.modalRadioNeedFooter) ? [
833
+ <Button key="back" onClick={handleCancel}>
834
+ 取消
835
+ </Button>,
836
+ <Button
837
+ key="submit"
838
+ type="primary"
839
+ onClick={handleOk}
840
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
841
+ >
842
+ 确定
843
+ </Button>,
844
+ ] : null}
845
+ {...(modalTableProps?.modalProps || {})}
846
+ >
847
+ <div className={'search_select_wrapper'}>
848
+ <div className={'search_select_wrapper_click_flag'} onClick={() => setCaretLeftFlag(!caretLeftFlag)}>
849
+ <CaretLeftOutlined className={caretLeftFlag ? 'search_select_wrapper_click_flag_arrow' : 'search_select_wrapper_click_flag_arrow_1'} />
850
+ </div>
851
+ <div className={caretLeftFlag ? 'search_select_wrapper_left' : 'search_select_wrapper_left1'}>
852
+ <div className={'select_list_columns'}>
853
+ <div className={'select_list_columns_tips'}>搜索</div>
854
+ <div className={'select_list_columns_formItems'}>
855
+ <Form form={form} layout='vertical' key='modalForm'>
856
+ {formItem(modalTableProps?.tableSearchForm)}
857
+ </Form>
858
+ </div>
859
+ </div>
860
+ <div className={'select_list_searchButton'}>
861
+ <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
862
+ <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
863
+ </div>
864
+ </div>
865
+ <div className={caretLeftFlag ? 'search_select_wrapper_right' : 'search_select_wrapper_right1'}>
866
+ <div>
867
+ <div className={'select_list_selectTips'}>
868
+ <div style={{ marginLeft: 8 }}>搜索结果共<span style={themeColor}>{tablePagination?.total || 0}</span>项{selectMode ? <span>, 本次已选<span style={themeColor}>{selectedRowKeys?.length || 0}</span>项</span> : ''}</div>
869
+ <div style={{ color: 'rgba(127, 127, 127, 0.6470588235294118)' }}>{selectMode ? '勾选后点击确定按钮完成选择' : '双击数据行或点击单选图标完成选择'}</div>
870
+ </div>
871
+ <Table
872
+ size='small'
873
+ rowSelection={rowSelection}
874
+ columns={modalTableProps?.tableColumns}
875
+ dataSource={tableData}
876
+ pagination={tablePagination}
877
+ onChange={handleTableChange}
878
+ rowKey={mappingValueField}
879
+ scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
880
+ onRow={record => {
881
+ return {
882
+ onDoubleClick: event => onDoubleClickSelect(event, record),
883
+ };
884
+ }}
885
+ />
886
+ {selectMode ? <div className={'select_list_selectAll'}><Checkbox indeterminate={indeterminate} checked={checkedAll} onChange={onChangeCheckAll} disabled={selectProps?.disabled || props?.disabled} /> 全选所有页面</div> : ''}
887
+ </div>
888
+ </div>
889
+ </div>
890
+ </Modal>
891
+ )}
892
+ </div>
893
+ );
894
+ });
895
+
896
+ export default SearchSelect;