ManualInvoiceModal.tsx
3.86 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
import { RESPONSE_CODE } from '@/constants/enum';
import { PAYEE_OPTIONS } from '@/pages/Order/constant';
import { postServiceOrderInvoicing } from '@/services';
import {
ModalForm,
ProFormDatePicker,
ProFormDigit,
ProFormSelect,
ProFormText,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
import { useState } from 'react';
interface ManualInvoiceModalProps {
record: any;
onSuccess?: () => void;
}
const ManualInvoiceModal: React.FC<ManualInvoiceModalProps> = ({
record,
onSuccess,
}) => {
const [form] = Form.useForm();
const [visible, setVisible] = useState(false);
// 转换PAYEE_OPTIONS为Select组件需要的格式
const payeeOptions = Object.entries(PAYEE_OPTIONS).map(([value, label]) => ({
value,
label,
}));
return (
<ModalForm
title="手动开票"
trigger={
<a
key="invoice"
style={{ color: '#1890ff' }}
onClick={() => setVisible(true)}
>
开票
</a>
}
width={600}
layout={'horizontal'}
form={form}
open={visible}
onOpenChange={setVisible}
autoFocusFirstInput
modalProps={{
destroyOnClose: true,
}}
initialValues={{
purchaser: record.partyAName,
payee: record.partyB,
money: record.price,
}}
submitTimeout={2000}
onFinish={async (values) => {
try {
const body = {
invoiceIdentificationNumber: values.purchaser,
invoicingTime: values.invoicingTime,
purchaser: values.purchaser,
financialReceiptIssuanceTime:
values.financialReceiptIssuanceTime || values.invoicingTime,
collectMoneyTime: values.collectMoneyTime || values.invoicingTime,
invoiceNumber: values.invoiceNumber,
payee: values.payee,
money: values.money,
afterInvoicingStatus: [record.type],
mainOrderIds: record.mainOrderIds,
invoiceRecordIds: [record.id],
};
// 根据现有组件实现,使用data来传递参数
const res = await postServiceOrderInvoicing({
data: body,
});
if (res.result === RESPONSE_CODE.SUCCESS) {
message.success('开票成功');
if (onSuccess) {
onSuccess();
}
return true;
} else {
message.error('开票失败');
return false;
}
} catch (error) {
message.error('操作失败');
return false;
}
}}
>
<ProFormText
width="md"
name="purchaser"
label="抬头名称"
rules={[{ required: true, message: '请输入抬头名称' }]}
disabled
/>
<ProFormText
width="md"
name="invoiceType"
label="发票类型"
initialValue="普票"
disabled
/>
<ProFormDigit
width="md"
name="money"
label="发票金额"
fieldProps={{
precision: 2,
prefix: '¥',
}}
rules={[{ required: true, message: '请输入发票金额' }]}
disabled
/>
<ProFormSelect
width="md"
name="payee"
label="收款单位"
options={payeeOptions}
rules={[{ required: true, message: '请选择收款单位' }]}
disabled
/>
<ProFormText
width="md"
name="invoiceNumber"
label="发票号码"
rules={[{ required: true, message: '请输入发票号码' }]}
/>
<ProFormDatePicker
width="md"
name="invoicingTime"
label="开票时间"
rules={[{ required: true, message: '请选择开票时间' }]}
fieldProps={{
format: 'YYYY-MM-DD',
}}
/>
</ModalForm>
);
};
export default ManualInvoiceModal;