InvoicingDrawerForm.tsx
9.38 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
// import { PlusOutlined } from '@ant-design/icons';
import InvoiceModal from '@/pages/Invoice/components/InvoiceModal';
import {
postServiceConstGetPayeeEnum,
postServiceConstInvoiceType,
postServiceConstInvoicingType,
postServiceConstListInvoiceDetailNames,
postServiceInvoiceApplyInvoice,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
DrawerForm,
ProCard,
ProFormDigit,
ProFormGroup,
ProFormList,
ProFormMoney,
ProFormSelect,
ProFormText,
ProFormTextArea,
} from '@ant-design/pro-components';
import { Button, Form } from 'antd';
import { useEffect } from 'react';
export default ({ dataList, mainOrder, setVisible, onClose }) => {
// let subOrderIds = dataList?.map((item) => {
// return item.id;
// });
const [form] = Form.useForm();
useEffect(() => {}, []);
return (
<DrawerForm
open
title="合并开票"
resize={{
onResize() {
console.log('resize!');
},
maxWidth: window.innerWidth * 0.8,
minWidth: 400,
}}
form={form}
autoFocusFirstInput
drawerProps={{
destroyOnClose: true,
}}
submitter={{
render: (props, defaultDoms) => {
return [
<InvoiceModal
key={'invoicePreview'}
button={<Button type="primary"> 发票预览 </Button>}
getRecord={form.getFieldsValue}
/>,
...defaultDoms,
];
},
}}
submitTimeout={2000}
onFinish={async (values) => {
postServiceInvoiceApplyInvoice({
data: {
...values,
subOrderIds: dataList.map((item) => {
return item.id;
}),
},
});
onClose();
}}
onOpenChange={(val) => {
return !val && setVisible();
}}
>
<ProFormList
name="subOrderIdObjs"
readonly={true}
label="开票订单"
initialValue={dataList.map((item) => {
return {
value: item.id,
};
})}
deleteIconProps={false}
>
<ProFormGroup key="group">
<ProFormText readonly={true} name="value" label="" />
</ProFormGroup>
</ProFormList>
<ProFormText
rules={[
{
required: true,
},
]}
width="md"
name="partyAName"
label="购方名称"
initialValue={mainOrder.institution}
placeholder="请输入名称"
/>
<ProFormText
rules={[
{
required: true,
},
]}
width="md"
name="partyATaxid"
label="购方税号"
placeholder="请输入名称"
/>
<ProFormText
width="md"
name="partyAOpenBank"
label="开户银行"
placeholder="请输入名称"
/>
<ProFormText
width="md"
name="partyABankAccount"
label="开户行账号"
placeholder="请输入名称"
/>
<ProFormMoney
label="开票金额"
name="price"
locale="zh-CN"
rules={[{ required: true, message: '请填写开票金额!' }]}
initialValue={dataList.reduce((accumulator, currentValue) => {
return accumulator + currentValue.subOrderPayment;
}, 0)}
/>
<ProFormSelect
name="invoicingType"
label="开具类型"
request={async () => {
let invoicingTypeRet = await postServiceConstInvoicingType();
let options = enumToSelect(invoicingTypeRet.data);
return options;
}}
placeholder="请选择开具类型"
rules={[{ required: true, message: '请选择开具类型!' }]}
/>
<ProFormSelect
name="type"
label="开票类型"
placeholder="请选择开票类型"
rules={[{ required: true, message: '请选择开票类型!' }]}
request={async () => {
let invoiceTypeRet = await postServiceConstInvoiceType();
let options = enumToSelect(invoiceTypeRet.data);
return options;
}}
/>
<ProFormSelect
name="partyB"
label="开票收款单位"
request={async () => {
const res = await postServiceConstGetPayeeEnum();
let options = res?.data?.map((payee: any) => {
return {
...payee,
label: payee.payeeName,
value: payee.name,
};
});
return options;
}}
onChange={(_, option) => {
if (option) {
form.setFieldsValue({
partyBName: option.payeeName,
partyBTaxid: option.taxId,
});
}
}}
placeholder="请选择收款单位"
rules={[{ required: true, message: '请选择收款单位!' }]}
/>
<ProFormText
name="partyBName"
label="开票收款单位名称"
hidden
rules={[{ required: true, message: '请选择收款单位!' }]}
/>
<ProFormText
name="partyBTaxid"
label="开票收款单位税号"
hidden
rules={[{ required: true, message: '请选择收款单位!' }]}
/>
<ProFormSelect
name="isUrgent"
label="是否加急"
valueEnum={{
true: '是',
false: '否',
}}
placeholder="请选择是否加急"
rules={[{ required: true, message: '请选择是否加急!' }]}
/>
<ProFormList
name="invoiceDetails"
label="开票明细"
initialValue={dataList.map((item) => {
return {
projectName: item.productName,
specification: item.parameters,
unit: item.unit,
quantity: item.quantity,
price: item.productPrice,
totalPrice: item.totalPayment,
};
})}
rules={[
{
required: true,
validator: async (_, value) => {
console.log(value);
if (value && value.length > 0) {
return;
}
throw new Error('至少要有一项!');
},
},
]}
itemRender={(doms, listMeta) => {
console.log(listMeta);
return (
<ProCard
bordered
extra={doms.action}
title={'明细' + (listMeta.index + 1)}
style={{
marginBlockEnd: 8,
}}
>
<ProFormSelect
key={'projectName' + listMeta.index}
width="md"
showSearch
name="projectName"
request={async (value) => {
const keywords = value.keyWords;
const res = await postServiceConstListInvoiceDetailNames({
data: {
nameLike: keywords,
},
});
let options = res?.data?.map((c: any) => {
return {
...c,
label: c.name,
value:
'*' +
c.productAndServiceCatagoryAbbreviation +
'*' +
c?.name,
key: c.id,
};
});
return options;
}}
fieldProps={{
filterOption() {
return true;
},
}}
onChange={(_, option) => {
let index = listMeta.index;
let copyList = form.getFieldValue('invoiceDetails');
let currentData = copyList[index];
currentData.projectName =
'*' +
option.productAndServiceCatagoryAbbreviation +
'*' +
option.name;
currentData.specification = option.specification;
currentData.unit = option.unit;
form.setFieldValue('invoiceDetails', copyList);
}}
debounceTime={1000}
label="项目名称"
placeholder="请输入名称"
/>
<ProFormText
key={'specification' + listMeta.index}
name="specification"
label="规格型号"
placeholder="请输入名称"
/>
<ProFormText
key={'unit' + listMeta.index}
name="unit"
label="单位"
placeholder="请输入名称"
/>
<ProFormDigit
key={'quantity' + listMeta.index}
label="数量"
name="quantity"
min={0}
/>
<ProFormDigit
key={'price' + listMeta.index}
label="单价"
name="price"
min={0}
/>
<ProFormMoney
key={'totalPrice' + listMeta.index}
label="金额"
name="totalPrice"
locale="zh-CN"
/>
</ProCard>
);
}}
></ProFormList>
<ProFormTextArea
name="applyInvoicingNotes"
label="备注"
placeholder="请输入名称"
/>
</DrawerForm>
);
};