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

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: 'custCode',
    label: '客户号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custName',
    label: '黑名单客户名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCardno',
    label: '客户证件号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'matchingtype',
    label: '匹配类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'matchingscore',
    label: '匹配度',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCode1',
    label: '存量客户号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute5',
    label: '客户账号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custName1',
    label: '存量客户名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'createDate',
    label: '客户号开立时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tranDate',
    label: '交易时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'oppName',
    label: '交易对手名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'oppPapersno',
    label: '交易对手证件号码',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'warnCode',
    label: '生成可疑案例编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'exportDate',
    label: '匹配日期',
    component: 'DatePicker',
    componentProps: {
      
    },
  },
  {
    field: 'blackNum',
    label: '黑名单编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custOrgancode',
    label: '客户归属机构',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'acctOrgancode',
    label: '账号开立机构',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tranOrgancode',
    label: '交易机构',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'plResult',
    label: '匹配结果',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custCardtype',
    label: '证件类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'recordId',
    label: '道琼斯黑名单记录id',
    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 { exportDate } = formData;
    Object.assign(formData, { exportDate: dayjs(exportDate).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>

