<script setup lang="tsx">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { PropType, reactive, watch } from 'vue'
import { getCsckSystemList } from '@/api/common'
import { useValidator } from '@/hooks/web/useValidator'
import { STATUS_DICT_LIST } from '../constants';

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',
    hidden: true
  },{
    field: 'orgCode',
    label: '机构编码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataDate',
    label: '数据日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'systemCode',
    label: '系统编码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'systemName',
    label: '系统名称',
    component: 'Select',
        optionApi: async () => {
      const res = await getCsckSystemList(
        
      )
      return res
    },
    componentProps: {
      
    },
  },
  {
    field: 'systemVersion',
    label: '系统版本号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'modelReportId',
    label: '模型/报表ID',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'modelReportName',
    label: '模型/报表名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'status',
    label: '导入状态',
    component: 'Select',
    componentProps: {
      options: STATUS_DICT_LIST
    },
  },
  {
    field: 'reportType',
    label: '报表类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'updateTime',
    label: '更新时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'errorDesc',
    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>

