import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { HouseOrdersPaymentMethodEnum } from '@/gen/Enums';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';

export default function Create(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Bill.BillPayments.Store>
      {...MyModalFormProps.props}
      title="支付流水"
      wrapperCol={{ span: 24 }}
      width="650px"
      trigger={
        <MyButtons.Edit
          title={props?.title}
          disabled={props?.item?.status !== 'PendingPayment'}
          size="small"
        />
      }
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      onFinish={async (values) =>
        Apis.Bill.BillPayments.Store({
          ...values,
          bills_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success('提交成功，等待审核！');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        MyFormItems.EnumRadio({
          key: 'payment_method',
          title: '支付方式',
          colProps: { span: 24 },
          valueEnum: HouseOrdersPaymentMethodEnum,
          required: true,
        }),
        {
          title: '支付时间',
          key: 'paid_time',
          valueType: 'dateTime',
        },
        {
          title: '收款账户',
          key: 'accept_account_name',
          colProps: { span: 8 },
        },
        {
          title: '收款账号',
          key: 'accept_account_number',
          colProps: { span: 8 },
        },
        {
          title: '收款流水号',
          key: 'accept_serial_number',
          colProps: { span: 8 },
        },
        MyFormItems.UploadImages({
          key: 'pay_certificate',
          title: '支付凭证',
          max: 10,
        }),
        {
          title: '备注',
          key: 'remark',
          valueType: 'textarea',
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
