<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 dayjs from 'dayjs'
import { CHECK_OBJ_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: 'taskId',
    label: '工作流ID',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataDate',
    label: '数据日期',
    component: 'DatePicker',
    componentProps: {
      
    },
  },
  {
    field: 'orgNo',
    label: '金融许可证号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkObj',
    label: '校验对象',
    component: 'Select',
    componentProps: {
      options:CHECK_OBJ_LIST
    },
  },
  {
    field: 'orgName',
    label: '机构名称',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'ruleVersion',
    label: '规则版本',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ruleNo',
    label: '校验关系代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkProp',
    label: '校验性质',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkTotalNum',
    label: '校验总记录数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkPassNum',
    label: '校验通过记录数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkPassPer',
    label: '通过率',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkResult',
    label: '校验结果值',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkResultVal',
    label: '校验结果值',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkPassResult',
    label: '校验通过情况枚举',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'checkBatch',
    label: '批次',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'createTime',
    label: '创建时间',
    component: 'DatePicker',
    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()
    const { dataDate, createTime } = formData;
    Object.assign(formData, { dataDate: dayjs(dataDate).format('YYYY-MM-DD') })
    Object.assign(formData, { createTime: dayjs(createTime).format('YYYY-MM-DD') })
    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>

