FinancialDrawer.tsx 2.75 KB
// import { PlusOutlined } from '@ant-design/icons';
import { RESPONSE_CODE } from '@/constants/enum';
import {
  postServiceOrderEditOrder,
  postServiceOrderInvoicing,
} from '@/services';
import {
  DrawerForm,
  ProFormDatePicker,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';

export default ({ mainOrder, subOrders, isEdit, onClose }) => {
  const subIds = subOrders.map((item) => item.id);
  console.log(subOrders);
  const [form] = Form.useForm<{ name: string; company: string }>();
  return (
    <DrawerForm<{
      name: string;
      company: string;
    }>
      open
      title="财务信息"
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 400,
      }}
      initialValues={mainOrder}
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
      }}
      submitTimeout={2000}
      onFinish={async () => {
        let res;
        let body = {
          invoicingTime: form.getFieldValue('invoicingTime'),
          subIds: subIds,
          collectMoneyTime: form.getFieldValue('collectMoneyTime'),
          invoicingNotes: form.getFieldValue('invoicingNotes'),
        };
        if (isEdit) {
          res = await postServiceOrderEditOrder({ data: body });
        } else {
          res = await postServiceOrderInvoicing({ data: body });
        }
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
        }
      }}
      onOpenChange={(val) => {
        return !val && onClose();
      }}
    >
      <ProFormText
        width="lg"
        name="invoiceIdentificationNumber"
        label="开票信息"
        placeholder="请输入开票信息"
        disabled
      />
      <ProFormText
        width="lg"
        name="bank"
        label="开户银行"
        placeholder="请输入开户银行"
        disabled
      />
      <ProFormText
        width="lg"
        name="bankAccountNumber"
        label="开户银行账号"
        placeholder="请输入开户银行账号"
        disabled
      />
      <ProFormDatePicker
        width="lg"
        name="invoicingTime"
        label="开票时间"
        disabled={isEdit}
        rules={[{ required: !isEdit ? true : false, message: '这是必填项' }]}
        initialValue={subOrders[0].invoicingTime}
      />
      <ProFormDatePicker
        width="lg"
        name="collectMoneyTime"
        label="收款时间"
        initialValue={subOrders[0].collectMoneyTime}
      />

      <ProFormTextArea
        width="lg"
        name="invoicingNotes"
        label="备注"
        initialValue={subOrders[0].invoicingNotes}
      />
    </DrawerForm>
  );
};