<template>
  <el-form
    :label-position="'right'"
    label-width="120px"
    :model="contactForm"
    :rules="contactFormRules"
    ref="contactRef"
    style="max-width: 66%"
  >
    <el-form-item label="联系人姓名" prop="contact_user">
      <el-input v-model="contactForm.contact_user" />
    </el-form-item>
    <el-form-item label="联系人手机号" prop="phone">
      <el-input v-model="contactForm.phone" />
    </el-form-item>
    <el-form-item label="联系人邮箱">
      <el-input v-model="contactForm.email"/>
    </el-form-item>
     <el-form-item label="备注">
      <el-input type="textarea" :rows="3" v-model="contactForm.remark" />
    </el-form-item>
  </el-form>
</template>

<script setup>
import { reactive, ref, onMounted } from 'vue'

const contactForm = reactive({
  contact_user: '',
  phone: '',
  email: '',
  remark: '',
})

const contactFormRules = reactive({
  contact_user: [
    { required: true, message: '请输入联系人姓名', trigger: 'blur' },
  ],
  phone: [
    { required: true, message: '请输入联系人手机号', trigger: 'blur' },
  ],
})
const contactRef = ref(null)
const emit = defineEmits(['action'])

const submitForm = async () => {
  if (!contactRef) return
  await contactRef.value.validate((valid, fields) => {
    if (valid) {
      emit('action', contactForm)
    } else {
      emit('action',null)
    }
  })
}
const clearForm = () => {
  if (!contactRef) return
  contactRef.value.resetFields()
} 

const setForm = (data) => {
  contactForm.value = Object.assign(contactForm, data);
}

onMounted(() => {
   
})

defineExpose({ submitForm, clearForm, setForm })
</script>