<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'
import {TAB_LEVEL_LIST,TAB_TYPE_LIST,TAB_STATUS_LIST,IS_REPORT_FILE_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: 'id',
    label: '主键ID',
    component: 'Input',
    hidden: true
  },{
    field: 'collectingCode',
    label: '采集编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regulationId',
    label: '制度编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regulationName',
    label: '制度名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regulationVersion',
    label: '制度版本',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabGuid',
    label: '表编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabName',
    label: '表中文名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabNameEn',
    label: '表英文名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabBelonging',
    label: '一级分类',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabLevel',
    label: '二级分类',
    component: 'Select',
    componentProps: {
      options:TAB_LEVEL_LIST
    },
  },
  {
    field: 'tabType',
    label: '三级分类',
    component: 'Select',
    componentProps: {
      options:TAB_TYPE_LIST
    },
  },
  {
    field: 'tabSchema',
    label: '数据库schema',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'databaseName',
    label: '数据库名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'databaseType',
    label: '数据库类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'databaseVer',
    label: '数据库版本',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'safetyLevel',
    label: '数据安全等级',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'preTableList',
    label: '数据来源表GUID列表',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'department',
    label: '该表所属管理部门',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'physicsStrategy',
    label: '物理化策略',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataLifeCycle',
    label: '数据生命周期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataType',
    label: '数据表分类',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataTypeNo',
    label: '数据表分类编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'remark',
    label: '备注',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabStatus',
    label: '启用状态',
    component: 'Select',
    componentProps: {
      options:TAB_STATUS_LIST
    },
  },
  {
    field: 'businessType',
    label: '业务类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'isReportFile',
    label: '是否上报文件',
    component: 'Select',
    componentProps: {
      options:IS_REPORT_FILE_LIST
    },
  }
])

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>

