<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: 'warnCode',
    label: '案例编号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'warnDate',
    label: '案例日期',
    component: 'DatePicker',
    componentProps: {
      type: 'daterange'
    },
  },
  {
    field: 'warnType',
    label: '案例类型',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'ruleType',
    label: '规则类型',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'ruleCode',
    label: '案例规则',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'tranRecord',
    label: '交易次数',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tranAmount',
    label: '交易金额',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attrOrgan',
    label: '归属机构',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'custCode',
    label: '客户号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'status',
    label: '案例状态',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'attribute3',
    label: '提出操作人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute4',
    label: '通过操作人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute5',
    label: '操作时间',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'attribute6',
    label: '通过操作时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute7',
    label: '不通过的原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute8',
    label: '操作注解',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute9',
    label: '附件List',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute10',
    label: '校验状态',
    component: 'Select',
    componentProps: {
      
    },
  },
  {
    field: 'organName',
    label: '归属机构',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'custName',
    label: '客户名称',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'orgbody',
    label: '报告机构主体号',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute11',
    label: '审批意见',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute12',
    label: '加入跟踪库说明',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute13',
    label: '可疑交易出发点',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute14',
    label: '其它可疑交易报告处发点',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute15',
    label: '资金交易及客户行为情况',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'attribute16',
    label: '可疑交易特征',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'urgency',
    label: '报告紧急程度',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportdirectionorg',
    label: '报告其他方向',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportdirection',
    label: '报告方向',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'suscrimtypes',
    label: '可疑交易特征(上报)',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'suscrimtypel',
    label: '涉罪类型大项',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'outcause',
    label: '排除原因',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'enduser',
    label: '审核人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'enddate',
    label: '审核日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'repeatuser',
    label: '复核人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'repeatdate',
    label: '复核日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'initialuser',
    label: '补录人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'initialdate',
    label: '补录日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportuser',
    label: '报告人',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'reportdate',
    label: '报告日期',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tranceEnddata',
    label: '加入跟踪库到期时间',
    component: 'Input',
    componentProps: {
      
    },
  },
  {
    field: 'tranceType',
    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>

