<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',
    hidden: true
  },{
    field: 'bankco',
    label: '金融机构网点代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'bankna',
    label: '金融机构网点名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'bantyp',
    label: '行别代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'bankType',
    label: '联行类别',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'area',
    label: '地区代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'status',
    label: '联行状态',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'cnapsc',
    label: '清算行行号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'rmbnkc',
    label: '所属人行代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'addres',
    label: '联系地址',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tel',
    label: '联系电话',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'email',
    label: '电子邮件',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'post',
    label: '邮编',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'updtun',
    label: '更新序号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'updtat',
    label: '更新日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'upoper',
    label: '最近更新操作',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'nodenu',
    label: '节点代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'usedat',
    label: '有效日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'inused',
    label: '失效日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'districts',
    label: '金融机构网点行政区划代码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'lockStatus',
    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>

