import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} 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 PayCreate(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Bill.BillPayments.Store>
      {...MyModalFormProps.props}
      title={`收取装修押金`}
      labelCol={{ span: 4 }}
      wrapperCol={{ span: 20 }}
      width="600px"
      layout="horizontal"
      trigger={<MyButtons.Default title={`收款`} />}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      key={new Date().getTime()}
      form={form}
      onFinish={async (values) =>
        Apis.Bill.BillPayments.Store({
          ...values,
          bills_id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success('收款信息提交成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'total_paid_amount',
          title: '收款金额',
          valueType: 'digit',
          colProps: { span: 24 },
          initialValue: props?.item?.payable_amount,
          fieldProps: {
            style: { width: '100%' },
            addonAfter: '元',
          },
          formItemProps: { ...rulesHelper.number },
        },
        MyFormItems.EnumRadio({
          key: 'payment_method',
          title: '收款方式',
          colProps: { span: 24 },
          valueEnum: () => {
            const obj: Record<string, any> = JSON.parse(
              JSON.stringify(HouseOrdersPaymentMethodEnum),
            );
            delete obj.WeChat;
            delete obj.Alipay;
            delete obj.TongLian;
            delete obj.Prepayment;
            return obj;
          },
          required: true,
        }),

        {
          key: 'paid_time',
          title: '收款日期',
          valueType: 'date',
          formItemProps: { ...rulesHelper.text },
          colProps: { span: 24 },
        },
        {
          key: 'remark',
          title: '收款备注',
          valueType: 'textarea',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.text },
          fieldProps: {
            placeholder: '请详细描述工单内容',
            rows: 4,
          },
        },
        MyFormItems.UploadImages({
          key: 'pay_certificate',
          title: '收款凭证',
          tooltip: '最多上传5张图片',
          // uploadType: 'file',
          max: 5,
          colProps: { span: 24 },
          formItemProps: { required: false },
        }),
      ]}
    />
  );
}
