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

export default function Create(props: MyBetaModalFormProps) {
  return (
    <BetaSchemaForm<ApiTypes.Company.Companies.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="800px"
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      onFinish={async (values) =>
        Apis.Company.Companies.Store(values)
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        SysSelects?.Companies({
          key: 'parent_id',
          title: '上级组织',
          colProps: { span: 24 },
        }),
        {
          key: 'name',
          title: '组织名称',
          colProps: { span: 8 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'short_name',
          title: '组织简称',
          colProps: { span: 8 },
        },
        {
          key: 'business_license_number',
          title: '营业执照号',
          colProps: { span: 8 },
          formItemProps: { ...rulesHelper.text },
        },

        {
          key: 'contact_name',
          title: '联系人姓名',
          colProps: { span: 8 },
          formItemProps: { ...rulesHelper.text },
        },
        {
          key: 'contact_phone',
          title: '联系人手机',
          colProps: { span: 8 },
          valueType: 'number',
          fieldProps: {
            maxLength: 11,
          },
          formItemProps: { ...rulesHelper.number },
        },
        {
          key: 'contact_email',
          title: '联系人邮箱',
          colProps: { span: 8 },
        },
        {
          key: 'contact_address',
          title: '联系人地址',
          colProps: { span: 24 },
        },
        MyFormItems.EnumRadio({
          key: 'merchant_type',
          title: '商户类型',
          colProps: { span: 24 },
          valueEnum: CompaniesMerchantTypeEnum,
          required: true,
        }),
        Address.Cascader({
          key: 'casacader',
          title: '选择地址',
          colProps: { span: 24 },
          keys: ['province', 'city', 'area', 'street'],
          required: true,
        }),
        {
          key: 'address',
          title: '机构地址',
          colProps: { span: 24 },
        },
      ]}
    />
  );
}
