<script setup lang="tsx">
import { Form, FormSchema } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'
import { reactive } from 'vue'
import { useValidator } from '@/hooks/web/useValidator'

const { required,phone } = useValidator()

const { formRegister, formMethods } = useForm()
const { getFormData, getElFormExpose } = formMethods

const formSchema = reactive<FormSchema[]>([
    {
        field: 'dataDate',
        label: '数据日期',
        component: 'DatePicker',
        componentProps: {
            valueFormat:'YYYY-MM-DD'
        },
    },
    {
        field: 'tabGuids',
        label: '报表英文名称',
        component: 'Input',
    },
    
    {
        field: 'applicant',
        label: '申报人名称',
        component: 'Input',
    },
    {
        field: 'applicantTelphone',
        label: '申报人手机号',
        component: 'Input',
        componentProps: {
            
        },
    },
    {
        field: 'corrAdvice',
        label: '重报原因',
        component: 'Input',
        colProps:{
            span:24
        },
        componentProps: {
            type:'textarea',
            
        },
    },
])

const rules = reactive({
    dataDate:[required()],
    tabGuids:[required()],
    corrAdvice:[required()],
    applicant:[required()],
    applicantTelphone:[required(),phone()],
})

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
  }
}

defineExpose({
  submit
})
</script>

<template>
  <Form :rules="rules" @register="formRegister" :schema="formSchema" />
</template>

