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

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: 'pkid',
    label: '主键',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ricd',
    label: '报告机构编码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tmlm',
    label: '更正、补充完成时限',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'rqds',
    label: '更正、补充填报要求',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ornm',
    label: '原可疑交易报告报文名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'rqnm',
    label: '待更正大额可疑交易总数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tsno',
    label: '可疑交易在原可疑交易报告中的序号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'stdt',
    label: '待更正可疑交易发生日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'item',
    label: '待更正字段',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ocnm',
    label: '原客户号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'otdt',
    label: '原大额交易发生日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'otcd',
    label: '原大额交易特征代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'otic',
    label: '原业务标示号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'bgdt',
    label: '补充开始日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'eddt',
    label: '补充结束日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'citp',
    label: '证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ctid',
    label: '证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ctac',
    label: '客户账户',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'filename',
    label: '人工补正补充文件名',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ruletype',
    label: 'BH ,BS',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'createdate',
    label: '文件解析时间',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'itemvalue1',
    label: '流水号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'itemvalue2',
    label: '备用2',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'itemvalue3',
    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>

