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

export default function OrganizationHasProjects(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();

  return (
    <BetaSchemaForm<ApiTypes.HouseOrder.HouseOrders.UpdateSerialNumber>
      {...MyModalFormProps.props}
      title={`关联银行流水`}
      wrapperCol={{ span: 24 }}
      width="500px"
      trigger={<MyButtons.Edit title={`流水`} size="small" />}
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open && props.item) {
          form.setFieldsValue({
            ...props.item,
            serial_number: props?.item?.accept_serial_number || '',
          });
        }
      }}
      onFinish={async (values: any) =>
        Apis.HouseOrder.HouseOrders.UpdateSerialNumber({
          ...values,
          id: props?.item?.id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'serial_number',
          title: '银行流水号',
          formItemProps: { ...rulesHelper.text },
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
