ManualInvoicingModal.tsx 2.73 KB
import UploadC from '@/pages/Invoice/components/UploadSingleImg';
import { postOrderErpOrderStagesUpload } from '@/services';
import {
  ModalForm,
  ProCard,
  ProFormDatePicker,
  ProFormList,
  ProFormText,
} from '@ant-design/pro-components';
import { Col, Form, Row, message } from 'antd';
import { RcFile } from 'antd/es/upload';

export default ({ record }) => {
  const [form] = Form.useForm<{ name: string; company: string }>();
  return (
    <ModalForm<{
      name: string;
      company: string;
    }>
      title="手动开票"
      trigger={<a type="primary">手动开票</a>}
      width={400}
      layout={'horizontal'}
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => console.log('run'),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        console.log(values);
        message.success('提交成功');
        return true;
      }}
    >
      <ProFormText width={'md'} name="invoicingPerson" label="开票人" />
      <ProFormText width={'md'} name="invoiceNumber" label="发票号码" />
      <ProFormDatePicker
        fieldProps={{
          format: 'YY-MM-DD',
        }}
        name="invoicingDate"
        label="开票日期"
      />
      <ProFormText hidden name="url" label="發票地址" />
      <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>
      <ProFormList
        name="invoiceDetails"
        label="明细"
        creatorButtonProps={false}
        copyIconProps={false}
        itemRender={({ listDom, action }, { index }) => (
          <ProCard
            bordered
            style={{ marginBlockEnd: 8 }}
            title={`明细${index + 1}`}
            extra={action}
            bodyStyle={{ paddingBlockEnd: 0 }}
          >
            {listDom}
          </ProCard>
        )}
        creatorRecord={{ name: '', items: [{ name: '' }] }}
        initialValue={record.invoiceDetails}
      ></ProFormList>
    </ModalForm>
  );
};