<template>
  <el-dialog
      model-value="edialogVisible"
      :title="dialogTitle"
      width="30%"
      @close="handleClose"
  >
    <el-form
        ref="formRef"
        :model="form"
        label-width="100px"
    >
      <el-form-item label="头像" prop="manicuristAvatar">

        <img :src="form.manicuristAvatar" width="80px" height="80px"/>
      </el-form-item>
      <el-form-item label="用户昵称" prop="manicuristName">
        {{form.manicuristName}}
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <template v-if="form.gender==0">女</template>
        <template v-else>男</template>
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        {{form.phone}}
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        {{form.email}}
      </el-form-item>
      <el-form-item label="工作名称" prop="specialties">
        {{form.specialties}}
      </el-form-item>
      <el-form-item label="工作时长" prop="employment_date">
        {{form.employment_date}}
      </el-form-item>
      <el-form-item label="评分" prop="rating">
        {{form.rating}}
      </el-form-item>
      <el-form-item label="余额" prop="salary">
        {{form.salary}}
      </el-form-item>
    </el-form>
    <template #footer v-if="title">
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">审核成功</el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import {defineEmits, defineProps, ref, watch} from "vue";
import axios from "@/util/axios";
import { ElMessage } from "element-plus";
const props=defineProps({
  id:{
    type:String,
    default:'',
    required:true
  },
  dialogTitle:{
    type:String,
    default:'',
    required:true
  }
})
const form=ref({
  id:null,
  email: "",
  gender: null,
  phone: "",
  businessId: "",
  manicuristName: "",
  employment_date: "",
  specialties: "",
  rating: null,
  salary: null,
  auditStatus:null,
  manicuristAvatar: ""
})

const title=ref(false);
const formRef=ref(null);
const initFormData=async(id)=>{

  const res = await axios.get("manicurist/queryById", {manicuristId: id})
  form.value=res.data.data;
   //console.log(res.data.data)
}
watch(
    ()=>props.id,
    ()=>{
      //console.log("id="+props.id);
      if (props.dialogTitle=='审核美甲师'){
        title.value=true;
      }
      let id=props.id;
        initFormData(id)


    }
)
// 定义父组件事件
const emits=defineEmits(['update:modelValue','handleCollapse'])
const handleClose=()=>{
  console.log("xxx")
// 调用执行
  emits('update:modelValue',false)
}


const handleConfirm = () => {
  form.value.auditStatus=1
  formRef.value.validate(async (valid) => {
    if (valid) {
      let result = await axios.post("manicurist/update", form.value)
      console.log(result.data.data)
      let data = result.data;
      if (data.code == 0) {
        ElMessage.success("执行成功！");
        formRef.value.resetFields();
        emits("handleCollapse");
        handleClose();
      } else {
        ElMessage.error(data.description);
      }
    } else {
      console.log("fail")
      return false
    }
  })
}

</script>
<style scoped>
</style>