InvoiceVerificationModal.tsx
9.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import ButtonConfirm from '@/components/ButtomConfirm';
import EllipsisDiv from '@/components/Div/EllipsisDiv';
import { RESPONSE_CODE } from '@/constants/enum';
import { INVOCING_STATUS, PAYEE_OPTIONS } from '@/pages/Order/constant';
import {
postServiceInvoiceCancelInvoiceAndBankStatement,
postServiceInvoiceQueryInvoiceDetail,
} from '@/services';
import { enumValueToLabel, formatDateTime } from '@/utils';
import { formatDate } from '@/utils/time';
import { PlusOutlined } from '@ant-design/icons';
import {
ActionType,
ModalForm,
ProCard,
ProTable,
} from '@ant-design/pro-components';
import {
Button,
Descriptions,
DescriptionsProps,
Divider,
Flex,
Form,
message,
} from 'antd';
import { useEffect, useRef, useState } from 'react';
import { BANK_STATEMENT_COLUMNS, INVOICE_STATUS } from '../constant';
import '../index.less';
import BankChooseModal from './BankChooseModal';
export default ({ invoiceId, setVisible, onClose }) => {
const [form] = Form.useForm<{ id: string }>();
const [bankChooseModalVisible, setBankChooseModalVisible] = useState(false);
const [invoiceInfo, setInvoiceInfo] = useState({});
const [relationOrderIds, setRelationOrderIds] = useState([]);
const [relationBankStatements, setRelationBankStatements] = useState([]);
const actionRef = useRef<ActionType>();
const loadInvoiceData = async () => {
let res = await postServiceInvoiceQueryInvoiceDetail({
data: { invoiceId: invoiceId },
});
if (res && res.data) {
setInvoiceInfo(res.data);
setRelationOrderIds(res.data.mainOrderIds);
console.log('bs:' + res.data.bankStatementDtos);
setRelationBankStatements(res.data.bankStatementDtos);
}
};
const showRelationOrders = () => {
return relationOrderIds?.map((item) => {
return (
<>
<Button
className="pl-1 pr-0"
type="link"
target="_blank"
href={'/order?id=' + item}
>
{item}
</Button>
<Divider type="vertical" />
</>
);
});
};
const items: DescriptionsProps['items'] = [
{
key: '1',
label: '发票号码',
children: invoiceInfo?.invoiceNumber,
span: 6,
},
{
key: '2',
label: '发票类型',
children: enumValueToLabel(invoiceInfo?.invoiceStatus, INVOCING_STATUS),
span: 6,
},
{
key: '3',
label: '状态',
children: enumValueToLabel(invoiceInfo?.status, INVOICE_STATUS),
span: 4,
},
{
key: '4',
label: '购买方',
children: invoiceInfo?.purchaser,
span: 8,
},
{
key: '5',
label: '收款单位',
children: enumValueToLabel(invoiceInfo?.payee, PAYEE_OPTIONS),
span: 12,
},
{
key: '6',
label: '联系人',
children: invoiceInfo?.contacts,
span: 4,
},
{
key: '7',
label: '销售',
children: invoiceInfo?.sale,
span: 8,
},
{
key: '9',
label: '开票日期',
children: formatDate(invoiceInfo?.invoicingTime),
span: 12,
},
{
key: '10',
label: '收款时间',
children: formatDate(invoiceInfo?.collectionTime),
span: 4,
},
{
key: '8',
label: '金额',
children: invoiceInfo?.money,
span: 10,
},
{
key: '11',
label: '备注',
children: invoiceInfo?.notes,
span: 24,
},
];
const getTableCellText = (target: any) => {
if (!target) {
return '';
}
if (target.props) {
return target.props.text;
}
return target;
};
/**
* 加载表格的各个列格式
*/
const bankStatementColumnsInit = () => {
let columns = BANK_STATEMENT_COLUMNS.map((item) => {
let newItem = { ...item };
let dataIndex = item.dataIndex;
let dataType = item.valueType;
newItem.render = (text, record) => {
let textValue = record[dataIndex];
if (dataType === 'date') {
textValue = formatDate(textValue);
}
if (dataType === 'dateTime') {
textValue = formatDateTime(textValue);
}
if (dataType === 'money') {
textValue = '¥' + textValue;
}
switch (dataIndex) {
case 'invoiceStatus':
return (
<EllipsisDiv
text={enumValueToLabel(
getTableCellText(textValue),
INVOCING_STATUS,
)}
/>
);
case 'status':
return (
<EllipsisDiv
text={enumValueToLabel(
getTableCellText(textValue),
INVOICE_STATUS,
)}
/>
);
case 'payee':
return (
<EllipsisDiv
text={enumValueToLabel(
getTableCellText(textValue),
PAYEE_OPTIONS,
)}
/>
);
default:
return <EllipsisDiv text={getTableCellText(textValue)} />;
}
};
return newItem;
});
columns.push({
title: '操作',
valueType: 'option',
key: 'option',
fixed: 'right',
width: 70,
render: (text, record) => {
let optBtns = [];
if (invoiceInfo?.status === 'VERIFIED') {
return [];
}
optBtns.push(
<ButtonConfirm
key="delete"
className="p-0"
title={'确认删除此项吗?'}
text="删除"
onConfirm={async () => {
let res = await postServiceInvoiceCancelInvoiceAndBankStatement({
data: {
invoiceId: invoiceId,
cancelId: [record.id],
},
});
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success(res.message);
loadInvoiceData();
}
}}
/>,
);
return optBtns;
},
});
return columns;
};
useEffect(() => {
loadInvoiceData();
}, []);
return (
<>
<ModalForm<{
id: string;
}>
className="invoice-detail"
open
width="80%"
title="发票详情"
form={form}
autoFocusFirstInput
modalProps={{
okText: '确定',
cancelText: '返回',
destroyOnClose: true,
onCancel: () => {
setVisible(false);
onClose();
},
}}
submitter={{
render: (props, defaultDoms) => {
return [defaultDoms[0]];
},
}}
onFinish={async () => {
onClose();
}}
onOpenChange={setVisible}
>
<Divider orientation="left" plain>
发票信息
</Divider>
<Descriptions
bordered
column={24}
size="small"
title=""
items={items}
/>
<Divider orientation="left" plain>
订单号
</Divider>
<ProCard bordered style={{}}>
<Flex>
<div>{showRelationOrders()}</div>
</Flex>
</ProCard>
<Divider plain></Divider>
<ProTable
columns={bankStatementColumnsInit()}
actionRef={actionRef}
cardBordered
pagination={{
pageSize: 10,
}}
dataSource={relationBankStatements}
columnsState={{
persistenceKey: 'pro-table-singe-demos',
persistenceType: 'localStorage',
defaultValue: {
option: { fixed: 'right', disable: true },
},
onChange(value) {
console.log('value: ', value);
},
}}
rowKey="id"
search={false}
options={{
setting: {
listsHeight: 400,
},
reload: false,
}}
form={{
// 由于配置了 transform,提交的参与与定义的不同这里需要转化一下
syncToUrl: (values, type) => {
if (type === 'get') {
return {
...values,
created_at: [values.startTime, values.endTime],
};
}
return values;
},
}}
dateFormatter="string"
headerTitle="银行流水"
scroll={{ x: 1400, y: 360 }}
toolBarRender={() => [
<Button
key="button"
icon={<PlusOutlined />}
onClick={() => {
setBankChooseModalVisible(true);
}}
hidden={invoiceInfo?.status === 'VERIFIED'}
type="primary"
>
添加
</Button>,
]}
/>
</ModalForm>
{bankChooseModalVisible ? (
<BankChooseModal
loadInvoiceData={loadInvoiceData}
setVisible={setBankChooseModalVisible}
invoiceId={invoiceId}
onClose={() => {
setBankChooseModalVisible(false);
loadInvoiceData();
actionRef.current?.reload();
}}
></BankChooseModal>
) : (
''
)}
</>
);
};