<template>
  <div style="height: 50px;line-height: 50px;border-bottom: 1px solid #ccc;display: flex">
    <div style="width: 200px;padding-left: 30px;font-weight: bold;color: #39c5bb">后台管理</div>
    <div style="flex: 1"></div>
    <div style="width: 100px">
      <el-dropdown>
    <span class="el-dropdown-link">
     <br>{{username}}
      <el-icon class="el-icon--right">
        <arrow-down />
      </el-icon>
    </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="showInfo">个人信息</el-dropdown-item>
            <el-dropdown-item ><el-popconfirm title="确定要退出系统吗" @confirm="quit">
              <template #reference>
                退出系统
              </template>
            </el-popconfirm></el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>
  <el-dialog disabled="InfoEditable" width="30%" v-model="selfInfo" >
    <el-form model="InfoForm" label-width="120px"
             :disabled="InfoEditable">
      <el-form-item label="姓名" >
        <el-input v-model="username"/>
      </el-form-item>
      <el-form-item label="身份证">
        <el-input v-model="userid" />
      </el-form-item>
      <el-form-item label="联系电话">
        <el-input v-model="phonenumber"/>
      </el-form-item>
      <el-form-item label="就职医院">
        <el-input type="textarea" v-model="hospitalname"/>
      </el-form-item>
      <el-form-item label="擅长">
        <el-input type="textarea" v-model="description"/>
      </el-form-item>
    </el-form>
    <template #footer >
      <span class="dialog-footer" v-show="ToEditInfo">
        <el-button @click="ToViewInfo=true;ToEditInfo=false;InfoEditable=true">取消</el-button>
        <el-button type="primary" @click="save">确定</el-button>
      </span>
      <span class="dialog-footer" v-show="ToViewInfo">
        <el-button @click="selfInfo=false">取消</el-button>
        <el-button type="primary" @click="ToViewInfo=false;ToEditInfo=true;InfoEditable=false">编辑</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "DoctorHeader",
  props:["msg"],
  created() {
    this.initialization();
    },
  methods:{
    initialization(){
      this.did = this.msg;
      request.get('/doctor/get',{params:{userid:this.did}}).then(res=>{
        this.phonenumber=res.data.phonenumber;
        this.username=res.data.username;
        this.userid=res.data.userid;
        this.hospitalname=res.data.hospitalname;
        this.description=res.data.description;
        this.password=res.data.password;
      })
    },
    quit(){
      this.$router.replace({path: "/"});
    },
    save(){
      //将更新后的数据同步到数据库
      request.post('/doctor/updateDoctor',{
        phonenumber:this.phonenumber,
        username:this.username,
        userid:this.userid,
        hospitalname:this.hospitalname,
        description:this.description,
        password:this.password
      }).then(res=>{
        this.initialization();
      })
      this.selfInfo = false;
      this.ToViewInfo=true;
      this.ToEditInfo=false;
      this.InfoEditable=true
    },
    showInfo(){
      this.selfInfo=true;
    }
  },
  data(){
    return{
      did: "",
      selfInfo:false,
      InfoForm:{},
      ToEditInfo:false,
      ToViewInfo:true,
      username:"",
      phonenumber:"",
      userid:"",
      InfoEditable:true,
      hospitalname:"",
      description:"",
      password:"",
    }
  }
}
</script>
