Blame view

src/pages/Invoice/InvoiceRecord/components/InvoiceRecordDetailModal.tsx 14.6 KB
曾国涛 authored
1
import { RESPONSE_CODE } from '@/constants/enum';
2
import InvoiceDetailTable from '@/pages/Invoice/InvoiceRecord/components/InvoiceDetailTable';
曾国涛 authored
3
4
5
6
7
8
9
10
11
12
import {
  postServiceConstGetPayeeEnum,
  postServiceConstInvoiceType,
  postServiceConstInvoicingType,
  postServiceInvoiceGetInvoiceRecord,
  postServiceInvoiceModifyRecord,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
  ModalForm,
13
  ProCard,
曾国涛 authored
14
15
  ProForm,
  ProFormInstance,
16
  ProFormList,
曾国涛 authored
17
18
19
20
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
曾国涛 authored
21
import { Button, Divider, Form, Space, message } from 'antd';
曾国涛 authored
22
23
import { useEffect, useRef, useState } from 'react';
24
export default ({ id, setVisible, reloadTable }) => {
曾国涛 authored
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  const [readOnly, setReadOnly] = useState(true);
  const [detailTableData, setDetailTableData] = useState([]);
  const [payees, setPayees] = useState([]);
  const [payeeNameOptions, setPayeeNameOptions] = useState([]);
  const formRef = useRef<ProFormInstance>();
  const [form] = Form.useForm();

  useEffect(() => {
    const getPayees = async () => {
      let res = await postServiceConstGetPayeeEnum();
      setPayees(res.data);
      let payeeNameOptions = res.data.map((item) => {
        return {
          label: item.payeeName,
          value: item.payeeName,
        };
      });
      setPayeeNameOptions(payeeNameOptions);
    };
    getPayees();
  }, []);
曾国涛 authored
46
47
48
49
50
51
  const getRecord = async (id) => {
    let ret = await postServiceInvoiceGetInvoiceRecord({
      query: {
        id: id,
      },
    });
52
    console.log(ret.data);
曾国涛 authored
53
54
55
56
57
58
59
60
    const updatedInvoiceDetails = ret.data.invoiceDetails?.map(
      (item, index) => ({
        ...item, // 保留原有属性
        tid: index + 1, // 添加tid属性,这里以T开头,后面跟索引+1,仅作示例,实际可根据需求生成tid
      }),
    );
    setDetailTableData(updatedInvoiceDetails);
  };
曾国涛 authored
61
  useEffect(() => {
曾国涛 authored
62
63
    getRecord(id);
  }, []);
曾国涛 authored
64
65
66
67
68
69
70

  const updateDetails = (values) => {
    setDetailTableData(values);
  };
  return (
    <>
      <Space>
曾国涛 authored
71
72
        <ModalForm
          open
曾国涛 authored
73
          title="发票详情"
曾国涛 authored
74
75
76
77
78
          formRef={formRef}
          request={async () => {
            let ret = await postServiceInvoiceGetInvoiceRecord({
              query: {
                id: id,
曾国涛 authored
79
              },
曾国涛 authored
80
            });
81
82
83
            const data = ret.data;
            const orderIdMap = data.orderIdMap;
            const orderIdList = [];
84
85
86
87
88
89
90
91
92

            // 使用Object.entries()遍历属性
            Object.entries(orderIdMap).forEach(([key, value]) => {
              const orderId = {
                mainId: key,
                subIds: value,
              };
              orderIdList.push(orderId);
            });
93
94
95
96
            return {
              ...data,
              orderIdList: orderIdList,
            };
曾国涛 authored
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
          }}
          submitter={{
            render: () => {
              return [
                <Button
                  type={readOnly ? 'primary' : 'default'}
                  key="ok"
                  onClick={() => {
                    setReadOnly(!readOnly);
                  }}
                >
                  {readOnly ? '编辑' : '取消编辑'}
                </Button>,
                <>
                  {!readOnly && (
                    <Button
                      type="primary"
                      key="submit"
                      onClick={async () => {
                        const result = await postServiceInvoiceModifyRecord({
                          data: {
                            ...form.getFieldsValue(),
                            invoiceDetails: [...detailTableData],
                          },
                        });
                        if (result.result === RESPONSE_CODE.SUCCESS) {
                          message.success('提交成功');
                        }
                        setVisible(false);
126
                        reloadTable();
曾国涛 authored
127
128
129
130
131
132
133
134
                        return true;
                      }}
                    >
                      提交
                    </Button>
                  )}
                </>,
                /*<Button
135
136
137
138
139
140
141
142
                                                                                                        type={'default'}
                                                                                                        key="ok"
                                                                                                        onClick={() => {
                                                                                                            setVisible(false)
                                                                                                        }}
                                                                                                    >
                                                                                                        取消
                                                                                                    </Button>,*/
曾国涛 authored
143
144
145
146
147
148
149
150
151
              ];
            },
          }}
          width={1200}
          form={form}
          autoFocusFirstInput
          modalProps={{
            destroyOnClose: true,
            onCancel: () => {
曾国涛 authored
152
              setVisible(false);
曾国涛 authored
153
154
            },
          }}
155
156
157
158
159
          grid={true}
          layout="horizontal"
          rowProps={{
            gutter: [0, 0],
          }}
曾国涛 authored
160
161
162
163
164
165
166
167
168
169
170
          submitTimeout={2000}
          onFinish={async (values) => {
            const result = await postServiceInvoiceModifyRecord({
              data: {
                ...values,
                invoiceDetails: {
                  ...detailTableData,
                },
              },
            });
            if (result.result === RESPONSE_CODE.SUCCESS) {
171
              reloadTable();
曾国涛 authored
172
173
174
175
176
              message.success('提交成功');
            }
            return true;
          }}
        >
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
          <ProCard
            title="基础信息"
            bordered
            //
            headStyle={{}}
            headerBordered
            size={'small'}
          >
            <ProForm.Group>
              <ProFormText
                readonly
                name="id"
                label="订单批号"
                colProps={{
                  span: 5,
                }}
                tooltip="最长为 24 位"
                placeholder="请输入名称"
              />

              <ProFormText
                readonly
                width="md"
                colProps={{
                  span: 5,
                }}
                name="createByName"
                label="销售代表"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                colProps={{
                  span: 5,
                }}
                name="createTime"
                label="申请时间"
                placeholder="请输入名称"
              />
              <ProFormSelect
                name="type"
                label="发票类型"
                colProps={{
                  span: 5,
                }}
                readonly={readOnly}
                request={async () => {
                  let invoiceTypeRet = await postServiceConstInvoiceType();
                  return enumToSelect(invoiceTypeRet.data);
                }}
                placeholder="Please select a country"
                rules={[
                  { required: true, message: 'Please select your country!' },
                ]}
              />
              <ProFormSelect
                name="invoicingType"
                readonly={readOnly}
                label="开具类型"
                colProps={{
                  span: 4,
                }}
                request={async () => {
                  let invoicingTypeRet = await postServiceConstInvoicingType();
                  let options = enumToSelect(invoicingTypeRet.data);
                  return options;
                }}
                placeholder="Please select a country"
                rules={[
                  { required: true, message: 'Please select your country!' },
                ]}
              />
250
              <ProFormList
251
                label="订单号"
252
253
254
255
256
                name="orderIdList"
                creatorButtonProps={false}
                itemRender={({}, { record }) => {
                  console.log('record' + JSON.stringify(record));
                  return (
257
                    <Space size={[8, 16]} wrap>
258
259
260
261
262
                      <Button
                        key={record.mainId}
                        className="pl-1 pr-0"
                        type="link"
                        target="_blank"
263
                        href={'/order/order?id=' + record.mainId}
264
265
266
267
268
269
270
271
272
273
274
                      >
                        {record.mainId}
                      </Button>
                      (
                      {record.subIds.map((item) => {
                        return (
                          <Button
                            key={item}
                            className="pl-1 pr-0"
                            type="link"
                            target="_blank"
275
                            href={'/order/order?subOrderId=' + item}
276
277
278
279
280
281
282
283
284
285
                          >
                            {item}
                          </Button>
                        );
                      })}
                      )
                      <Divider type="vertical" />
                    </Space>
                  );
                }}
286
              >
287
288
                <ProFormText allowClear={false} width="xs" name={['name']} />
              </ProFormList>
289
290
            </ProForm.Group>
          </ProCard>
曾国涛 authored
291
          <hr />
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
          <ProCard title="购方信息" bordered headerBordered size={'small'}>
            <ProForm.Group>
              <ProFormText
                readonly={readOnly}
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyAName"
                label="购方名称"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyATaxid"
                label="购方税号"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                colProps={{
                  span: 8,
                }}
                label="开户银行"
                name={'partyAOpenBank'}
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyABankAccount"
                label="银行账号"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyAAddress"
                label="购方地址"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly={readOnly}
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyAPhoneNumber"
                label="电话"
                placeholder="请输入名称"
              />
            </ProForm.Group>
          </ProCard>
          <hr />
          <ProCard title="销方信息" bordered headerBordered size={'small'}>
            <ProForm.Group>
              <ProFormSelect
                readonly={readOnly}
                width="md"
                name="partyBName"
                options={payeeNameOptions}
                onChange={(value: any) => {
                  let payee = payees.find((item: any) => {
                    return item.payeeName === value;
                  });
                  console.log(JSON.stringify(payee));
                  form.setFieldsValue({
                    partyBTaxid: payee.taxId,
                    partyBBankAccount: payee.bankAccount,
                    partyBOpenBank: payee.openBank,
                    partyBAddress: payee.address,
                    partyBPhoneNumber: payee.phoneNumber,
                  });
                }}
                label="销方名称"
                colProps={{
                  span: 8,
                }}
                placeholder="请输入名称"
              />
曾国涛 authored
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
              <ProFormText
                readonly
                width="md"
                name="partyBTaxid"
                label="销方税号"
                colProps={{
                  span: 8,
                }}
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="partyBOpenBank"
                label="开户银行"
                colProps={{
                  span: 8,
                }}
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                name="partyBBankAccount"
                label="银行账号"
                colProps={{
                  span: 8,
                }}
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyBAddress"
                label="销方地址"
                placeholder="请输入名称"
              />
              <ProFormText
                readonly
                width="md"
                colProps={{
                  span: 8,
                }}
                name="partyBPhoneNumber"
                label="电话"
                placeholder="请输入名称"
              />
            </ProForm.Group>
          </ProCard>
曾国涛 authored
436
          <hr />
437
438
439
440
441
442
          <ProCard title="发票明细" bordered headerBordered size={'small'}>
            <InvoiceDetailTable
              recordId={id}
              details={detailTableData}
              updateDetails={updateDetails}
              readOnly={readOnly}
曾国涛 authored
443
            />
444
          </ProCard>
曾国涛 authored
445
          <hr />
446
447
          <ProCard title="备注" bordered headerBordered size={'small'}>
            <ProFormTextArea
曾国涛 authored
448
              readonly={readOnly}
449
450
              name="comment"
              placeholder="请输入备注"
曾国涛 authored
451
            />
452
          </ProCard>
曾国涛 authored
453
        </ModalForm>
曾国涛 authored
454
455
456
457
      </Space>
    </>
  );
};