import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Apis } from '@/gen/Apis';
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.Refund.Refunds.Complete>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="700px"
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      trigger={
        <MyButtons.Default
          type="primary"
          size="small"
          title="退款登记"
          disabled={!props.item?.has_refunding}
        />
      }
      onFinish={async (values) =>
        Apis.Refund.Refunds.Complete({
          ...values,
          id: props.item?.id ?? '',
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        // Selects?.CompanyAccounts({
        //   key: 'company_receipt_accounts_id',
        //   title: '付款账户',
        //   colProps: { span: 24 },
        //   formItemProps: { ...rulesHelper.number },
        //   fieldProps: {
        //     showSearch: true,
        //   },
        // }),
        {
          key: 'refund_time',
          title: '退款日期',
          valueType: 'date',
          formItemProps: { ...rulesHelper.text },
          colProps: { span: 24 },
        },
        {
          key: 'serial_number',
          title: '退款流水号',
          formItemProps: { ...rulesHelper.text },
          colProps: { span: 24 },
        },

        MyFormItems.UploadImages({
          key: 'voucher',
          title: '上传退款凭证',
          tooltip: '支持上传任意格式的文件',
          uploadType: 'file',
          colProps: { span: 24 },
          // accept: '.docx,.doc,.pdf',
          max: 100,
          required: true,
        }),
      ]}
    />
  );
}
