@bit-sun/business-component 2.0.37 → 2.0.39-alpha.0

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