<script setup lang="tsx">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'
import dayjs from 'dayjs'

const { required } = useValidator()

const props = defineProps({
  currentRow: {
    type: Object as PropType<any>,
    default: () => null
  },
  actionType: {
    type: String,
    default: 'add'
  }
})

const { formRegister, formMethods } = useForm()
const { setValues, getFormData, getElFormExpose } = formMethods

const formSchema = reactive<FormSchema[]>([
  {
    field: 'pkid',
    label: '序列号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCode',
    label: '客户号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custName',
    label: '客户名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custType',
    label: '客户类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custNation',
    label: '民族',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custStatus',
    label: '客户状态',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custOrgancode',
    label: '客户归属机构',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'lockStatus',
    label: '锁状态',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custPptype',
    label: '客户公私类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custCardtype',
    label: '客户证件类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custCardname',
    label: '客户身份证件名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'isnewcust',
    label: '是否为新增客户',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCardno',
    label: '客户证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custTel',
    label: '客户固定电话',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custPhone',
    label: '客户手机号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custAddress',
    label: '客户住址',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custContactway',
    label: '客户其它联系方式',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCountry',
    label: '客户国籍',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custBusinesstype',
    label: '客户行业类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custRegcap',
    label: '客户注册资金',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'conshName',
    label: '控股股东或实际控制人名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'conshCardtype',
    label: '控股股东或实际控制人名称身份证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'conshCardname',
    label: '控股股东或实际控制人名称身份证件名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'conshCardno',
    label: '控股股东或实际控制人名称身份证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationName',
    label: '法人代表人姓名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardtye',
    label: '法人代表人证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardname',
    label: '法人代表人证件名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardno',
    label: '法人代表人证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'targetOrgancode',
    label: '上级归属机构',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute1',
    label: '客户开户机构法人代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute2',
    label: '注册币种',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'issuing',
    label: '发证机关',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'endDate',
    label: '到期日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'businessScope',
    label: '营业执照上标注的经营范围',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationIssuing',
    label: '法人代表人证件发证机关',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationEndDate',
    label: '法人代表人证件到期日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dgZjlx',
    label: '对公证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'clrq',
    label: '成立日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jyqx',
    label: '营业期限（年）',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regsterCode',
    label: '注册地行政区代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'gsDjh',
    label: '国税登记号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dsDjh',
    label: '地税登记号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jgxydmz',
    label: '机构信用代码证',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jbhXkz',
    label: '基本户开户许可证核准号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jbhKhh',
    label: '基本户开户行',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'qygm',
    label: '企业规模',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jjlx',
    label: '经济类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'proxyName',
    label: '代理人姓名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'proxyCardtye',
    label: '代理人证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'proxyCardno',
    label: '代理人证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'proxyIssuing',
    label: '代理人发证机关',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'proxyEndDate',
    label: '代理人到期日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'isIntegererBank',
    label: '是否开通网银',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'integererBankName',
    label: '网银操作员姓名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'integererBankCardtye',
    label: '网银操作员证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'integererBankCardno',
    label: '网银操作员证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'integererBankIssuing',
    label: '发证机关',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'integererBankEndDate',
    label: '到期日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custListType',
    label: '客户名单类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dgZjhm',
    label: '对公证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'wgzy',
    label: '外国政要',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskLevel',
    label: '风险等级',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute3',
    label: '登记注册地址',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute4',
    label: '法人代表信用等级',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute5',
    label: '开户日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'createDate',
    label: '客户创建日期',
    component: 'DatePicker',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCreateDate',
    label: '法人代表人证件起始日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'personalProfession',
    label: '个人职业',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'integererBankOpendate',
    label: '网银开户时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sex',
    label: '性别',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'isSell',
    label: '售出凭证时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'etlDate',
    label: 'ETL时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sfjhzf',
    label: '是否聚合支付',
    component: 'Input',
    componentProps: {
      
    },
  }
])

const rules = reactive({
  
})

const submit = async () => {
  const elForm = await getElFormExpose()
  const valid = await elForm?.validate().catch((err) => {
    console.log(err)
  })
  if (valid) {
    const formData = await getFormData()
    const { createDate } = formData;
    Object.assign(formData, { createDate: dayjs(createDate).format('YYYY-MM-DD') })
    return formData
  }
}

watch(
  () => props.currentRow,
  (currentRow) => {
    if (!currentRow) return
    setValues(currentRow)
  },
  {
    deep: true,
    immediate: true
  }
)

defineExpose({
  submit
})
</script>

<template>
  <Form :rules="rules" @register="formRegister" :schema="formSchema" />
</template>

