@bit-sun/business-component 3.1.5 → 3.1.6

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