@bit-sun/business-component 1.2.3 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/.umirc.ts +31 -16
  2. package/dist/components/Business/SearchSelect/BusinessUtils.d.ts +1 -1
  3. package/dist/components/Business/SearchSelect/common.d.ts +5 -1
  4. package/dist/components/Business/SearchSelect/utils.d.ts +2 -1
  5. package/dist/components/Business/TreeSearchSelect/index.d.ts +3 -0
  6. package/dist/components/Business/TreeSearchSelect/utils.d.ts +2 -0
  7. package/dist/components/Functional/AddSelect/index.d.ts +3 -0
  8. package/dist/components/Functional/TreeSearchSelect/index.d.ts +2 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.esm.js +1876 -89
  11. package/dist/index.js +1877 -87
  12. package/dist/utils/CheckOneUser/index.d.ts +1 -1
  13. package/package.json +1 -1
  14. package/src/components/Business/CommodityEntry/index.md +2 -2
  15. package/src/components/Business/CommodityEntry/index.tsx +1 -1
  16. package/src/components/Business/SearchSelect/BusinessUtils.ts +85 -6
  17. package/src/components/Business/SearchSelect/common.ts +20 -1
  18. package/src/components/Business/SearchSelect/index.md +60 -30
  19. package/src/components/Business/SearchSelect/index.tsx +2 -1
  20. package/src/components/Business/SearchSelect/utils.ts +27 -2
  21. package/src/components/Business/TreeSearchSelect/index.md +126 -0
  22. package/src/components/Business/TreeSearchSelect/index.tsx +34 -0
  23. package/src/components/Business/TreeSearchSelect/utils.ts +60 -0
  24. package/src/components/Functional/AddSelect/index.less +275 -0
  25. package/src/components/Functional/AddSelect/index.md +118 -0
  26. package/src/components/Functional/AddSelect/index.tsx +795 -0
  27. package/src/components/Functional/SearchSelect/index.tsx +24 -7
  28. package/src/components/Functional/TreeSearchSelect/index.md +47 -0
  29. package/src/components/Functional/TreeSearchSelect/index.tsx +148 -0
  30. package/src/index.ts +8 -0
@@ -0,0 +1,795 @@
1
+ // @ts-nocheck
2
+ import React, { useState, useEffect } from 'react';
3
+ import { useDebounceFn } from 'ahooks';
4
+ import { Input, Button, Modal, Select, InputNumber, message, Spin, Form, Table, Checkbox, TreeSelect, Tooltip, Tag } from 'antd';
5
+ import { SearchOutlined, CopyOutlined, CloseCircleOutlined } from '@ant-design/icons';
6
+ import axios from 'axios';
7
+ import { stringify } from 'querystring';
8
+ import _ from "loadsh"
9
+ import './index.less';
10
+ import { BusinessSearchSelect, QueryMutipleInput } from '@/index';
11
+
12
+ const { Option } = Select;
13
+
14
+ const AddSelect = (props: any) => {
15
+ const {
16
+ value, // 必传
17
+ onChange,
18
+ selectProps = {},
19
+ modalTableProps = {},
20
+ labelInValue = false,
21
+ requestConfig,
22
+ ctx,
23
+ sourceName,
24
+ needModalTable = true,
25
+ getPopupContainer = undefined,
26
+ onSaveCallback
27
+ } = props;
28
+ const { url, otherParams, isMap, fixedparameter, fieldValToParam, mappingTextField = 'name', mappingTextShowKeyField, mappingValueField = 'code', mappingTextShowTextField } = requestConfig || {};
29
+ const resultSourceKey = sourceName || requestConfig?.sourceName || 'supplierCode'
30
+
31
+ const selectMode = selectProps?.mode // 设定当前选择器 为单选或者多选模式 无设定为单选模式(默认)
32
+ const initVal = value || (selectMode ? [] : null);
33
+ const pageSize = 100 // 下拉框默认分页 条数
34
+ const tableInitPageSize = 10 // 弹框默认分页 条数
35
+ const currentPage = 1
36
+ const selectParamsKey = requestConfig?.filter || 'qp-codeAndName-like'
37
+ const selectParamsInitKey = requestConfig?.filterInit || selectParamsKey
38
+ const currentSelectProps = {
39
+ ...selectProps,
40
+ // 以下属性不可更改----设计配置项
41
+ showSearch: false,
42
+ filterOption: false,
43
+ allowClear: true,
44
+ listHeight: 160,
45
+ optionLabelProp: "label",
46
+ autoClearSearchValue: false
47
+ }
48
+ const [items, setItems] = useState([]);
49
+ const [scrollPage, setScrollPage] = useState(1);
50
+ const [itemsTotal, setItemsTotal] = useState(0);
51
+ const [fetching, setFetching] = useState(false);
52
+ const [searchValue, setSearchValue] = useState('');
53
+ const [isModalVisible, setIsModalVisible] = useState(false);
54
+ const [popvalue, setPopValue] = useState(initVal);
55
+ const [uniqueValue, setUniqueValue] = useState(sourceName)
56
+ const { run } = useDebounceFn(
57
+ (v?: any) => {
58
+ // 优化搜索参数 支持传多个
59
+ let searchParams = {};
60
+ if (typeof selectParamsKey === 'string') {
61
+ searchParams = v ? { [selectParamsInitKey]: initVal } : { [selectParamsKey]: searchValue }
62
+ }
63
+ if (Array.isArray(selectParamsKey)) {
64
+ selectParamsKey.forEach((i: any) => {
65
+ searchParams = { ...searchParams, [i]: searchValue }
66
+ })
67
+ }
68
+ // 防抖函数 待定
69
+ getData(searchParams)
70
+ },
71
+ {
72
+ wait: 1000,
73
+ },
74
+ );
75
+
76
+ const [form] = Form.useForm();
77
+ const [caretLeftFlag, setCaretLeftFlag] = useState(true);
78
+ const [tableData, setTableData] = useState([]);
79
+ const [tablePagination, setTablePagination] = useState({ total: 0, size: "small", current: 1, pageSize: tableInitPageSize })
80
+ const [selectedRowKeys, setSelectedRowKeys] = useState([]);
81
+ const [doubleArr, setDoubleArr] = useState([]); // 存放双数组的数组
82
+ const [checkedAll, setCheckedAll] = useState(false)
83
+ const [indeterminate, setIndeterminate] = useState(false)
84
+ const [tableFormParams, setTableFormParams] = useState({});
85
+
86
+ // 获取数据源 (type: 1下拉框 2弹框 不传值默认为下拉框)
87
+ const getData = (params = {}, type = 1) => {
88
+ if (!requestConfig) return;
89
+
90
+ setFetching(true)
91
+
92
+ // 处理dependence参数
93
+ const fixedParam = {};
94
+ if (fixedparameter && fieldValToParam && ctx) {
95
+ fixedparameter.forEach((item: any, index: any) => {
96
+ const fixedParamVal = ctx.form.getFieldValue(fieldValToParam[index]);
97
+ if (fixedParamVal) {
98
+ fixedParam[item] = fixedParamVal;
99
+ form.setFieldsValue({ ...form?.getFieldsValue(), [item]: fixedParamVal })
100
+ }
101
+ });
102
+ }
103
+
104
+ // 数组对象处理,对带有特殊标记的name进行处理
105
+ for (const key in params) {
106
+ if (Object.prototype.hasOwnProperty.call(params, key)) {
107
+ const element = params[key];
108
+ if (element && key.indexOf('*number*') >= 0) {
109
+ const dataParams = key.split('*number*');
110
+ dataParams.forEach((value, index) => {
111
+ params[value] = element[index];
112
+ });
113
+ delete params[key];
114
+ } else if (element && key.indexOf('*address*') >= 0) {
115
+ const dataParams = key.split('*address*');
116
+ dataParams.forEach((value, index) => {
117
+ params[value] = element.PCDCode[index];
118
+ });
119
+ delete params[key];
120
+ } else if (element && key.indexOf('*costType*') >= 0) {
121
+ const dataParams = key.split('*costType*');
122
+ // eslint-disable-next-line prefer-destructuring
123
+ params[dataParams[0]] = element[1];
124
+ delete params[key];
125
+ } else if (element && key.indexOf('*fullDate*') >= 0) {
126
+ const dataParams = key.split('*fullDate*');
127
+ dataParams.forEach((value, index) => {
128
+ if (index === 0) {
129
+ params[value] = moment(element[index])
130
+ .millisecond(0)
131
+ .second(0)
132
+ .minute(0)
133
+ .hour(0)
134
+ .format('YYYY-MM-DD HH:mm:ss');
135
+ } else {
136
+ params[value] = moment(element[index])
137
+ .millisecond(59)
138
+ .second(59)
139
+ .minute(59)
140
+ .hour(23)
141
+ .format('YYYY-MM-DD HH:mm:ss');
142
+ }
143
+ });
144
+ delete params[key];
145
+ } else if (typeof element === 'boolean' && key.indexOf('*checkBox*') >= 0) {
146
+ const dataParams = key.split('*checkBox*');
147
+ if (element) {
148
+ params[dataParams[0]] = 0
149
+ }
150
+ delete params[key];
151
+ } else if (element && key.indexOf('*cascader*') >= 0) {
152
+ const dataParams = key.split('*cascader*');
153
+ params[dataParams[0]] = element[element.length - 1]
154
+ delete params[key];
155
+ } else if (element && key.indexOf('*date*') >= 0) {
156
+ const dataParams = key.split('*date*')
157
+ dataParams.forEach((value, index) => {
158
+ if (index === 0) {
159
+ params[value] = moment(element[index])
160
+ .format('YYYY-MM-DD');
161
+ } else {
162
+ params[value] = moment(element[index])
163
+ .format('YYYY-MM-DD');
164
+ }
165
+ });
166
+ delete params[key];
167
+ }
168
+ else if (element && key.indexOf('*') >= 0) {
169
+ const dataParams = key.split('*');
170
+ dataParams.forEach((value, index) => {
171
+ params[value] = element[index].format('YYYY-MM-DD HH:mm:ss');
172
+ });
173
+ delete params[key];
174
+ } else if (element && key.indexOf('_selectNumberRange') >= 0) { // key = xxxxx_selectNumberRange qp-xxxxx-gt
175
+ const dataParams = key.split('_selectNumberRange')[0]
176
+ if (params[key][0] === 'range') {
177
+ if (params[key][1][0]) {
178
+ params[`qp-${dataParams}-ge`] = params[key][1][0]
179
+ }
180
+ if (params[key][1][1]) {
181
+ params[`qp-${dataParams}-le`] = params[key][1][1]
182
+ }
183
+ } else {
184
+ params[`qp-${dataParams}-${params[key][0]}`] = params[key][1]
185
+ }
186
+ delete params[key]
187
+ } else if (Array.isArray(element)) {
188
+ params[key] = element.join(',');
189
+ } else if (element == null || element === undefined || String(element).trim() === '') {
190
+ delete params[key]
191
+ }
192
+ }
193
+ }
194
+
195
+ const queryParams = {
196
+ pageSize,
197
+ currentPage,
198
+ ...otherParams, // 默认参数
199
+ ...fixedParam,
200
+ ...params,
201
+ }
202
+ axios
203
+ .get(`${url}?${stringify(queryParams)}`)
204
+ .then((result: any) => {
205
+ setFetching(false)
206
+ result = result.data;
207
+ if ((result?.status && result.status !== '0') || (result?.code && result.code !== '000000')) {
208
+ message.error(result.msg);
209
+ return;
210
+ }
211
+ const res = result.data;
212
+ let source = [];
213
+ if (isMap) {
214
+ source = Object.keys(res).map((d, i) => {
215
+ return {
216
+ text: Object.values(res)[i],
217
+ value: d,
218
+ };
219
+ });
220
+ } else {
221
+ const keys = res.list ? 'list' : 'items';
222
+ source = res
223
+ ? res[keys]
224
+ ? res[keys].map((item: any) => {
225
+ let textShowText = item[mappingTextField]
226
+ if (mappingTextShowTextField) {
227
+ textShowText = []
228
+ if (Array.isArray(mappingTextShowTextField)) {
229
+ mappingTextShowTextField.forEach((r: any) => {
230
+ textShowText.push(item[r])
231
+ })
232
+ } else {
233
+ textShowText = item[mappingTextShowTextField]
234
+ }
235
+ }
236
+ return {
237
+ ...item,
238
+ text: item[mappingTextField],
239
+ textShowText,
240
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
241
+ value: item[mappingValueField],
242
+ };
243
+ })
244
+ : Array.isArray(res) &&
245
+ res?.map((item: Record<string, any>) => {
246
+ let textShowText = item[mappingTextField]
247
+ if (mappingTextShowTextField) {
248
+ textShowText = []
249
+ if (Array.isArray(mappingTextShowTextField)) {
250
+ mappingTextShowTextField.forEach((r: any) => {
251
+ textShowText.push(item[r])
252
+ })
253
+ } else {
254
+ textShowText = item[mappingTextShowTextField]
255
+ }
256
+ }
257
+ return {
258
+ ...item,
259
+ text: item[mappingTextField],
260
+ textShowText,
261
+ textShowKey: item[mappingTextShowKeyField || mappingValueField],
262
+ value: item[mappingValueField],
263
+ };
264
+ })
265
+ : [];
266
+ }
267
+ source = Array.isArray(source) ? source : []
268
+ if (type === 1) {
269
+ ctx?.form?.setFieldSource(resultSourceKey, source)
270
+ setItems(source)
271
+ setItemsTotal(Number(res?.total || res?.totalCount || source.length))
272
+ } else {
273
+ setTableData(source)
274
+ 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)) })
275
+ }
276
+ })
277
+ .catch((err) => { setFetching(false) });
278
+ }
279
+
280
+ const SelectScroll = e => {
281
+ e.persist();
282
+ const { target } = e;
283
+ const totalPage = Math.ceil(itemsTotal / pageSize)
284
+ // 判断是否滑动到底部
285
+ const isTouchGround = target.scrollTop + target.offsetHeight === target.scrollHeight // >=scrollHeight
286
+ // 判断数据是否还没有加载到了最后一页
287
+ const canPageAdd = scrollPage < totalPage
288
+ if (isTouchGround && canPageAdd) {
289
+ const nextScrollPage = scrollPage + 1;
290
+ setScrollPage(nextScrollPage);
291
+ getData({ currentPage: nextScrollPage }); // 调用api方法
292
+ }
293
+
294
+ //判断是否滑动到顶部
295
+ const isTouchTop = target.scrollTop === 0 // <=0
296
+ // 判断数据是否到第一页
297
+ const canPageJian = scrollPage > 1
298
+ if (isTouchTop && canPageJian) {
299
+ const preScrollPage = scrollPage - 1;
300
+ setScrollPage(preScrollPage);
301
+ getData({ currentPage: preScrollPage }); // 调用api方法
302
+ }
303
+ }
304
+
305
+ useEffect(() => {
306
+ run('init')
307
+ }, [])
308
+
309
+ useEffect(() => {
310
+ if (value) {
311
+ setPopValue(value);
312
+ }
313
+ }, [value]);
314
+
315
+ useEffect(() => {
316
+ makeUniqueValue();
317
+ }, [sourceName])
318
+
319
+ const showModal = () => {
320
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
321
+ setIsModalVisible(true);
322
+ // 回显
323
+ if (value) {
324
+ if (selectMode) {
325
+ setSelectedRowKeys(labelInValue ? value.map(i => i.key) : value)
326
+ setPopValue(labelInValue ? value.map(i => ({ value: i.key, text: i.label })) : value.map(i => ({ value: i })));
327
+ setIndeterminate(!!value.length && value.length < itemsTotal);
328
+ setCheckedAll(itemsTotal && value.length === itemsTotal);
329
+ // 需清空数据
330
+ if (!value.length) {
331
+ setDoubleArr([])
332
+ }
333
+ } else {
334
+ setSelectedRowKeys(labelInValue ? [value.key] : [value])
335
+ setPopValue(labelInValue ? [{ value: value.key, text: value.label }] : [{ value: value }]);
336
+ }
337
+ }
338
+ };
339
+
340
+ const handleSelectOver = (selectedValue: any) => {
341
+ if (selectedValue?.length) {
342
+ formaData(selectedValue);
343
+ // 解决选择最后1页的sku,返回后,不显示名称问题
344
+ const source = _.uniqBy(items.concat(selectedValue), 'value')
345
+ ctx?.form?.setFieldSource(resultSourceKey, source)
346
+ setItems(source)
347
+ }
348
+ }
349
+
350
+ const handleOk = (isContinue) => {
351
+ if(!popvalue.length) {
352
+ message.warning('至少选中一条数据')
353
+ return;
354
+ }
355
+ // handleSelectOver(popvalue)
356
+ if(onSaveCallback) {
357
+ onSaveCallback(popvalue).then(res => {
358
+ if(true) {
359
+ message.success('保存成功')
360
+ deleteSelectRows();
361
+ !isContinue && handleCancel();
362
+ } else {
363
+ message.error(res)
364
+ }
365
+ }).catch(Error => {
366
+ message.error(Error)
367
+ })
368
+ } else {
369
+ !isContinue && handleCancel();
370
+ }
371
+ };
372
+
373
+ const formaData = (value) => {
374
+ if (labelInValue) {
375
+ const formatResult = value.map((i: any) => ({ key: i[mappingValueField], label: i[mappingTextField], value: i[mappingValueField] }))
376
+ onChange(selectMode ? formatResult : formatResult[0])
377
+ } else {
378
+ const formatResult = selectMode ? value.map((i: any) => i.value) : _.get(value[0], 'value')
379
+ onChange(formatResult)
380
+ }
381
+ };
382
+
383
+ const handleCancel = () => {
384
+ form.resetFields();
385
+ setTableFormParams({});
386
+ setIsModalVisible(false);
387
+ if (selectMode) {
388
+ run();
389
+ }
390
+ };
391
+
392
+ const onSearchChange = (e) => {
393
+ setSearchValue(e.target.value);
394
+ run();
395
+ }
396
+
397
+ const onSearchBlur = () => {
398
+ setSearchValue('')
399
+ run();
400
+ }
401
+
402
+ const onSearchTable = () => {
403
+ const params = form.getFieldsValue();
404
+ setTableFormParams(params);
405
+ getData({ ...params, pageSize: tableInitPageSize }, 2)
406
+ if (selectMode) {
407
+ getData(params)
408
+ }
409
+ }
410
+
411
+ const onResetTable = () => {
412
+ form.resetFields();
413
+ setTableFormParams({});
414
+ getData({ pageSize: tableInitPageSize, currentPage: 1 }, 2)
415
+ }
416
+
417
+ const handleTableChange = (pagination) => {
418
+ getData({ ...tableFormParams, pageSize: pagination.pageSize, currentPage: pagination.current }, 2)
419
+ }
420
+
421
+ // 扁平化二维数组的方法
422
+ const mapRows = params => {
423
+ var res = [];
424
+ for (var i = 0; i < params.length; i++) {
425
+ if (Array.isArray(params[i])) {
426
+ // 去重
427
+ res = _.uniqBy(res.concat(mapRows(params[i])), 'value');
428
+ } else {
429
+ res.push(params[i]);
430
+ // 去重
431
+ res = _.uniqBy(res, 'value')
432
+ }
433
+ }
434
+ return res.filter(Boolean); //去掉undefined的情况
435
+ };
436
+
437
+ const onChangeSelectedKeys = (selectKeys, selectRows) => {
438
+ setPopValue(selectRows);
439
+ setSelectedRowKeys(selectKeys)
440
+ // setIndeterminate(!!filterRows.length && filterRows.length < tablePagination?.total);
441
+ // setCheckedAll(filterRows.length === tablePagination?.total);
442
+ }
443
+
444
+ // 生成唯一值
445
+ const makeUniqueValue = () => {
446
+ const generateUnitKey = (((1 + Math.random()) * 0x10000) | 0).toString(16);
447
+ setUniqueValue(generateUnitKey);
448
+ return generateUnitKey;
449
+ }
450
+
451
+ const rowSelection = {
452
+ type: 'checkbox',
453
+ selectedRowKeys,
454
+ preserveSelectedRowKeys: true,
455
+ onChange: (sks, srs) => {
456
+ onChangeSelectedKeys(sks, srs)
457
+ },
458
+ getCheckboxProps: () => ({
459
+ disabled: selectProps?.disabled || props?.disabled,
460
+ }),
461
+ };
462
+
463
+ const onDoubleClickSelect = (e, record) => {
464
+ if (!selectMode) {
465
+ const srs = [JSON.parse(JSON.stringify(record))]
466
+ const sks = srs.map((i: any) => i.value)
467
+ onChangeSelectedKeys(sks, srs)
468
+ }
469
+ }
470
+
471
+ const themeColor = { color: '#005CFF' }
472
+
473
+ const formItem = (list) => {
474
+ if (isModalVisible && list?.length) {
475
+ return list.map((i: any, index) => {
476
+ if (i?.type === 'select' || i?.field?.type === 'select') {
477
+ return (
478
+ <Form.Item name={i.name} label={i.label} key={i.name}>
479
+ <Select style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}>
480
+ {i?.initialSource?.length && i?.initialSource.map((m: any) => (
481
+ <Option value={m.value} key={m.value}>{m.text}</Option>
482
+ ))}
483
+ </Select>
484
+ </Form.Item>
485
+ )
486
+ }
487
+
488
+ if (i?.type === 'treeSelect' || i?.field?.type === 'treeSelect') {
489
+ return (
490
+ <Form.Item name={i.name} label={i.label} key={i.name}>
491
+ <TreeSelect style={{ width: '100%' }} placeholder='请选择' {...i?.field?.props}></TreeSelect>
492
+ </Form.Item>
493
+ )
494
+ }
495
+
496
+ if (i?.type === 'BusinessSearchSelect' || i?.field?.type === 'BusinessSearchSelect') {
497
+ return (
498
+ <div>
499
+ <Form.Item name={i.name} label={i.label} key={i.name}>
500
+ <BusinessSearchSelect {...i.field.props} />
501
+ </Form.Item>
502
+ </div>
503
+ )
504
+ }
505
+
506
+ if (i?.type === 'multipleQueryInput' || i?.field?.type === 'multipleQueryInput') {
507
+ return (
508
+ <div>
509
+ <Form.Item name={i.name} label={i.label} key={i.name}>
510
+ <QueryMutipleInput onValueChange={(value) => {
511
+ form.setFieldsValue({
512
+ [i.name]: value
513
+ })
514
+ }} />
515
+ </Form.Item>
516
+ </div>
517
+ );
518
+ }
519
+
520
+ // 默认type是input
521
+ return (
522
+ <Form.Item name={i.name} label={i.label} key={i.name}>
523
+ <Input id={index === 0 ? "2345234242342" : 'index'} style={{ width: '100%' }} placeholder='请输入' allowClear maxLength={100} {...i?.field?.props} />
524
+ </Form.Item>
525
+ )
526
+ })
527
+ } else {
528
+ return null
529
+ }
530
+ }
531
+
532
+ const maxTagPlaceholder = (selectedValues) => {
533
+ const onClose = (e: any, item: any) => {
534
+ e.preventDefault();
535
+ 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)
536
+ onChange(newValue);
537
+ }
538
+ return (
539
+ <Tooltip title={selectedValues.map((i: any) => (
540
+ <Tag
541
+ closable={true}
542
+ onClose={(e) => onClose(e, i)}
543
+ style={{ marginRight: 3, background: '#f5f5f5', height: '24px', border: '1px solid #f0f0f0' }}
544
+ >
545
+ {i.label}
546
+ </Tag>
547
+ ))}>
548
+ {`+ ${selectedValues?.length}`}
549
+ </Tooltip>
550
+ )
551
+ }
552
+
553
+ const deleteSelectRows = () => {
554
+ setPopValue([])
555
+ setSelectedRowKeys([])
556
+ }
557
+
558
+ const deleteRecord = (record) => {
559
+ setPopValue(popvalue.filter(item => item.skuCode !== record.skuCode))
560
+ setSelectedRowKeys([...selectedRowKeys.filter(item => item !== record.skuCode)])
561
+ }
562
+
563
+ let inputIndex = 0;
564
+ let selectColumns = [... modalTableProps.selectColumn.map(item => {
565
+ const inputLength = modalTableProps.selectColumn.filter(item => item.isInputItem).length
566
+ const currentIndex = inputIndex;
567
+ if (item.isInputItem) {
568
+ inputIndex++;
569
+ return {
570
+ ...item,
571
+ render: (text, record, index) => {
572
+ return (
573
+ <InputNumber
574
+ defaultValue={text || 0}
575
+ min={0}
576
+ keyboard={false}
577
+ onChange={(value) => {
578
+ record['count'] = value
579
+ }}
580
+ // onFocus={(e)=> {
581
+ // let dom1 = e.currentTarget;
582
+ // dom1.setSelectionRange(100, 0);
583
+ // dom1.select(text);
584
+ // }}
585
+ onKeyDown={(e) => {
586
+ if(e.keyCode === 13 && e.ctrlKey) {
587
+ handleOk(true)
588
+ document.getElementById("2345234242342")?.focus()
589
+ }
590
+ if(e.keyCode === 8 && e.ctrlKey) {
591
+ message.success('删除当前行')
592
+ e.stopPropagation();
593
+ e.preventDefault();
594
+ let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
595
+ if (dom) {
596
+ dom.select();
597
+ dom.focus();
598
+ dom.scrollIntoView(false)
599
+ }
600
+ dom = null
601
+ deleteRecord(record, popvalue);
602
+ }
603
+ if (e.keyCode === 37 && e.shiftKey) { // 左滑动
604
+ e.stopPropagation();
605
+ e.preventDefault();
606
+ let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
607
+ if (dom) {
608
+ dom.select();
609
+ dom.focus();
610
+ dom.scrollIntoView(false)
611
+ }
612
+ dom = null
613
+ }
614
+ if (e.keyCode === 39 && e.shiftKey) { // 右滑
615
+ e.stopPropagation();
616
+ e.preventDefault();
617
+ let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
618
+ if (dom) {
619
+ dom.select();
620
+ dom.focus();
621
+ dom.scrollIntoView(false)
622
+ }
623
+ dom = null
624
+ }
625
+ if (e.keyCode === 40) {
626
+ e.stopPropagation();
627
+ e.preventDefault();
628
+ let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
629
+ if (dom) {
630
+ dom.select();
631
+ dom.focus();
632
+ dom.scrollIntoView(false)
633
+ }
634
+ dom = null
635
+ } else if (e.keyCode === 38) {
636
+ e.stopPropagation();
637
+ e.preventDefault();
638
+ let dom1 = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
639
+ if (dom1) {
640
+ // dom1.value=""
641
+ // dom1.setSelectionRange(100, 0);
642
+ dom1.select();
643
+ dom1.focus();
644
+ dom1.scrollIntoViewIfNeeded(false)
645
+ // dom1.value=record['count']
646
+ }
647
+ dom1 = null
648
+ } else if (e.keyCode === 9 && index === selectedRowKeys.length - 1 && currentIndex === inputLength - 1) {
649
+ e.stopPropagation();
650
+ e.preventDefault();
651
+ }
652
+ }}
653
+ />
654
+ );
655
+ },
656
+ }
657
+ }
658
+
659
+ return item
660
+ }), {
661
+ title: '操作',
662
+ width: 150,
663
+ fixed: 'right',
664
+ render: (text, record, index) => {
665
+ return (
666
+ <Button onClick={() => {
667
+ deleteRecord(record)
668
+ }} type={"link"}>删除</Button>
669
+ )
670
+ }
671
+ },]
672
+
673
+ return (
674
+ <div className={'add_select'}>
675
+ <div className="add_select_show" id={`add_select_div_${uniqueValue}`}>
676
+ <Button onClick={showModal} type="primary">
677
+ 添加
678
+ </Button>
679
+ </div>
680
+ {needModalTable && isModalVisible && (
681
+ <Modal
682
+ width='1200px'
683
+ style={{ top: 20 }}
684
+ bodyStyle={{ padding: '0px' }}
685
+ // title={modalTableProps?.modalTableTitle}
686
+ visible={isModalVisible}
687
+ onOk={handleOk}
688
+ closable={false}
689
+ onCancel={handleCancel}
690
+ footer={selectMode ? [
691
+ <Button key="back" onClick={handleCancel}>
692
+ 取消
693
+ </Button>,
694
+ <Button
695
+ key="submit"
696
+ style={{color: '#005CFF', borderColor: '#005CFF'}}
697
+ onClick={() => {handleOk(true)}}
698
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
699
+ >
700
+ 保存并继续
701
+ </Button>,
702
+ <Button
703
+ key="submit"
704
+ type="primary"
705
+ onClick={() => {handleOk(false)}}
706
+ disabled={!tableData.length || (selectProps?.disabled || props?.disabled)}
707
+ >
708
+ 确定
709
+ </Button>,
710
+ ] : null}
711
+ >
712
+ <div>
713
+ <div className='add_select_header'>
714
+ {modalTableProps?.modalTableTitle}
715
+ <span><span>*</span> &nbsp;快捷键:【Tab】-跳格切换;【Shift+←、→】-当前行左、右移动;【 ↑、↓】-当前列上、下移动;【ctrl+Enter】-保存并继续;【ctrl+Delete】-删除当前行;</span>
716
+ <span className='add_select_header_close'><CloseCircleOutlined style={{fontSize: '20px'}} onClick={handleCancel} /></span>
717
+ </div>
718
+ <div className={'add_select_wrapper'}>
719
+ <div className={caretLeftFlag ? 'add_select_wrapper_left' : 'add_select_wrapper_left1'}>
720
+ <div className={'select_list_columns'}>
721
+ <div className={'select_list_columns_formItems'}>
722
+ <Form form={form} layout='vertical' key='modalForm'>
723
+ {formItem(modalTableProps?.tableSearchForm)}
724
+ </Form>
725
+ </div>
726
+ </div>
727
+ <div className={'select_list_searchButton'}>
728
+ <Button key='reset' className={'select_list_button_space'} onClick={onResetTable}>重置</Button>
729
+ <Button key='search' type="primary" onClick={onSearchTable}>查询</Button>
730
+ </div>
731
+ </div>
732
+ <div className={caretLeftFlag ? 'add_select_wrapper_right' : 'add_select_wrapper_right1'}>
733
+ <div>
734
+ <div className={'select_list_selectTips'}>
735
+ <div style={{ marginLeft: 8 }}>搜索结果共&nbsp;<span style={themeColor}>{tablePagination?.total || 0}</span>&nbsp;项{selectMode ? <span>, 本次已选&nbsp;<span style={themeColor}>{selectedRowKeys?.length || 0}</span>&nbsp;项</span> : ''}</div>
736
+ </div>
737
+ <Table
738
+ size='small'
739
+ rowSelection={rowSelection}
740
+ columns={[...modalTableProps?.tableColumns]}
741
+ dataSource={tableData}
742
+ pagination={tablePagination}
743
+ loading={fetching}
744
+ onChange={handleTableChange}
745
+ rowKey={mappingValueField}
746
+ rowClassName={'row-class'}
747
+ scroll={{ y: 500 }}
748
+ />
749
+ </div>
750
+ </div>
751
+ {/* <div>
752
+ <Table
753
+ size='small'
754
+ columns={modalTableProps?.tableColumns}
755
+ dataSource={mapRows(doubleArr)}
756
+ rowKey={mappingValueField}
757
+ scroll={{ x: modalTableProps.overScrollX || 'max-content', y: modalTableProps.overScrollY || null }}
758
+ onRow={record => {
759
+ return {
760
+ onDoubleClick: event => onDoubleClickSelect(event, record),
761
+ };
762
+ }}
763
+ />
764
+ </div> */}
765
+ </div>
766
+ <div className={'add_select_wrapper_select'}>
767
+ <div className={'select_list_selectTips'}>
768
+ <div style={{ marginLeft: 8 }}><span>本次已选&nbsp;<span style={themeColor}>{selectedRowKeys?.length || 0}</span>&nbsp;项</span></div>
769
+ <div style={{ marginRight: 8 }}><span onClick={deleteSelectRows} style={{ ...themeColor, cursor: 'pointer' }}>清空所选商品</span></div>
770
+ </div>
771
+ <Table
772
+ size='small'
773
+ // rowSelection={rowSelection}
774
+ columns={selectColumns}
775
+ dataSource={popvalue}
776
+ pagination={false}
777
+ // onChange={handleTableChange}
778
+ rowKey={mappingValueField}
779
+ rowClassName={'row-class'}
780
+ scroll={{ y: 500 }}
781
+ onRow={record => {
782
+ return {
783
+ onDoubleClick: event => onDoubleClickSelect(event, record),
784
+ };
785
+ }}
786
+ />
787
+ </div>
788
+ </div>
789
+ </Modal>
790
+ )}
791
+ </div>
792
+ );
793
+ };
794
+
795
+ export default AddSelect;