@bit-sun/business-component 2.3.21 → 2.3.23

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