Blame view

src/pages/Invoice/waitProcessRecord/components/ManualInvoicingModal.tsx 2.81 KB
1
import { RESPONSE_CODE } from '@/constants/enum';
2
import UploadC from '@/pages/Invoice/waitProcessRecord/components/UploadSingleImg';
3
4
5
6
import {
  postOrderErpOrderStagesUpload,
  postServiceInvoiceDealInvoicingResult,
} from '@/services';
7
8
9
10
11
12
13
import {
  ModalForm,
  ProFormDatePicker,
  ProFormText,
} from '@ant-design/pro-components';
import { Col, Form, Row, message } from 'antd';
import { RcFile } from 'antd/es/upload';
14
import { useEffect } from 'react';
15
16
export default ({ record }) => {
17
18
19
20
  useEffect(() => {
    console.log('invoicing');
  }, []);
  const [form] = Form.useForm();
21
  return (
22
    <ModalForm
23
24
      title="手动开票"
      trigger={<a type="primary">手动开票</a>}
25
      width={600}
26
27
28
29
30
31
32
33
34
      layout={'horizontal'}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => console.log('run'),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
35
36
37
38
39
40
        const res = await postServiceInvoiceDealInvoicingResult({
          data: {
            ...values,
            isSuccess: true,
            invoiceRecordId: record.id,
            manual: true,
41
            invoiceDetailDtoList: record.invoiceDetails,
42
43
44
45
46
47
48
49
          },
        });
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success('开票成功');
          return true;
        } else {
          message.error('开票失败');
        }
50
51
      }}
    >
52
53
54
55
56
57
      <ProFormText
        rules={[{ required: true, message: '此项为必填项' }]}
        width={'md'}
        name="invoiceNumber"
        label="发票号码"
      />
58
      <ProFormDatePicker
59
        rules={[{ required: true, message: '此项为必填项' }]}
60
        fieldProps={{
61
          format: 'YYYY-MM-DD',
62
63
64
65
        }}
        name="invoicingDate"
        label="开票日期"
      />
66
67
68
69
70
71
      <ProFormText
        rules={[{ required: true, message: '发票必须上传' }]}
        hidden
        name="url"
        label="發票地址"
      />
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
      <Row>
        <Col span={4}>上传发票</Col>
        <Col span={20}>
          <UploadC
            onFilesChange={async (newFileList) => {
              if (newFileList.length > 0) {
                const formData = new FormData();
                formData.append('file', newFileList[0].originFileObj as RcFile);
                const res = await postOrderErpOrderStagesUpload({
                  data: formData,
                  headers: {
                    'Content-Type':
                      'multipart/form-data; boundary=----WebKitFormBoundarynl6gT1BKdPWIejNq',
                  },
                });
                const url = res.data;
                form.setFieldValue('url', url);
              } else {
                form.setFieldValue('url', null);
              }
            }}
          ></UploadC>
        </Col>
      </Row>
    </ModalForm>
  );
};