@bit-sun/business-component 3.1.5 → 3.1.6

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