<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 { LOG_TYPE_LIST,HANDLE_STATUS_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: 'handleStatus',
    label: '处理状态',
    component: 'Select',
    componentProps: {
      options:HANDLE_STATUS_LIST
    },
  },
  {
    field: 'requestTime',
    label: '请求时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reqMessage',
    label: '请求报文',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'respMessage',
    label: '响应报文',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'msg',
    label: '失败原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'timeConsume',
    label: '耗时',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'logType',
    label: '查询类型',
    component: 'Select',
    componentProps: {
      options:LOG_TYPE_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>

