@bit-sun/business-component 3.1.10-alpha.1 → 3.1.10-alpha.11

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