import {
  MyBetaModalFormProps,
  MyButtons,
  MyFormItems,
  MyModalFormProps,
  rulesHelper,
} from '@/common';
import { Address } from '@/components/Address';
import { SysSelects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import {
  AssetProjectsChargeEnum,
  AssetProjectsEntrustTypeEnum,
  AssetProjectsPropertyTypeEnum,
  AssetProjectsStatusEnum,
} from '@/gen/Enums';
import { BetaSchemaForm } from '@ant-design/pro-components';
import { message } from 'antd';

export default function Create(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Asset.AssetProjects.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="800px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      onFinish={async (values) =>
        Apis.Asset.AssetProjects.Store(values)
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        SysSelects?.Companies({
          key: 'companies_id',
          title: '所属机构',
          colProps: { span: 24 },
          formItemProps: { ...rulesHelper.number },
        }),
        {
          key: 'name',
          title: '项目名称',
          colProps: { span: 8 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'alias_name',
          title: '项目别名',
          colProps: { span: 8 },
        },
        {
          key: 'code',
          title: '项目编码',
          colProps: { span: 8 },
          formItemProps: { ...rulesHelper.text },
        },
        MyFormItems.EnumRadio({
          key: 'property_type',
          title: '物业类型',
          colProps: { span: 24 },
          valueEnum: AssetProjectsPropertyTypeEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'status',
          title: '状态',
          colProps: { span: 12 },
          valueEnum: AssetProjectsStatusEnum,
          required: true,
        }),
        MyFormItems.EnumRadio({
          key: 'charge',
          title: '收费方式',
          colProps: { span: 12 },
          valueEnum: AssetProjectsChargeEnum,
          required: true,
        }),

        MyFormItems.EnumRadio({
          key: 'entrust_type',
          title: '委托类型',
          colProps: { span: 24 },
          valueEnum: AssetProjectsEntrustTypeEnum,
          required: true,
        }),

        Address.Cascader({
          key: 'casacader',
          title: '选择地址',
          colProps: { span: 24 },
          keys: ['province', 'city', 'area', 'street'],
          required: true,
        }),
        {
          key: 'address',
          title: '详细地址',
          colProps: { span: 24 },
        },
        {
          key: 'longitude',
          title: '经度',
          colProps: { span: 6 },
        },
        {
          key: 'latitude',
          title: '纬度',
          colProps: { span: 6 },
        },
        {
          key: 'takeover_date',
          title: '接管日期',
          valueType: 'date',
          fieldProps: {
            style: {
              width: '100%',
            },
          },
          colProps: { span: 6 },
        },
        {
          key: 'closure_date',
          title: '封园日期',
          valueType: 'date',
          fieldProps: {
            style: {
              width: '100%',
            },
          },
          colProps: { span: 6 },
        },
      ]}
    />
  );
}
