<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'

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: 'ssnNo',
    label: '证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ssnNotype',
    label: '证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCountry',
    label: '客户国籍',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custTel',
    label: '客户联系电话',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custAddress',
    label: '客户住址',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custContactway',
    label: '客户其他联系方式',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custPptype',
    label: '客户标识',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custBusinesstype',
    label: '对私客户职业或对公客户行也',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custRegcap',
    label: '注册资金',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationName',
    label: '法定代表人姓名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardtye',
    label: '法定代表人身份类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardno',
    label: '法定代表人身份证号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custClipro',
    label: '客户性质',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'openorg',
    label: '开户机构号',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'attribute1',
    label: '其它证件类型名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportfreq',
    label: '客户报送次数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jrdpbna',
    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: 'reportDate',
    label: '上报时间 最后一次上报的时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportFirstname',
    label: '当前客户上报第一次的文件名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'status',
    label: '状态： 0：未补录，1：已补录',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'errStatus',
    label: '0 需要重新补录   1 重新补录ok  2 生成报文 ',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'opuser',
    label: '操作人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'oplasttime',
    label: '操作时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'txflg',
    label: '标志： 2、3 为一次性金融服务',
    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()
    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>

