<template>
  <view class="pa-3">
    <uni-forms ref="baseForm" v-model="baseFormData" validateTrigger="bind" :rules="rules" label-width="100px" label-align="right">
      <uni-forms-item label="姓名" required  >
        <uni-easyinput v-model="baseFormData.name" placeholder="请输入姓名" />
      </uni-forms-item>
      <uni-forms-item label="联系手机号" required >
        <uni-easyinput v-model="baseFormData.phone" placeholder="请输入联系手机号" />
      </uni-forms-item>
      <uni-forms-item label="企业名称" required>
        <uni-easyinput v-model="baseFormData.enterpriseName" placeholder="请输入企业名称" />
      </uni-forms-item>
      <button type="primary" @click="submit">提交</button>
    </uni-forms>
  </view>
</template>

<script setup>
import { ref, unref } from 'vue'
import { huntSubmit } from '@/api/common'
const baseForm = ref()
const baseFormData = ref({
  name: null,
  phone: null,
  enterpriseName: null
})
const rules = {
  name: {
    rules: [{
      required: true,
      errorMessage: '姓名不能为空'
    }]
  },
  phone: {
    rules: [{required: true, errorMessage: '请输入手机号码' }]
  },
  enterpriseName: {
    rules: [{required: true, errorMessage: '请输入企业名称' }]
  }
}

const submit = async () => {
  try {
    const valid = await unref(baseForm).validate()
    if (!valid) return

    const { code, msg } = await huntSubmit(baseFormData.value)
    if (code !== 0) {
      uni.showToast({ title: msg, icon: 'none' })
      return
    }
    uni.showToast({ title: '提交成功，我们会尽快与您联系', icon: 'none', success: () => {
      setTimeout(() => {
        uni.navigateBack()
      }, 1000)
    } })
  } catch (error) {
    console.log('error', error)
  }
}
</script>

<style lang="scss" scoped>
.pa-3 {
  padding: 30rpx;
}
</style>