<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: 'custType',
    label: '客户类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custOpendate',
    label: '客户开户日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custName',
    label: '客户名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custOrganname',
    label: '归属机构名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'lastRiskdate',
    label: '上次评级日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'lastRiskScore',
    label: '上次评级结果',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'sysRiskdate',
    label: '系统评级日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskScore',
    label: '系统总分',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskInitalscore',
    label: '初评总分',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskInitialdate',
    label: '初评日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskRepeatscore',
    label: '复评总分',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskRepeatdate',
    label: '复评日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskReason',
    label: '评级原因',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'state',
    label: '处理状态',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'shReason',
    label: '审核退回原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'repeatReason',
    label: '复评退回原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'isman',
    label: '是否人工发起',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custOrgancode',
    label: '客户归属机构号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskLevel',
    label: '系统评级结果',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskInitallevel',
    label: '初评结果',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskRepeatlevel',
    label: '复评结果',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskRepeatUser',
    label: '复评用户',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskAuditUser',
    label: '审核用户',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskInitalUser',
    label: '初评用户',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskCauseAuditreason',
    label: '审核原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskCount',
    label: '评级次数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskAuditdate',
    label: '审核时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskAddInitalscore',
    label: '初评附加分',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskAddRepeatscore',
    label: '复评附加分',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskCauseInitalreason',
    label: '初评调整原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'riskCauseRepeatreason',
    label: '复评调整原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'lastRiskReason',
    label: '上次评级理由',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'manRiskReason',
    label: '人工发起评级理由',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'manDate',
    label: '评级日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'lastRiskLevel',
    label: '上次评级结果',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'flag',
    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>

