@bit-sun/business-component 2.1.1 → 2.1.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 (137) hide show
  1. package/.editorconfig +16 -16
  2. package/.fatherrc.ts +5 -5
  3. package/.gitlab-ci.yml +174 -174
  4. package/.prettierignore +7 -7
  5. package/.prettierrc +11 -11
  6. package/.umirc.ts +74 -74
  7. package/README.md +27 -27
  8. package/dist/index.esm.js +119 -92
  9. package/dist/index.js +119 -92
  10. package/dist/utils/enumConfig.d.ts +1 -0
  11. package/dist/utils/utils.d.ts +2 -0
  12. package/docs/index.md +21 -21
  13. package/lib/assets/drag.svg +17 -17
  14. package/lib/assets/exportFail.svg +37 -37
  15. package/lib/assets/exportProcessing.svg +28 -28
  16. package/lib/assets/exportSuccess.svg +34 -34
  17. package/lib/assets/label_icon_bottom.svg +25 -25
  18. package/lib/assets/upExport.svg +22 -22
  19. package/package.json +71 -71
  20. package/src/assets/32.svg +27 -27
  21. package/src/assets/addIcon.svg +17 -17
  22. package/src/assets/allfunc.svg +27 -27
  23. package/src/assets/arrowRight.svg +24 -24
  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/components/Business/AddSelectBusiness/index.md +41 -41
  47. package/src/components/Business/AddSelectBusiness/index.tsx +290 -290
  48. package/src/components/Business/BsLayouts/Components/AllFunc/drawContent.tsx +111 -111
  49. package/src/components/Business/BsLayouts/Components/AllFunc/index.less +153 -153
  50. package/src/components/Business/BsLayouts/Components/AllFunc/index.tsx +70 -70
  51. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.less +90 -90
  52. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/index.tsx +37 -37
  53. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/leftTree.tsx +242 -242
  54. package/src/components/Business/BsLayouts/Components/CustomerMenu/MenuSetting/rightTree.tsx +384 -384
  55. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/DrawContent.tsx +285 -285
  56. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/customMenuHeader.tsx +74 -74
  57. package/src/components/Business/BsLayouts/Components/CustomerMenu/globalMenu/drawContent.less +170 -170
  58. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.less +64 -64
  59. package/src/components/Business/BsLayouts/Components/CustomerMenu/index.tsx +153 -153
  60. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.less +72 -72
  61. package/src/components/Business/BsLayouts/Components/GlobalHeader/index.tsx +157 -157
  62. package/src/components/Business/BsLayouts/Components/RightContent/LoginModal.tsx +85 -85
  63. package/src/components/Business/BsLayouts/Components/RightContent/home.less +218 -218
  64. package/src/components/Business/BsLayouts/Components/RightContent/index.tsx +156 -156
  65. package/src/components/Business/BsLayouts/Components/SearchFunc/index.less +160 -160
  66. package/src/components/Business/BsLayouts/Components/SearchFunc/index.tsx +75 -75
  67. package/src/components/Business/BsLayouts/index.less +79 -79
  68. package/src/components/Business/BsLayouts/index.tsx +1469 -1465
  69. package/src/components/Business/BsLayouts/service.ts +10 -10
  70. package/src/components/Business/BsLayouts/utils.tsx +210 -210
  71. package/src/components/Business/BsSulaQueryTable/index.less +219 -219
  72. package/src/components/Business/BsSulaQueryTable/index.tsx +505 -505
  73. package/src/components/Business/BsSulaQueryTable/setting.tsx +801 -799
  74. package/src/components/Business/BsSulaQueryTable/utils.less +65 -65
  75. package/src/components/Business/BsSulaQueryTable/utils.tsx +688 -688
  76. package/src/components/Business/CommodityEntry/index.md +70 -70
  77. package/src/components/Business/CommodityEntry/index.tsx +80 -80
  78. package/src/components/Business/CommonAlert/index.tsx +23 -23
  79. package/src/components/Business/CommonGuideWrapper/index.less +111 -111
  80. package/src/components/Business/CommonGuideWrapper/index.md +39 -39
  81. package/src/components/Business/CommonGuideWrapper/index.tsx +83 -83
  82. package/src/components/Business/DetailPageWrapper/index.less +79 -79
  83. package/src/components/Business/DetailPageWrapper/index.tsx +335 -334
  84. package/src/components/Business/DetailPageWrapper/utils.tsx +102 -100
  85. package/src/components/Business/HomePageWrapper/index.less +33 -33
  86. package/src/components/Business/HomePageWrapper/index.md +45 -45
  87. package/src/components/Business/HomePageWrapper/index.tsx +162 -162
  88. package/src/components/Business/SearchSelect/BusinessUtils.ts +1458 -1458
  89. package/src/components/Business/SearchSelect/common.ts +53 -53
  90. package/src/components/Business/SearchSelect/index.md +1137 -1137
  91. package/src/components/Business/SearchSelect/index.tsx +51 -51
  92. package/src/components/Business/SearchSelect/utils.ts +100 -100
  93. package/src/components/Business/StateFlow/index.less +130 -130
  94. package/src/components/Business/StateFlow/index.md +60 -60
  95. package/src/components/Business/StateFlow/index.tsx +29 -29
  96. package/src/components/Business/TreeSearchSelect/index.md +126 -126
  97. package/src/components/Business/TreeSearchSelect/index.tsx +34 -34
  98. package/src/components/Business/TreeSearchSelect/utils.ts +60 -60
  99. package/src/components/Business/columnSettingTable/columnSetting.tsx +765 -763
  100. package/src/components/Business/columnSettingTable/index.less +247 -247
  101. package/src/components/Business/columnSettingTable/index.md +357 -357
  102. package/src/components/Business/columnSettingTable/index.tsx +232 -232
  103. package/src/components/Business/columnSettingTable/sulaSettingTable.tsx +240 -240
  104. package/src/components/Business/columnSettingTable/utils.tsx +68 -68
  105. package/src/components/Functional/AddSelect/index.less +367 -367
  106. package/src/components/Functional/AddSelect/index.md +122 -122
  107. package/src/components/Functional/AddSelect/index.tsx +994 -992
  108. package/src/components/Functional/BillEntry/index.less +371 -371
  109. package/src/components/Functional/BillEntry/index.md +39 -39
  110. package/src/components/Functional/BillEntry/index.tsx +643 -643
  111. package/src/components/Functional/DataImport/index.less +63 -63
  112. package/src/components/Functional/DataImport/index.md +44 -44
  113. package/src/components/Functional/DataImport/index.tsx +689 -689
  114. package/src/components/Functional/DataValidation/index.less +63 -63
  115. package/src/components/Functional/DataValidation/index.md +38 -38
  116. package/src/components/Functional/DataValidation/index.tsx +681 -681
  117. package/src/components/Functional/ExportFunctions/ExportIcon/index.md +37 -37
  118. package/src/components/Functional/ExportFunctions/ExportIcon/index.tsx +59 -59
  119. package/src/components/Functional/QueryMutipleInput/index.less +37 -37
  120. package/src/components/Functional/QueryMutipleInput/index.md +33 -33
  121. package/src/components/Functional/QueryMutipleInput/index.tsx +130 -128
  122. package/src/components/Functional/SearchSelect/index.less +115 -115
  123. package/src/components/Functional/SearchSelect/index.md +141 -141
  124. package/src/components/Functional/SearchSelect/index.tsx +814 -812
  125. package/src/components/Functional/TreeSearchSelect/index.md +47 -47
  126. package/src/components/Functional/TreeSearchSelect/index.tsx +149 -149
  127. package/src/index.ts +31 -31
  128. package/src/styles/bsDefault.less +1906 -1906
  129. package/src/utils/CheckOneUser/index.md +39 -39
  130. package/src/utils/CheckOneUser/index.ts +51 -51
  131. package/src/utils/checkUtils.ts +39 -39
  132. package/src/utils/enumConfig.ts +10 -9
  133. package/src/utils/index.ts +2 -2
  134. package/src/utils/requestUtils.ts +33 -33
  135. package/src/utils/utils.ts +69 -52
  136. package/tsconfig.json +29 -29
  137. package/typings.d.ts +4 -4
@@ -1,643 +1,643 @@
1
- // @ts-nocheck
2
- import { Button, message, Input, InputNumber, Tooltip, Table, Popover, Select } from 'antd';
3
- import React, { useState, useRef, useEffect } from 'react';
4
- import { SearchOutlined, CopyOutlined, CloseCircleOutlined } from '@ant-design/icons';
5
- import { stringify } from 'querystring';
6
- import './index.less';
7
- import axios from 'axios';
8
- import { checkQuantityAccuracy, precisionQuantity } from '@/utils/checkUtils';
9
-
10
- const InputElement = ({
11
- record, text, currentIndex, inputLength, index, setData, data, item, callSelectItem
12
- }: {
13
- record: any, text: string, currentIndex: any, inputLength: any, index: any, setData: any, data: any, item: any, callSelectItem: any
14
- }) => {
15
- const [hoverVisibled, updateHoverVisibled] = useState(false);
16
- const [searchData, updateSearchData] = useState([]);
17
- const tableRef = useRef(null);
18
- const [value, setValue] = useState(text)
19
- const inputRef = useRef(false);
20
-
21
- const onSerchdata = (name: any) => {
22
- axios
23
- .get(`/items/sku/pager/v2?${stringify({ 'skuCodeAndSkuName': name, 'pageSize': 100, 'qp-combination-eq': false, 'qp-approveStatus-eq': 1, 'qp-status-eq': 1 })}`)
24
- .then(({ data, status }: any) => {
25
- if (status === 200) {
26
- if (data.status === '0') {
27
- const resultData = data.data.items.map((item: any, index: any) => ({
28
- ...item,
29
- index
30
- }));
31
- if (resultData.length === 1) {
32
- callSelectItem({ ...resultData[0], needFocus: true })
33
- setValue(resultData[0][item.dataIndex])
34
- } else {
35
- updateHoverVisibled(true)
36
- updateSearchData(resultData)
37
- }
38
- } else {
39
- updateSearchData([])
40
- }
41
- }
42
- })
43
- }
44
-
45
- const onCallback = (itemData: any) => {
46
- updateHoverVisibled(false)
47
- if (itemData) {
48
- callSelectItem({ ...itemData, needFocus: true })
49
- setValue(itemData[item.dataIndex])
50
- } else {
51
- callSelectItem(null)
52
- }
53
- }
54
-
55
- const SearchDataTable = (hoverVisibled: any) => {
56
- const [selectIndex, setSelectIndex] = useState(0);
57
- const inputRef = useRef(null);
58
-
59
- useEffect(() => {
60
- if (searchData.length && hoverVisibled) {
61
- let dom = tableRef?.current?.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[0]
62
- if (dom) {
63
- dom.style.background = '#005CFF30'
64
- }
65
- }
66
- }, [hoverVisibled, tableRef?.current])
67
-
68
- useEffect(() => {
69
- const inter = setInterval(() => {
70
- if (inputRef.current) {
71
- inputRef.current.focus()
72
- }
73
- }, 500)
74
-
75
- return () => {
76
- clearInterval(inter);
77
- }
78
- })
79
-
80
- if (!hoverVisibled) return <></>
81
-
82
- return <div className={'add_select_wrapper_select'} style={{ width: '800px', height: '400px', overflow: 'auto', position: 'relative' }}>
83
- <Input placeholder='请输入skucode或者sku名称' ref={inputRef} style={{ position: 'absolute', zIndex: '-100', height: '22px' }} onKeyDown={(e) => {
84
- let currentIndex = selectIndex
85
- if (e.keyCode === 27) {
86
- e.stopPropagation();
87
- e.preventDefault();
88
- setSelectIndex(0);
89
- onCallback(null)
90
- }
91
- if (e.keyCode === 13) { // enter
92
- onCallback(searchData[currentIndex])
93
- setSelectIndex(0);
94
- }
95
-
96
- if (e.keyCode === 40) { // 向下
97
- let dom = tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex + 1]
98
- if (dom) {
99
- tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex].style.background = ''
100
- setSelectIndex(currentIndex + 1)
101
- dom.style.background = '#005CFF30'
102
- dom.scrollIntoViewIfNeeded(false)
103
- }
104
- } else if (e.keyCode === 38) {
105
- let dom = tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex - 1]
106
- if (dom) {
107
- tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex].style.background = ''
108
- setSelectIndex(currentIndex - 1)
109
- dom.style.background = '#005CFF30'
110
- dom.scrollIntoViewIfNeeded(false)
111
- }
112
- }
113
- }} />
114
- <Table
115
- ref={tableRef}
116
- pagination={false}
117
- // components={
118
- // {
119
- // body: {
120
- // cell: ({index, record, ...props}) => {
121
- // debugger
122
- // return <td {...props} style={selectIndex === record?.index ? {background: '#005CFF30'} : {} } />
123
- // }
124
- // }
125
- // }
126
- // }
127
- onRow={(record, index) => {
128
- return {
129
- onClick: ((record, index, event) => {
130
- let dom = tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[index]
131
- if (dom) {
132
- [...(tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr'))].map(item => {
133
- item.style.background = ''
134
- })
135
- dom.style.background = '#005CFF30'
136
- dom.scrollIntoViewIfNeeded(false)
137
- }
138
- setSelectIndex(index)
139
- }).bind(this, record, index), // 点击行
140
- }
141
- }}
142
- rowClassName={'row-class'}
143
- columns={[{
144
- title: 'SKU编码',
145
- width: 150,
146
- dataIndex: 'skuCode',
147
- },
148
- {
149
- title: 'SKU名称',
150
- width: 200,
151
- ellipsis: {
152
- showTitle: false,
153
- },
154
- render: (text: any) => (
155
- <Tooltip placement="topLeft" title={text}>
156
- {text}
157
- </Tooltip>
158
- ),
159
- dataIndex: 'name',
160
- },
161
- {
162
- title: '国际条码',
163
- width: 100,
164
- ellipsis: {
165
- showTitle: false,
166
- },
167
- dataIndex: 'barCode',
168
- render: (text: any) => (
169
- <Tooltip placement="topLeft" title={text}>
170
- {text}
171
- </Tooltip>
172
- ),
173
- },
174
- {
175
- title: '所属SPU名称',
176
- width: 100,
177
- ellipsis: {
178
- showTitle: false,
179
- },
180
- dataIndex: 'itemName',
181
- render: (text: any) => (
182
- <Tooltip placement="topLeft" title={text}>
183
- {text}
184
- </Tooltip>
185
- ),
186
- },
187
- {
188
- title: '所属SPU编码',
189
- width: 100,
190
- ellipsis: {
191
- showTitle: false,
192
- },
193
- dataIndex: 'itemCode',
194
- render: (text: any) => (
195
- <Tooltip placement="topLeft" title={text}>
196
- {text}
197
- </Tooltip>
198
- ),
199
- },
200
- {
201
- title: '外部编码',
202
- width: 100,
203
- ellipsis: {
204
- showTitle: false,
205
- },
206
- render: (text: any) => (
207
- <Tooltip placement="topLeft" title={text}>
208
- {text}
209
- </Tooltip>
210
- ),
211
- dataIndex: 'externalCode',
212
- }]} dataSource={searchData} />
213
- </div>
214
- }
215
-
216
- let precisionObj={};
217
- const unitAccuracy = record.packingUnitList?.[0]?.unitAccuracy
218
- const isCountUnitAccuracyCheck = item.dataIndex =='count' && unitAccuracy !== undefined
219
- if(isCountUnitAccuracyCheck) {
220
- precisionObj = {
221
- onBlur: (e: any) => {
222
- const { target: { value } } = e;
223
- if(!checkQuantityAccuracy(value,Number(unitAccuracy))) {
224
- record[item.dataIndex] = precisionQuantity(value,Number(unitAccuracy))
225
- const newData = data.map((i: any, innerIndex: number) => {
226
- if(innerIndex == index) {
227
- i[item.dataIndex] = record[item.dataIndex]
228
- }
229
- return i
230
- })
231
- setData(newData)
232
- }
233
- }
234
- // precision: unitAccuracy
235
- }
236
- }
237
-
238
- return (
239
- <Popover placement="bottomLeft" destroyTooltipOnHide={{ keepParent: false }} title="" trigger="" content={SearchDataTable(hoverVisibled)} visible={hoverVisibled} onVisibleChange={(disabled) => { updateHoverVisibled(disabled) }}>
240
- {item.isPrimaryInput ?
241
- <Input
242
- value={value}
243
- ref={inputRef}
244
- placeholder='skucode / sku名称'
245
- keyboard={false}
246
- autoFocus={record.autoFocus}
247
- onChange={(value) => {
248
- record[item.dataIndex] = value.currentTarget.value
249
- setValue(value.currentTarget.value)
250
- // setData(data);
251
- }}
252
- // onFocus={(e)=> {
253
- // let dom1 = e.currentTarget;
254
- // dom1.setSelectionRange(100, 0);
255
- // dom1.select(text);
256
- // }}
257
- onKeyDown={(e) => {
258
- // if (e.keyCode === 13 && e.ctrlKey) {
259
- // handleOk(true)
260
- // document.getElementById("first-query")?.focus()
261
- // }
262
- if (e.keyCode === 8 && e.ctrlKey && index) {
263
- message.success('删除当前行')
264
- e.stopPropagation();
265
- e.preventDefault();
266
- let dom = e.nativeEvent.path[3].children[index]?.getElementsByTagName('input')[currentIndex]
267
- if (dom) {
268
- dom.select();
269
- dom.focus();
270
- dom.scrollIntoViewIfNeeded(false)
271
- }
272
- dom = null
273
- setData(data.filter((item, innerIndex) => innerIndex !== index))
274
- }
275
- if (e.keyCode === 13) { // enter
276
- if (item.isPrimaryInput) {
277
- if (e.currentTarget.value.length < 2) {
278
- message.warning('至少输入两个字符');
279
- } else {
280
- onSerchdata(e.currentTarget.value)
281
- }
282
- }
283
- }
284
- if (e.keyCode === 37 && e.shiftKey) { // 左滑动
285
- e.stopPropagation();
286
- e.preventDefault();
287
- let dom = e.nativeEvent.path[3].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
288
- if (dom) {
289
- dom.select();
290
- dom.focus();
291
- dom.scrollIntoViewIfNeeded(false)
292
- }
293
- dom = null
294
- }
295
- if (e.keyCode === 39 && e.shiftKey) { // 右滑
296
- e.stopPropagation();
297
- e.preventDefault();
298
- let dom = e.nativeEvent.path[3].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
299
- if (dom) {
300
- dom.select();
301
- dom.focus();
302
- dom.scrollIntoViewIfNeeded(false)
303
- }
304
- dom = null
305
- }
306
- if (e.keyCode === 40) { // 向下
307
- debugger
308
- e.stopPropagation();
309
- e.preventDefault();
310
- let dom = e.nativeEvent.path[3].children[index + 2]?.getElementsByTagName('input')[currentIndex]
311
- if (dom) {
312
- dom.select();
313
- dom.focus();
314
- dom.scrollIntoViewIfNeeded(false)
315
- }
316
- dom = null
317
- } else if (e.keyCode === 38) {
318
- e.stopPropagation();
319
- e.preventDefault();
320
- let dom1 = e.nativeEvent.path[3].children[index]?.getElementsByTagName('input')[currentIndex]
321
- if (dom1) {
322
- // dom1.value=""
323
- // dom1.setSelectionRange(100, 0);
324
- dom1.select();
325
- dom1.focus();
326
- dom1.scrollIntoViewIfNeeded(false)
327
- // dom1.value=record['count']
328
- }
329
- dom1 = null
330
- } else if (e.keyCode === 9 && currentIndex === inputLength - 1 && index === data.length - 1) {
331
- setData([...data, {}])
332
- }
333
- }}
334
- />
335
- :
336
- <InputNumber
337
- // onBlur={() => {updateHoverVisibled(false)}}
338
- value={text || ''}
339
- min={0}
340
- keyboard={false}
341
- {...precisionObj}
342
- onChange={(value) => {
343
- record[item.dataIndex] = value
344
- const newData = data.map((i: any, innerIndex: number) => {
345
- if(innerIndex == index) {
346
- i[item.dataIndex] = record[item.dataIndex]
347
- }
348
- return i
349
- })
350
- setData(newData)
351
- }}
352
- onKeyDown={(e) => {
353
- // if (e.keyCode === 13 && e.ctrlKey) {
354
- // handleOk(true)
355
- // document.getElementById("first-query")?.focus()
356
- // }
357
- if (e.keyCode === 8 && e.ctrlKey && index) {
358
- message.success('删除当前行')
359
- e.stopPropagation();
360
- e.preventDefault();
361
- let dom = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
362
- if (dom) {
363
- dom.select();
364
- dom.focus();
365
- dom.scrollIntoViewIfNeeded(false)
366
- }
367
- dom = null
368
- setData(data.filter((item, innerIndex) => innerIndex !== index))
369
- }
370
- if (e.keyCode === 37 && e.shiftKey) { // 左滑动
371
- e.stopPropagation();
372
- e.preventDefault();
373
- let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
374
- if (dom) {
375
- dom.select();
376
- dom.focus();
377
- dom.scrollIntoViewIfNeeded(false)
378
- }
379
- dom = null
380
- }
381
- if (e.keyCode === 39 && e.shiftKey) { // 右滑
382
- e.stopPropagation();
383
- e.preventDefault();
384
- let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
385
- if (dom) {
386
- dom.select();
387
- dom.focus();
388
- dom.scrollIntoViewIfNeeded(false)
389
- }
390
- dom = null
391
- }
392
- if (e.keyCode === 40) { // 向下
393
- e.stopPropagation();
394
- e.preventDefault();
395
- let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
396
- if (dom) {
397
- dom.select();
398
- dom.focus();
399
- dom.scrollIntoViewIfNeeded(false)
400
- }
401
- dom = null
402
- } else if (e.keyCode === 38) {
403
- e.stopPropagation();
404
- e.preventDefault();
405
- let dom1 = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
406
- if (dom1) {
407
- // dom1.value=""
408
- // dom1.setSelectionRange(100, 0);
409
- dom1.select();
410
- dom1.focus();
411
- dom1.scrollIntoViewIfNeeded(false)
412
- // dom1.value=record['count']
413
- }
414
- dom1 = null
415
- } else if (e.keyCode === 9 && currentIndex === inputLength - 1 && index === data.length - 1) {
416
- e.stopPropagation();
417
- e.preventDefault();
418
- } else if (e.keyCode === 13 && currentIndex === inputLength - 1 && index === data.length - 1 && record['skuCode']) {
419
- setData([...data, { autoFocus: true }])
420
- }
421
- }}
422
- />
423
- }
424
-
425
- </Popover>
426
- )
427
- }
428
-
429
- const BillEntry: React.FC = ({ onSaveCallback, validDataUrl="/items/sku/import/check", isBrandAuth=true, isCheckStockNum=true }) => {
430
- const columns = [
431
- {
432
- title: 'SKU编码',
433
- width: 150,
434
- dataIndex: 'skuCode',
435
- isInputItem: true,
436
- isPrimaryInput: true
437
- },
438
- {
439
- title: 'SKU名称',
440
- width: 200,
441
- ellipsis: {
442
- showTitle: false,
443
- },
444
- render: (text: any) => (
445
- <Tooltip placement="topLeft" title={text}>
446
- {text}
447
- </Tooltip>
448
- ),
449
- dataIndex: 'name',
450
- },
451
- {
452
- title: '单位',
453
- dataIndex: 'selectUnitCode',
454
- width: 100,
455
- render: (text: any, record: any) => {
456
- if (record?.packingUnitList?.length) {
457
- const basePackUnit = record?.packingUnitList[0]
458
- record.selectUnitCode = basePackUnit.unitCode
459
- return basePackUnit.name || basePackUnit.unitCode
460
- }
461
-
462
-
463
- return <></>
464
- },
465
- },
466
- {
467
- title: '数量',
468
- width: 100,
469
- isInputItem: true,
470
- dataIndex: 'count',
471
- },
472
- {
473
- title: '所属SPU编码',
474
- width: 100,
475
- ellipsis: {
476
- showTitle: false,
477
- },
478
- dataIndex: 'itemCode',
479
- render: (text: any) => (
480
- <Tooltip placement="topLeft" title={text}>
481
- {text}
482
- </Tooltip>
483
- ),
484
- },
485
- {
486
- title: '规格',
487
- width: 200,
488
- ellipsis: {
489
- showTitle: false,
490
- },
491
- render: (text: any) => (
492
- <Tooltip placement="topLeft" title={text}>
493
- {text}
494
- </Tooltip>
495
- ),
496
- dataIndex: 'propertyNameAndValue',
497
- }
498
- ]
499
- const [isModalVisible, setIsModalVisible] = useState(false);
500
- const [data, setData] = useState([{ hovered: false }]);
501
- const tableRef = useRef(null)
502
-
503
- const [loading, setLoading] = useState(false);
504
-
505
- const callSelectItem = (index, item) => {
506
- if (item) {
507
- let newData = [].concat(data)
508
- newData[index] = { ...data[index], ...item }
509
- setData(newData)
510
- }
511
- let dom = tableRef?.current?.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[index + 1]
512
- if (dom) {
513
- setTimeout(() => {
514
- dom.getElementsByTagName('input')[item ? 1 : 0]?.select()
515
- dom.getElementsByTagName('input')[item ? 1 : 0]?.focus()
516
- }, 200)
517
- }
518
- }
519
-
520
- const deleteRecord = (record) => {
521
- setData(data.filter(item => item.skuCode !== record.skuCode))
522
- }
523
-
524
- let inputIndex = 0;
525
- let selectColumns = [...columns.map(item => {
526
- const inputLength = columns.filter(item => item.isInputItem || item.isSelectItem).length
527
- const currentIndex = inputIndex
528
- if (item.isInputItem) {
529
- inputIndex++;
530
- return {
531
- ...item,
532
- render: (text, record, index) => {
533
- return (
534
- <InputElement setData={setData} callSelectItem={callSelectItem.bind(this, index)} item={item} isPrimaryInput={item.isPrimaryInput} record={record} text={text} data={data} index={index} inputLength={inputLength} currentIndex={currentIndex} />
535
- );
536
- },
537
- }
538
- } else if (item.isSelectItem) {
539
- inputIndex++;
540
- }
541
-
542
- return item
543
- }), {
544
- title: '操作',
545
- width: 50,
546
- render: (text, record, index) => {
547
- if (index !== 0) {
548
- return (
549
- <span style={{ cursor: 'pointer', color: '#005CFF' }} onClick={() => {
550
- deleteRecord(record)
551
- }}>删除</span>
552
- )
553
- }
554
- }
555
- }]
556
-
557
- const isSkuCanEntry = (resultData) => {
558
- // 处理业务参数
559
- let otherParams={}
560
- if(isBrandAuth){
561
- otherParams = { brandAuth: 'ctl-withAuth' }
562
- }
563
- return axios
564
- .post(validDataUrl, {
565
- ...otherParams,
566
- columns: ["skuCode", "quantity"],
567
- data: resultData.map((i:any) => ({ skuCode: i.skuCode, quality: i.count })),
568
- checkStockNum: isCheckStockNum,
569
- })
570
- .then((result) => {
571
- result = result.data;
572
- if (result.status !== '0') {
573
- message.error(result.msg);
574
- return { flag: false }
575
- } else {
576
- let res = result.data || [];
577
- const errorList = res.filter((i: any) => !i.flag);
578
- return { flag: !errorList?.length, errorList }
579
- }
580
- }).catch(() => {
581
- return { flag:false }
582
- })
583
- }
584
-
585
- const handleSubmit = async () => {
586
- // 加校验逻辑
587
- if (!data?.length) {
588
- message.warning('至少录入一条数据');
589
- return;
590
- }
591
- if (!data?.every((d: any) => d.skuCode && d.name)) {
592
- message.warning('请选择商品!');
593
- return;
594
- }
595
- if (!data?.every((d: any) => d.count)) {
596
- message.warning('请填写商品数量!');
597
- return;
598
- }
599
- const canEntryObject = await isSkuCanEntry(data)
600
- if(canEntryObject?.flag === false) {
601
- const messageInfo = canEntryObject?.errorList?.length && canEntryObject?.errorList.map((i: any) => <div>{i.skuCode}校验失败:{i.checkResults}</div>)
602
- messageInfo && message.warning({ content: messageInfo, duration: 6 });
603
- return;
604
- }
605
-
606
- setLoading(true)
607
- onSaveCallback(data).then(res => {
608
- if(true) {
609
- message.success('保存成功')
610
- }
611
- setLoading(false)
612
- }).catch(Error => {
613
- message.error(Error);
614
- setLoading(false)
615
- })
616
- }
617
-
618
- return (
619
- <div className='add_select'>
620
- <div className='add_select_quick_header'>
621
- <div className='add_select_quick_header_title'><div>快速录入</div><Button type="primary" onClick={() => handleSubmit()} loading={loading}>提交</Button></div>
622
- <span><span>*</span> &nbsp;快捷键:【Tab】-跳格切换;【Shift+←、→】-当前行左、右移动;【 ↑、↓】-当前列上、下移动;【ctrl+Delete】-删除当前行;</span>
623
- </div>
624
- <div className={'add_select_wrapper_select add_select_wrapper_select_quick'}>
625
- <Table
626
- size='small'
627
- scroll={{ y: 240 }}
628
- ref={tableRef}
629
- dataSource={data}
630
- columns={selectColumns}
631
- pagination={false}
632
- rowClassName={'row-class'}
633
- rowClassName={(record: object | null | undefined, index: number) =>
634
- index % 2 === 0 ? 'table_base row-class' : 'table_odd row-class'
635
- }
636
- />
637
- </div>
638
-
639
- </div>
640
- );
641
- };
642
-
643
- export default BillEntry;
1
+ // @ts-nocheck
2
+ import { Button, message, Input, InputNumber, Tooltip, Table, Popover, Select } from 'antd';
3
+ import React, { useState, useRef, useEffect } from 'react';
4
+ import { SearchOutlined, CopyOutlined, CloseCircleOutlined } from '@ant-design/icons';
5
+ import { stringify } from 'querystring';
6
+ import './index.less';
7
+ import axios from 'axios';
8
+ import { checkQuantityAccuracy, precisionQuantity } from '@/utils/checkUtils';
9
+
10
+ const InputElement = ({
11
+ record, text, currentIndex, inputLength, index, setData, data, item, callSelectItem
12
+ }: {
13
+ record: any, text: string, currentIndex: any, inputLength: any, index: any, setData: any, data: any, item: any, callSelectItem: any
14
+ }) => {
15
+ const [hoverVisibled, updateHoverVisibled] = useState(false);
16
+ const [searchData, updateSearchData] = useState([]);
17
+ const tableRef = useRef(null);
18
+ const [value, setValue] = useState(text)
19
+ const inputRef = useRef(false);
20
+
21
+ const onSerchdata = (name: any) => {
22
+ axios
23
+ .get(`/items/sku/pager/v2?${stringify({ 'skuCodeAndSkuName': name, 'pageSize': 100, 'qp-combination-eq': false, 'qp-approveStatus-eq': 1, 'qp-status-eq': 1 })}`)
24
+ .then(({ data, status }: any) => {
25
+ if (status === 200) {
26
+ if (data.status === '0') {
27
+ const resultData = data.data.items.map((item: any, index: any) => ({
28
+ ...item,
29
+ index
30
+ }));
31
+ if (resultData.length === 1) {
32
+ callSelectItem({ ...resultData[0], needFocus: true })
33
+ setValue(resultData[0][item.dataIndex])
34
+ } else {
35
+ updateHoverVisibled(true)
36
+ updateSearchData(resultData)
37
+ }
38
+ } else {
39
+ updateSearchData([])
40
+ }
41
+ }
42
+ })
43
+ }
44
+
45
+ const onCallback = (itemData: any) => {
46
+ updateHoverVisibled(false)
47
+ if (itemData) {
48
+ callSelectItem({ ...itemData, needFocus: true })
49
+ setValue(itemData[item.dataIndex])
50
+ } else {
51
+ callSelectItem(null)
52
+ }
53
+ }
54
+
55
+ const SearchDataTable = (hoverVisibled: any) => {
56
+ const [selectIndex, setSelectIndex] = useState(0);
57
+ const inputRef = useRef(null);
58
+
59
+ useEffect(() => {
60
+ if (searchData.length && hoverVisibled) {
61
+ let dom = tableRef?.current?.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[0]
62
+ if (dom) {
63
+ dom.style.background = '#005CFF30'
64
+ }
65
+ }
66
+ }, [hoverVisibled, tableRef?.current])
67
+
68
+ useEffect(() => {
69
+ const inter = setInterval(() => {
70
+ if (inputRef.current) {
71
+ inputRef.current.focus()
72
+ }
73
+ }, 500)
74
+
75
+ return () => {
76
+ clearInterval(inter);
77
+ }
78
+ })
79
+
80
+ if (!hoverVisibled) return <></>
81
+
82
+ return <div className={'add_select_wrapper_select'} style={{ width: '800px', height: '400px', overflow: 'auto', position: 'relative' }}>
83
+ <Input placeholder='请输入skucode或者sku名称' ref={inputRef} style={{ position: 'absolute', zIndex: '-100', height: '22px' }} onKeyDown={(e) => {
84
+ let currentIndex = selectIndex
85
+ if (e.keyCode === 27) {
86
+ e.stopPropagation();
87
+ e.preventDefault();
88
+ setSelectIndex(0);
89
+ onCallback(null)
90
+ }
91
+ if (e.keyCode === 13) { // enter
92
+ onCallback(searchData[currentIndex])
93
+ setSelectIndex(0);
94
+ }
95
+
96
+ if (e.keyCode === 40) { // 向下
97
+ let dom = tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex + 1]
98
+ if (dom) {
99
+ tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex].style.background = ''
100
+ setSelectIndex(currentIndex + 1)
101
+ dom.style.background = '#005CFF30'
102
+ dom.scrollIntoViewIfNeeded(false)
103
+ }
104
+ } else if (e.keyCode === 38) {
105
+ let dom = tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex - 1]
106
+ if (dom) {
107
+ tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[currentIndex].style.background = ''
108
+ setSelectIndex(currentIndex - 1)
109
+ dom.style.background = '#005CFF30'
110
+ dom.scrollIntoViewIfNeeded(false)
111
+ }
112
+ }
113
+ }} />
114
+ <Table
115
+ ref={tableRef}
116
+ pagination={false}
117
+ // components={
118
+ // {
119
+ // body: {
120
+ // cell: ({index, record, ...props}) => {
121
+ // debugger
122
+ // return <td {...props} style={selectIndex === record?.index ? {background: '#005CFF30'} : {} } />
123
+ // }
124
+ // }
125
+ // }
126
+ // }
127
+ onRow={(record, index) => {
128
+ return {
129
+ onClick: ((record, index, event) => {
130
+ let dom = tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[index]
131
+ if (dom) {
132
+ [...(tableRef.current.getElementsByTagName('tbody')[0].getElementsByTagName('tr'))].map(item => {
133
+ item.style.background = ''
134
+ })
135
+ dom.style.background = '#005CFF30'
136
+ dom.scrollIntoViewIfNeeded(false)
137
+ }
138
+ setSelectIndex(index)
139
+ }).bind(this, record, index), // 点击行
140
+ }
141
+ }}
142
+ rowClassName={'row-class'}
143
+ columns={[{
144
+ title: 'SKU编码',
145
+ width: 150,
146
+ dataIndex: 'skuCode',
147
+ },
148
+ {
149
+ title: 'SKU名称',
150
+ width: 200,
151
+ ellipsis: {
152
+ showTitle: false,
153
+ },
154
+ render: (text: any) => (
155
+ <Tooltip placement="topLeft" title={text}>
156
+ {text}
157
+ </Tooltip>
158
+ ),
159
+ dataIndex: 'name',
160
+ },
161
+ {
162
+ title: '国际条码',
163
+ width: 100,
164
+ ellipsis: {
165
+ showTitle: false,
166
+ },
167
+ dataIndex: 'barCode',
168
+ render: (text: any) => (
169
+ <Tooltip placement="topLeft" title={text}>
170
+ {text}
171
+ </Tooltip>
172
+ ),
173
+ },
174
+ {
175
+ title: '所属SPU名称',
176
+ width: 100,
177
+ ellipsis: {
178
+ showTitle: false,
179
+ },
180
+ dataIndex: 'itemName',
181
+ render: (text: any) => (
182
+ <Tooltip placement="topLeft" title={text}>
183
+ {text}
184
+ </Tooltip>
185
+ ),
186
+ },
187
+ {
188
+ title: '所属SPU编码',
189
+ width: 100,
190
+ ellipsis: {
191
+ showTitle: false,
192
+ },
193
+ dataIndex: 'itemCode',
194
+ render: (text: any) => (
195
+ <Tooltip placement="topLeft" title={text}>
196
+ {text}
197
+ </Tooltip>
198
+ ),
199
+ },
200
+ {
201
+ title: '外部编码',
202
+ width: 100,
203
+ ellipsis: {
204
+ showTitle: false,
205
+ },
206
+ render: (text: any) => (
207
+ <Tooltip placement="topLeft" title={text}>
208
+ {text}
209
+ </Tooltip>
210
+ ),
211
+ dataIndex: 'externalCode',
212
+ }]} dataSource={searchData} />
213
+ </div>
214
+ }
215
+
216
+ let precisionObj={};
217
+ const unitAccuracy = record.packingUnitList?.[0]?.unitAccuracy
218
+ const isCountUnitAccuracyCheck = item.dataIndex =='count' && unitAccuracy !== undefined
219
+ if(isCountUnitAccuracyCheck) {
220
+ precisionObj = {
221
+ onBlur: (e: any) => {
222
+ const { target: { value } } = e;
223
+ if(!checkQuantityAccuracy(value,Number(unitAccuracy))) {
224
+ record[item.dataIndex] = precisionQuantity(value,Number(unitAccuracy))
225
+ const newData = data.map((i: any, innerIndex: number) => {
226
+ if(innerIndex == index) {
227
+ i[item.dataIndex] = record[item.dataIndex]
228
+ }
229
+ return i
230
+ })
231
+ setData(newData)
232
+ }
233
+ }
234
+ // precision: unitAccuracy
235
+ }
236
+ }
237
+
238
+ return (
239
+ <Popover placement="bottomLeft" destroyTooltipOnHide={{ keepParent: false }} title="" trigger="" content={SearchDataTable(hoverVisibled)} visible={hoverVisibled} onVisibleChange={(disabled) => { updateHoverVisibled(disabled) }}>
240
+ {item.isPrimaryInput ?
241
+ <Input
242
+ value={value}
243
+ ref={inputRef}
244
+ placeholder='skucode / sku名称'
245
+ keyboard={false}
246
+ autoFocus={record.autoFocus}
247
+ onChange={(value) => {
248
+ record[item.dataIndex] = value.currentTarget.value
249
+ setValue(value.currentTarget.value)
250
+ // setData(data);
251
+ }}
252
+ // onFocus={(e)=> {
253
+ // let dom1 = e.currentTarget;
254
+ // dom1.setSelectionRange(100, 0);
255
+ // dom1.select(text);
256
+ // }}
257
+ onKeyDown={(e) => {
258
+ // if (e.keyCode === 13 && e.ctrlKey) {
259
+ // handleOk(true)
260
+ // document.getElementById("first-query")?.focus()
261
+ // }
262
+ if (e.keyCode === 8 && e.ctrlKey && index) {
263
+ message.success('删除当前行')
264
+ e.stopPropagation();
265
+ e.preventDefault();
266
+ let dom = e.nativeEvent.path[3].children[index]?.getElementsByTagName('input')[currentIndex]
267
+ if (dom) {
268
+ dom.select();
269
+ dom.focus();
270
+ dom.scrollIntoViewIfNeeded(false)
271
+ }
272
+ dom = null
273
+ setData(data.filter((item, innerIndex) => innerIndex !== index))
274
+ }
275
+ if (e.keyCode === 13) { // enter
276
+ if (item.isPrimaryInput) {
277
+ if (e.currentTarget.value.length < 2) {
278
+ message.warning('至少输入两个字符');
279
+ } else {
280
+ onSerchdata(e.currentTarget.value)
281
+ }
282
+ }
283
+ }
284
+ if (e.keyCode === 37 && e.shiftKey) { // 左滑动
285
+ e.stopPropagation();
286
+ e.preventDefault();
287
+ let dom = e.nativeEvent.path[3].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
288
+ if (dom) {
289
+ dom.select();
290
+ dom.focus();
291
+ dom.scrollIntoViewIfNeeded(false)
292
+ }
293
+ dom = null
294
+ }
295
+ if (e.keyCode === 39 && e.shiftKey) { // 右滑
296
+ e.stopPropagation();
297
+ e.preventDefault();
298
+ let dom = e.nativeEvent.path[3].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
299
+ if (dom) {
300
+ dom.select();
301
+ dom.focus();
302
+ dom.scrollIntoViewIfNeeded(false)
303
+ }
304
+ dom = null
305
+ }
306
+ if (e.keyCode === 40) { // 向下
307
+ debugger
308
+ e.stopPropagation();
309
+ e.preventDefault();
310
+ let dom = e.nativeEvent.path[3].children[index + 2]?.getElementsByTagName('input')[currentIndex]
311
+ if (dom) {
312
+ dom.select();
313
+ dom.focus();
314
+ dom.scrollIntoViewIfNeeded(false)
315
+ }
316
+ dom = null
317
+ } else if (e.keyCode === 38) {
318
+ e.stopPropagation();
319
+ e.preventDefault();
320
+ let dom1 = e.nativeEvent.path[3].children[index]?.getElementsByTagName('input')[currentIndex]
321
+ if (dom1) {
322
+ // dom1.value=""
323
+ // dom1.setSelectionRange(100, 0);
324
+ dom1.select();
325
+ dom1.focus();
326
+ dom1.scrollIntoViewIfNeeded(false)
327
+ // dom1.value=record['count']
328
+ }
329
+ dom1 = null
330
+ } else if (e.keyCode === 9 && currentIndex === inputLength - 1 && index === data.length - 1) {
331
+ setData([...data, {}])
332
+ }
333
+ }}
334
+ />
335
+ :
336
+ <InputNumber
337
+ // onBlur={() => {updateHoverVisibled(false)}}
338
+ value={text || ''}
339
+ min={0}
340
+ keyboard={false}
341
+ {...precisionObj}
342
+ onChange={(value) => {
343
+ record[item.dataIndex] = value
344
+ const newData = data.map((i: any, innerIndex: number) => {
345
+ if(innerIndex == index) {
346
+ i[item.dataIndex] = record[item.dataIndex]
347
+ }
348
+ return i
349
+ })
350
+ setData(newData)
351
+ }}
352
+ onKeyDown={(e) => {
353
+ // if (e.keyCode === 13 && e.ctrlKey) {
354
+ // handleOk(true)
355
+ // document.getElementById("first-query")?.focus()
356
+ // }
357
+ if (e.keyCode === 8 && e.ctrlKey && index) {
358
+ message.success('删除当前行')
359
+ e.stopPropagation();
360
+ e.preventDefault();
361
+ let dom = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
362
+ if (dom) {
363
+ dom.select();
364
+ dom.focus();
365
+ dom.scrollIntoViewIfNeeded(false)
366
+ }
367
+ dom = null
368
+ setData(data.filter((item, innerIndex) => innerIndex !== index))
369
+ }
370
+ if (e.keyCode === 37 && e.shiftKey) { // 左滑动
371
+ e.stopPropagation();
372
+ e.preventDefault();
373
+ let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex - 1]
374
+ if (dom) {
375
+ dom.select();
376
+ dom.focus();
377
+ dom.scrollIntoViewIfNeeded(false)
378
+ }
379
+ dom = null
380
+ }
381
+ if (e.keyCode === 39 && e.shiftKey) { // 右滑
382
+ e.stopPropagation();
383
+ e.preventDefault();
384
+ let dom = e.nativeEvent.path[5].children[index + 1]?.getElementsByTagName('input')[currentIndex + 1]
385
+ if (dom) {
386
+ dom.select();
387
+ dom.focus();
388
+ dom.scrollIntoViewIfNeeded(false)
389
+ }
390
+ dom = null
391
+ }
392
+ if (e.keyCode === 40) { // 向下
393
+ e.stopPropagation();
394
+ e.preventDefault();
395
+ let dom = e.nativeEvent.path[5].children[index + 2]?.getElementsByTagName('input')[currentIndex]
396
+ if (dom) {
397
+ dom.select();
398
+ dom.focus();
399
+ dom.scrollIntoViewIfNeeded(false)
400
+ }
401
+ dom = null
402
+ } else if (e.keyCode === 38) {
403
+ e.stopPropagation();
404
+ e.preventDefault();
405
+ let dom1 = e.nativeEvent.path[5].children[index]?.getElementsByTagName('input')[currentIndex]
406
+ if (dom1) {
407
+ // dom1.value=""
408
+ // dom1.setSelectionRange(100, 0);
409
+ dom1.select();
410
+ dom1.focus();
411
+ dom1.scrollIntoViewIfNeeded(false)
412
+ // dom1.value=record['count']
413
+ }
414
+ dom1 = null
415
+ } else if (e.keyCode === 9 && currentIndex === inputLength - 1 && index === data.length - 1) {
416
+ e.stopPropagation();
417
+ e.preventDefault();
418
+ } else if (e.keyCode === 13 && currentIndex === inputLength - 1 && index === data.length - 1 && record['skuCode']) {
419
+ setData([...data, { autoFocus: true }])
420
+ }
421
+ }}
422
+ />
423
+ }
424
+
425
+ </Popover>
426
+ )
427
+ }
428
+
429
+ const BillEntry: React.FC = ({ onSaveCallback, validDataUrl="/items/sku/import/check", isBrandAuth=true, isCheckStockNum=true }) => {
430
+ const columns = [
431
+ {
432
+ title: 'SKU编码',
433
+ width: 150,
434
+ dataIndex: 'skuCode',
435
+ isInputItem: true,
436
+ isPrimaryInput: true
437
+ },
438
+ {
439
+ title: 'SKU名称',
440
+ width: 200,
441
+ ellipsis: {
442
+ showTitle: false,
443
+ },
444
+ render: (text: any) => (
445
+ <Tooltip placement="topLeft" title={text}>
446
+ {text}
447
+ </Tooltip>
448
+ ),
449
+ dataIndex: 'name',
450
+ },
451
+ {
452
+ title: '单位',
453
+ dataIndex: 'selectUnitCode',
454
+ width: 100,
455
+ render: (text: any, record: any) => {
456
+ if (record?.packingUnitList?.length) {
457
+ const basePackUnit = record?.packingUnitList[0]
458
+ record.selectUnitCode = basePackUnit.unitCode
459
+ return basePackUnit.name || basePackUnit.unitCode
460
+ }
461
+
462
+
463
+ return <></>
464
+ },
465
+ },
466
+ {
467
+ title: '数量',
468
+ width: 100,
469
+ isInputItem: true,
470
+ dataIndex: 'count',
471
+ },
472
+ {
473
+ title: '所属SPU编码',
474
+ width: 100,
475
+ ellipsis: {
476
+ showTitle: false,
477
+ },
478
+ dataIndex: 'itemCode',
479
+ render: (text: any) => (
480
+ <Tooltip placement="topLeft" title={text}>
481
+ {text}
482
+ </Tooltip>
483
+ ),
484
+ },
485
+ {
486
+ title: '规格',
487
+ width: 200,
488
+ ellipsis: {
489
+ showTitle: false,
490
+ },
491
+ render: (text: any) => (
492
+ <Tooltip placement="topLeft" title={text}>
493
+ {text}
494
+ </Tooltip>
495
+ ),
496
+ dataIndex: 'propertyNameAndValue',
497
+ }
498
+ ]
499
+ const [isModalVisible, setIsModalVisible] = useState(false);
500
+ const [data, setData] = useState([{ hovered: false }]);
501
+ const tableRef = useRef(null)
502
+
503
+ const [loading, setLoading] = useState(false);
504
+
505
+ const callSelectItem = (index, item) => {
506
+ if (item) {
507
+ let newData = [].concat(data)
508
+ newData[index] = { ...data[index], ...item }
509
+ setData(newData)
510
+ }
511
+ let dom = tableRef?.current?.getElementsByTagName('tbody')[0].getElementsByTagName('tr')[index + 1]
512
+ if (dom) {
513
+ setTimeout(() => {
514
+ dom.getElementsByTagName('input')[item ? 1 : 0]?.select()
515
+ dom.getElementsByTagName('input')[item ? 1 : 0]?.focus()
516
+ }, 200)
517
+ }
518
+ }
519
+
520
+ const deleteRecord = (record) => {
521
+ setData(data.filter(item => item.skuCode !== record.skuCode))
522
+ }
523
+
524
+ let inputIndex = 0;
525
+ let selectColumns = [...columns.map(item => {
526
+ const inputLength = columns.filter(item => item.isInputItem || item.isSelectItem).length
527
+ const currentIndex = inputIndex
528
+ if (item.isInputItem) {
529
+ inputIndex++;
530
+ return {
531
+ ...item,
532
+ render: (text, record, index) => {
533
+ return (
534
+ <InputElement setData={setData} callSelectItem={callSelectItem.bind(this, index)} item={item} isPrimaryInput={item.isPrimaryInput} record={record} text={text} data={data} index={index} inputLength={inputLength} currentIndex={currentIndex} />
535
+ );
536
+ },
537
+ }
538
+ } else if (item.isSelectItem) {
539
+ inputIndex++;
540
+ }
541
+
542
+ return item
543
+ }), {
544
+ title: '操作',
545
+ width: 50,
546
+ render: (text, record, index) => {
547
+ if (index !== 0) {
548
+ return (
549
+ <span style={{ cursor: 'pointer', color: '#005CFF' }} onClick={() => {
550
+ deleteRecord(record)
551
+ }}>删除</span>
552
+ )
553
+ }
554
+ }
555
+ }]
556
+
557
+ const isSkuCanEntry = (resultData) => {
558
+ // 处理业务参数
559
+ let otherParams={}
560
+ if(isBrandAuth){
561
+ otherParams = { brandAuth: 'ctl-withAuth' }
562
+ }
563
+ return axios
564
+ .post(validDataUrl, {
565
+ ...otherParams,
566
+ columns: ["skuCode", "quantity"],
567
+ data: resultData.map((i:any) => ({ skuCode: i.skuCode, quality: i.count })),
568
+ checkStockNum: isCheckStockNum,
569
+ })
570
+ .then((result) => {
571
+ result = result.data;
572
+ if (result.status !== '0') {
573
+ message.error(result.msg);
574
+ return { flag: false }
575
+ } else {
576
+ let res = result.data || [];
577
+ const errorList = res.filter((i: any) => !i.flag);
578
+ return { flag: !errorList?.length, errorList }
579
+ }
580
+ }).catch(() => {
581
+ return { flag:false }
582
+ })
583
+ }
584
+
585
+ const handleSubmit = async () => {
586
+ // 加校验逻辑
587
+ if (!data?.length) {
588
+ message.warning('至少录入一条数据');
589
+ return;
590
+ }
591
+ if (!data?.every((d: any) => d.skuCode && d.name)) {
592
+ message.warning('请选择商品!');
593
+ return;
594
+ }
595
+ if (!data?.every((d: any) => d.count)) {
596
+ message.warning('请填写商品数量!');
597
+ return;
598
+ }
599
+ const canEntryObject = await isSkuCanEntry(data)
600
+ if(canEntryObject?.flag === false) {
601
+ const messageInfo = canEntryObject?.errorList?.length && canEntryObject?.errorList.map((i: any) => <div>{i.skuCode}校验失败:{i.checkResults}</div>)
602
+ messageInfo && message.warning({ content: messageInfo, duration: 6 });
603
+ return;
604
+ }
605
+
606
+ setLoading(true)
607
+ onSaveCallback(data).then(res => {
608
+ if(true) {
609
+ message.success('保存成功')
610
+ }
611
+ setLoading(false)
612
+ }).catch(Error => {
613
+ message.error(Error);
614
+ setLoading(false)
615
+ })
616
+ }
617
+
618
+ return (
619
+ <div className='add_select'>
620
+ <div className='add_select_quick_header'>
621
+ <div className='add_select_quick_header_title'><div>快速录入</div><Button type="primary" onClick={() => handleSubmit()} loading={loading}>提交</Button></div>
622
+ <span><span>*</span> &nbsp;快捷键:【Tab】-跳格切换;【Shift+←、→】-当前行左、右移动;【 ↑、↓】-当前列上、下移动;【ctrl+Delete】-删除当前行;</span>
623
+ </div>
624
+ <div className={'add_select_wrapper_select add_select_wrapper_select_quick'}>
625
+ <Table
626
+ size='small'
627
+ scroll={{ y: 240 }}
628
+ ref={tableRef}
629
+ dataSource={data}
630
+ columns={selectColumns}
631
+ pagination={false}
632
+ rowClassName={'row-class'}
633
+ rowClassName={(record: object | null | undefined, index: number) =>
634
+ index % 2 === 0 ? 'table_base row-class' : 'table_odd row-class'
635
+ }
636
+ />
637
+ </div>
638
+
639
+ </div>
640
+ );
641
+ };
642
+
643
+ export default BillEntry;