<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 { REPORT_STATUS_LIST,APPLE_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: 'orgNo',
    label: '机构金融许可证号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'subOrgNo',
    label: '子机构编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regulationId',
    label: '制度表编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regulationName',
    label: '制度名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'regulationVersion',
    label: '制度版本',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'orgApplicantNo',
    label: '整改编码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'dataDate',
    label: '数据日期',
    component: 'DatePicker',
    componentProps: {
      
    },
  },
  {
    field: 'workflowId',
    label: '任务编码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'rectifyType',
    label: '整改类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corrEndDate',
    label: '整改截止日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabName',
    label: '表中文',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabNameEn',
    label: '表英文',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tabGuid',
    label: '表唯一编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'metricsCode',
    label: '退回指标数量',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportStatus',
    label: '报送状态',
    component: 'Select',
    componentProps: {
      options:REPORT_STATUS_LIST
    },
  },
  {
    field: 'applyStatus',
    label: '申请状态',
    component: 'Select',
    componentProps: {
      options:APPLE_STATUS_LIST
    },
  },
  {
    field: 'centerPullStatus',
    label: '中心拉取通知状态',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'centerPullTime',
    label: '拉取时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'filePath',
    label: '整改要求文件存放全路径',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'corrAdvice',
    label: '整改说明',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'applicantTelphone',
    label: '申请人联系方式',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'applicant',
    label: '申请人名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'applyTime',
    label: '申请时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'backTime',
    label: '监管退回或审批时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'restateReportTime',
    label: '重报时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'createTime',
    label: '生成时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'collectingCode',
    label: '采集编码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'metricsName',
    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()
    const { dataDate } = formData;
    Object.assign(formData, { dataDate: dayjs(dataDate).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>

