import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import {
  AssetCarPortsPropertyTypeEnum,
  AssetCarPortsStatusEnum,
  AssetCarPortsTypeEnum,
} from '@/gen/Enums';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { Form, message } from 'antd';

export default function SpaceCreate(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.Asset.AssetCarPorts.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      // wrapperCol={{ span: 24 }}
      layout="horizontal"
      labelCol={{ span: 4 }}
      wrapperCol={{ span: 24 }}
      labelAlign="left"
      key={new Date().getTime()}
      width="600px"
      form={form}
      trigger={<MyButtons.Create title={`${props.title}`} />}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
        console.log(props?.item, 'ppppp');
      }}
      onFinish={async (values) =>
        Apis.Asset.AssetCarPorts.Store({
          ...values,
          asset_projects_id: props?.item?.asset_projects_id,
          asset_parking_places_id: props?.item?.asset_parking_places_id,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'name',
          title: '车位号',
          formItemProps: { ...rulesHelper.text },
          colProps: { span: 24 },
        },
        {
          key: 'built_area',
          title: '建筑面积',
          valueType: 'digit',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.number },
          fieldProps: {
            addonAfter: 'm²',
          },
          width: '100%',
        },
        MyFormItems.EnumRadio({
          key: 'type',
          title: '类型',
          valueEnum: AssetCarPortsTypeEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'property_type',
          title: '产权类型',
          valueEnum: AssetCarPortsPropertyTypeEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'status',
          title: '状态',
          valueEnum: AssetCarPortsStatusEnum,
          required: true,
        }),
        {
          key: 'owner_name',
          title: '业主姓名',
          colProps: { span: 24 },
        },
        {
          key: 'owner_phone',
          title: '业主手机号',
          colProps: { span: 24 },
        },
        Selects?.AssetFullName({
          key: 'asset_houses_id',
          params: {
            asset_projects_id: props?.item?.asset_projects_id,
          },
          title: '关联房屋',
          colProps: { span: 24 },
        }),
        {
          key: 'remark',
          title: '备注',
          valueType: 'textarea',
        },
      ]}
    />
  );
}
