@bit-sun/business-component 2.4.19 → 2.4.21

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