<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: 'pkid',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCode',
    label: '客户编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'areaId',
    label: '对方所在地区id',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'country',
    label: '对方所属国家',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'organType',
    label: '对方行号类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'organCode',
    label: '对方行号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'organName',
    label: '对方金融机构网点名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'oppPbcCd',
    label: '对方人行客户类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'acctName',
    label: '交易对手名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'acctNum',
    label: '交易对手账号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'acctType',
    label: '交易对手账户类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ssnType',
    label: '交易对手证件类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ssnNo',
    label: '交易对手证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'acctType',
    label: '对方客户类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'lockStatus',
    label: '锁定状态',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'organAreaId',
    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>

