<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: 'custpptype',
    label: '客户类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'dcdate',
    label: '识别日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'custcardtype',
    label: '证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custcardno',
    label: '证件号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dcorgan',
    label: '开户网点',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'sblx',
    label: '识别类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'dcjl',
    label: '调查结论',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dctj',
    label: '调查途径',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jlsxrq',
    label: '调查结论失效日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dcname',
    label: '调查人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sftrdl',
    label: '是否他人代理',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'syrs',
    label: '收益人数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sfylazxyg',
    label: '是否与离岸中心有关',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sftzfxdj',
    label: '是否调整风险等级',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sftzjgxydmcx',
    label: '是否通过机构信用代码调查',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dcqksm',
    label: '调查情况说明',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute2',
    label: '开户日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  }
])

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>

