<template>
  <div style="width: 100%;">
    <CtForm ref="formPageRef" :items="items"></CtForm>
  </div>
</template>

<script setup>
defineOptions({name: 'headhunting-form'})
import { reactive, ref } from 'vue'

const formPageRef = ref()
let query = reactive({})

const items = ref({
  options: [
    {
      type: 'text',
      key: 'name',
      value: '',
      default: null,
      label: '姓名 *',
      outlined: true,
      rules: [v => !!v || '请输入姓名']
    },
    {
      type: 'phoneNumber',
      key: 'phone',
      value: '',
      clearable: true,
      label: '联系手机号 *',
      rules: [v => !!v || '请填写联系手机号']
    },
    {
      type: 'text',
      key: 'enterpriseName',
      value: '',
      default: null,
      label: '企业名称 *',
      outlined: true,
      rules: [v => !!v || '请输入企业名称']
    },
  ]
})


const getQuery = async () => {
  const { valid } = await formPageRef.value.formRef.validate()
  if (!valid) return false
  const obj = {}
  items.value.options.forEach(e => {
    obj[e.key] = e.value
  })
  query = Object.assign(query, obj)
  return query
}

defineExpose({
  getQuery
})
</script>