<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: 'custType',
    label: '客户类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custStatus',
    label: '客户状态',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custOrgancode',
    label: '客户开户机构代码',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'lockStatus',
    label: '审核状态',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custPptype',
    label: '客户公私类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCardtype',
    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: 'corporationName',
    label: '法人代表人姓名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardtye',
    label: '法人代表人证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corporationCardno',
    label: '法人代表人证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskCode',
    label: '风险评级编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskGradecode',
    label: '风险等级编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskScore',
    label: '风险评级分值',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskNate',
    label: '风险评级备注',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute1',
    label: '审核人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute2',
    label: '审核时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute3',
    label: '审核意见',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute4',
    label: '申请时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute5',
    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()
    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>

