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