<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 {JOB_SCHEDULE_STATUS} 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: 'pId',
    label: '系统',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sId',
    label: '任务ID',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'jId',
    label: '作业ID',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sName',
    label: '任务名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sType',
    label: '任务类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sSystem',
    label: '系统',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sCron',
    label: 'cron表达式',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sStatus',
    label: '状态',
    component: 'Select',
    componentProps: {
      options:JOB_SCHEDULE_STATUS
    },
  },
  {
    field: 'createUser',
    label: '创建人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'createTime',
    label: '创建时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'updateTime',
    label: '更新时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'createOrgan',
    label: '创建机构',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataDate',
    label: '业务日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'sDescription',
    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>

