Commit 1d87cfcc9e78ab67c42ba91f400e5ae8f939e87a
1 parent
6b0d7fb3
feat: update 发票对账
Showing
2 changed files
with
94 additions
and
109 deletions
src/pages/Invoice/components/BankChooseModal.tsx
... | ... | @@ -7,28 +7,36 @@ import { |
7 | 7 | } from '@/services'; |
8 | 8 | import { enumValueToLabel, formatDateTime } from '@/utils'; |
9 | 9 | import { formatDate } from '@/utils/time'; |
10 | -import { | |
11 | - ActionType, | |
12 | - ProCard, | |
13 | - ProFormInstance, | |
14 | - ProTable, | |
15 | -} from '@ant-design/pro-components'; | |
10 | + | |
11 | +import { ActionType, ProCard, ProTable } from '@ant-design/pro-components'; | |
16 | 12 | import { Button, Divider, Flex, Modal, Tag, message } from 'antd'; |
17 | -import { useEffect, useRef, useState } from 'react'; | |
13 | +import { useRef, useState } from 'react'; | |
18 | 14 | import { BANK_STATEMENT_COLUMNS, INVOICE_STATUS } from '../constant'; |
19 | 15 | import '../index.less'; |
20 | 16 | export default ({ invoiceId, setVisible, onClose }) => { |
21 | 17 | const [bankData, setBankData] = useState([]); |
22 | - const [page, setPage] = useState(1); | |
23 | - const [pageSize, setPageSize] = useState(10); | |
24 | - const [total, setTotal] = useState(0); | |
25 | 18 | const [selectedStatement, setSelectedStatement] = useState([]); |
26 | - const [loading, setLoading] = useState(false); | |
19 | + const [selectedStatementIdSet, setSelectedStatementIdSet] = useState( | |
20 | + new Set(), | |
21 | + ); | |
22 | + | |
23 | + // 添加元素到Set | |
24 | + const addElement = (element) => { | |
25 | + setSelectedStatementIdSet((prevSet) => new Set([...prevSet, element])); | |
26 | + }; | |
27 | + | |
28 | + // 从Set中删除元素 | |
29 | + const removeElement = (element) => { | |
30 | + setSelectedStatementIdSet((prevSet) => { | |
31 | + const newSet = new Set(prevSet); | |
32 | + newSet.delete(element); | |
33 | + return newSet; | |
34 | + }); | |
35 | + }; | |
36 | + | |
27 | 37 | const [btnLoading, setBtnLoading] = useState(false); |
28 | 38 | |
29 | 39 | const actionRef = useRef<ActionType>(); |
30 | - const formRef = useRef<ProFormInstance>(); | |
31 | - | |
32 | 40 | const getTableCellText = (target: any) => { |
33 | 41 | if (!target) { |
34 | 42 | return ''; |
... | ... | @@ -41,21 +49,6 @@ export default ({ invoiceId, setVisible, onClose }) => { |
41 | 49 | return target; |
42 | 50 | }; |
43 | 51 | |
44 | - const loadBankData = async (params: any) => { | |
45 | - setLoading(true); | |
46 | - let searchParams = formRef?.current?.getFieldFormatValue(); | |
47 | - console.log(searchParams); | |
48 | - const res = await postServiceBankStatementQueryBankStatement({ | |
49 | - data: { ...searchParams, ...params, status: 'ABNORMAL' }, | |
50 | - }); | |
51 | - if (res) { | |
52 | - setBankData(res?.data?.data || []); | |
53 | - setTotal(res?.data?.total || 0); | |
54 | - } | |
55 | - | |
56 | - setLoading(false); | |
57 | - }; | |
58 | - | |
59 | 52 | /** |
60 | 53 | * 加载银行流水列表表格的各个列格式 |
61 | 54 | */ |
... | ... | @@ -65,6 +58,10 @@ export default ({ invoiceId, setVisible, onClose }) => { |
65 | 58 | let dataIndex = item.dataIndex; |
66 | 59 | let dataType = item.valueType; |
67 | 60 | |
61 | + if (item.dataIndex === 'status') { | |
62 | + newItem.hideInSearch = true; | |
63 | + } | |
64 | + | |
68 | 65 | newItem.render = (text, record) => { |
69 | 66 | let textValue = record[dataIndex]; |
70 | 67 | |
... | ... | @@ -93,7 +90,6 @@ export default ({ invoiceId, setVisible, onClose }) => { |
93 | 90 | |
94 | 91 | case 'status': { |
95 | 92 | //这里状态不显示在筛选条件中,只能筛异常的流水 |
96 | - newItem.hideInSearch = true; | |
97 | 93 | return ( |
98 | 94 | <EllipsisDiv |
99 | 95 | text={enumValueToLabel( |
... | ... | @@ -133,19 +129,24 @@ export default ({ invoiceId, setVisible, onClose }) => { |
133 | 129 | key="choose" |
134 | 130 | type="link" |
135 | 131 | onClick={() => { |
136 | - //去掉表格中对应的数据 | |
137 | - let newBankData = bankData.filter((item) => { | |
138 | - return item.id !== record.id; | |
139 | - }); | |
140 | - setBankData(newBankData); | |
141 | - | |
142 | - //添加到已选中区域中 | |
143 | - let newSelectedStatement = [...selectedStatement]; | |
144 | - newSelectedStatement.push(record); | |
145 | - setSelectedStatement(newSelectedStatement); | |
132 | + //已经选中,取消选中 | |
133 | + if (selectedStatementIdSet.has(record.id)) { | |
134 | + setSelectedStatement( | |
135 | + selectedStatement.filter((item) => { | |
136 | + return item.id !== record.id; | |
137 | + }), | |
138 | + ); | |
139 | + removeElement(record.id); | |
140 | + } else { | |
141 | + //添加到已选中区域中 | |
142 | + let newSelectedStatement = [...selectedStatement]; | |
143 | + newSelectedStatement.push(record); | |
144 | + setSelectedStatement(newSelectedStatement); | |
145 | + addElement(record.id); | |
146 | + } | |
146 | 147 | }} |
147 | 148 | > |
148 | - 选中 | |
149 | + {selectedStatementIdSet.has(record.id) ? '取消选中' : '选中'} | |
149 | 150 | </Button>, |
150 | 151 | ], |
151 | 152 | }); |
... | ... | @@ -153,68 +154,6 @@ export default ({ invoiceId, setVisible, onClose }) => { |
153 | 154 | return columns; |
154 | 155 | }; |
155 | 156 | |
156 | - /** | |
157 | - * 银行流水表 | |
158 | - * @param param0 | |
159 | - * @returns | |
160 | - */ | |
161 | - const BankTable = ({ actionRef = undefined }) => { | |
162 | - return ( | |
163 | - <ProTable | |
164 | - loading={loading} | |
165 | - columns={bankStatementColumnsInit()} | |
166 | - actionRef={actionRef} | |
167 | - formRef={formRef} | |
168 | - cardBordered | |
169 | - pagination={{ | |
170 | - pageSize: pageSize, | |
171 | - current: page, | |
172 | - total: total, | |
173 | - onChange: (page, pageSize) => { | |
174 | - setPage(page); | |
175 | - setPageSize(pageSize); | |
176 | - loadBankData({ current: page, pageSize: pageSize }); | |
177 | - }, | |
178 | - }} | |
179 | - dataSource={bankData} | |
180 | - columnsState={{ | |
181 | - persistenceKey: 'pro-table-singe-demos', | |
182 | - persistenceType: 'localStorage', | |
183 | - defaultValue: { | |
184 | - option: { fixed: 'right', disable: true }, | |
185 | - }, | |
186 | - onChange(value) { | |
187 | - console.log('value: ', value); | |
188 | - }, | |
189 | - }} | |
190 | - search={{ | |
191 | - labelWidth: 'auto', | |
192 | - span: 8, | |
193 | - }} | |
194 | - options={{ | |
195 | - setting: { | |
196 | - listsHeight: 400, | |
197 | - }, | |
198 | - reload: () => { | |
199 | - loadBankData({ current: 1 }); | |
200 | - }, | |
201 | - }} | |
202 | - form={{}} | |
203 | - onSubmit={() => { | |
204 | - loadBankData({ current: 1 }); | |
205 | - }} | |
206 | - onReset={() => { | |
207 | - formRef.current?.resetFields(); | |
208 | - loadBankData({ current: 1 }); | |
209 | - }} | |
210 | - dateFormatter="string" | |
211 | - headerTitle="银行流水" | |
212 | - scroll={{ x: 1400, y: 360 }} | |
213 | - toolBarRender={() => []} | |
214 | - /> | |
215 | - ); | |
216 | - }; | |
217 | - | |
218 | 157 | const removeSelectedStatement = (record: any) => { |
219 | 158 | console.log(record); |
220 | 159 | console.log(selectedStatement); |
... | ... | @@ -258,11 +197,6 @@ export default ({ invoiceId, setVisible, onClose }) => { |
258 | 197 | return tags; |
259 | 198 | }; |
260 | 199 | |
261 | - useEffect(() => { | |
262 | - message.info('1'); | |
263 | - loadBankData({ current: page, pageSize: pageSize }); | |
264 | - }, []); | |
265 | - | |
266 | 200 | return ( |
267 | 201 | <> |
268 | 202 | <Modal |
... | ... | @@ -305,7 +239,59 @@ export default ({ invoiceId, setVisible, onClose }) => { |
305 | 239 | </Flex> |
306 | 240 | </ProCard> |
307 | 241 | |
308 | - <BankTable actionRef={actionRef}></BankTable> | |
242 | + <ProTable | |
243 | + columns={bankStatementColumnsInit()} | |
244 | + actionRef={actionRef} | |
245 | + cardBordered | |
246 | + pagination={{ | |
247 | + pageSize: 10, | |
248 | + }} | |
249 | + editable={{ | |
250 | + type: 'multiple', | |
251 | + onSave: async (rowKey, data) => { | |
252 | + console.log(rowKey, data); | |
253 | + }, | |
254 | + actionRender: (row, config, defaultDom) => [ | |
255 | + defaultDom.save, | |
256 | + defaultDom.cancel, | |
257 | + ], | |
258 | + }} | |
259 | + request={async (params) => { | |
260 | + const res = await postServiceBankStatementQueryBankStatement({ | |
261 | + data: { ...params }, | |
262 | + }); | |
263 | + if (res) { | |
264 | + return { | |
265 | + data: res?.data?.data || [], | |
266 | + total: res?.data?.total || 0, | |
267 | + }; | |
268 | + } | |
269 | + }} | |
270 | + columnsState={{ | |
271 | + persistenceKey: 'pro-table-singe-demos', | |
272 | + persistenceType: 'localStorage', | |
273 | + defaultValue: { | |
274 | + option: { fixed: 'right', disable: true }, | |
275 | + }, | |
276 | + onChange(value) { | |
277 | + console.log('value: ', value); | |
278 | + }, | |
279 | + }} | |
280 | + rowKey="id" | |
281 | + search={{ | |
282 | + labelWidth: 'auto', | |
283 | + }} | |
284 | + options={{ | |
285 | + setting: { | |
286 | + listsHeight: 400, | |
287 | + }, | |
288 | + }} | |
289 | + form={{}} | |
290 | + dateFormatter="string" | |
291 | + headerTitle="银行流水列表" | |
292 | + scroll={{ x: 1400, y: 360 }} | |
293 | + toolBarRender={() => []} | |
294 | + /> | |
309 | 295 | </Modal> |
310 | 296 | </> |
311 | 297 | ); | ... | ... |