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

export default function Create(props: MyBetaModalFormProps) {
  const [form] = Form.useForm();
  return (
    <BetaSchemaForm<ApiTypes.CompanySupplier.CompanySuppliers.Store>
      {...MyModalFormProps.props}
      title={`添加${props.title}`}
      wrapperCol={{ span: 24 }}
      width="820px"
      style={{
        padding: '20px',
        maxHeight: '680px',
        overflowY: 'auto',
        overflowX: 'hidden',
      }}
      key={new Date().getTime()}
      form={form}
      onOpenChange={(open: any) => {
        if (open) {
          form.resetFields(); // 清空表单数据
        }
      }}
      trigger={<MyButtons.Create title={`添加${props.title}`} />}
      onFinish={async (values) =>
        Apis.CompanySupplier.CompanySuppliers.Store({
          ...values,
          is_general_taxpayer: values.is_general_taxpayer ? 1 : 0,
          counterparty: CompanySuppliersCounterpartyEnum.InternalCompany.value,
          supplier_type: CompanySuppliersSupplierTypeEnum.Enterprise.value,
          certificate_type:
            CompanySuppliersCertificateTypeEnum.BusinessLicense.value,
          company_name: values.name,
        })
          .then(() => {
            props.reload?.();
            message.success(props.title + '成功');
            return true;
          })
          .catch(() => false)
      }
      columns={[
        {
          key: 'name',
          title: '企业名称',
          formItemProps: { ...rulesHelper.text },
          colProps: { span: 12 },
        },
        {
          key: 'tax_number',
          title: '纳税人识别号',
          colProps: { span: 12 },
        },
        {
          valueType: 'group',
          columns: [
            Address.Cascader({
              key: 'casacader',
              title: '选择地址',
              // required: true,
              colProps: { span: 12 },
              keys: ['province', 'city', 'area', 'street'],
            }),
            {
              key: 'address',
              title: '详细地址',
              required: true,
              colProps: { span: 12 },
            },
          ],
        },
        {
          key: 'tax_address',
          title: '开票地址',
          colProps: { span: 12 },
        },
        {
          key: 'tax_phone',
          title: '开票电话',
          colProps: { span: 12 },
        },
        {
          key: 'tax_bank_name',
          title: '开户行',
          colProps: { span: 12 },
        },
        {
          key: 'tax_bank_account',
          title: '银行账号',
          colProps: { span: 6 },
        },
        {
          key: 'is_general_taxpayer',
          title: '是否一般纳税人',
          valueType: 'switch',
          colProps: { span: 6 },
        },
        // {
        //   key: 'legal_person',
        //   title: '法定代表人',
        //   colProps: { span: 6 },
        // },
        // {
        //   valueType: 'divider',
        //   fieldProps: {
        //     orientation: 'left',
        //     children: '收款账号',
        //   },
        // },
        // {
        //   valueType: 'formList',
        //   dataIndex: 'bank_accounts',
        //   fieldProps: {
        //     copyIconProps: false,
        //     // deleteIconProps: false,
        //   },
        //   columns: [
        //     {
        //       valueType: 'group',
        //       colProps: { span: 24 },
        //       columns: [
        //         {
        //           key: 'company_name',
        //           title: '开户名称',
        //           colProps: { span: 8 },
        //         },
        //         {
        //           key: 'tax_bank_name',
        //           title: '开户银行',
        //           colProps: { span: 8 },
        //         },
        //         {
        //           key: 'tax_bank_account',
        //           title: '银行账号',
        //           colProps: { span: 8 },
        //         },
        //       ],
        //     },
        //   ],
        // },
      ]}
    />
  );
}
