@bit-sun/business-component 2.3.0 → 2.3.2

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