InvoicingDrawerForm.tsx 4.56 KB
// import { PlusOutlined } from '@ant-design/icons';
import {
  postServiceConstInvoiceType,
  postServiceConstInvoicingType,
  postServiceInvoiceApplyInvoice,
} from '@/services';
import { enumToSelect } from '@/utils';
import {
  DrawerForm,
  ProFormGroup,
  ProFormList,
  ProFormMoney,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Form } from 'antd';
import { useEffect } from 'react';
import { PAYEE_OPTIONS } from '../constant';

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,
      }}
      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="partyBName"
        label="开票收款单位"
        options={enumToSelect(PAYEE_OPTIONS)}
        placeholder="请选择收款单位"
        rules={[{ required: true, message: '请选择收款单位!' }]}
      />
      <ProFormSelect
        name="isUrgent"
        label="是否加急"
        valueEnum={{
          true: '是',
          false: '否',
        }}
        placeholder="请选择是否加急"
        rules={[{ required: true, message: '请选择是否加急!' }]}
      />
      <ProFormUploadDragger
        key="filePaths"
        label="附件"
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
      <ProFormTextArea
        name="applyInvoicingNotes"
        label="备注"
        placeholder="请输入名称"
      />
    </DrawerForm>
  );
};