<template>
  <div style="display:flex">
<!-- 工作人员浏览全部患者   -->
    <div v-if="showModel=='allPatient'" style="flex:2">
      <el-table :data="patientData" stripe style="width: 100%">
        <el-table-column prop="userid" style="width: 1px" ></el-table-column>
        <el-table-column prop="username" label="患者姓名" />
        <el-table-column prop="phonenumber" label="联系方式" />
        <el-table-column label="操作">
          <template #default="scope">
            <el-button size="small" type="" @click="showPatientInfo(scope.row)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

<!--    工作人员浏览具体患者-->
    <div v-if="showModel=='onePatient'" style="display: flex">
      <div style="flex: 2">
        <div style="display: flex">
          <div>
          <!-- 患者头像-->
          </div>

          <div style="flex: 2">
              <div>姓名：{{pname}}</div>
              <div style="margin-top: 20px">性别：{{sex}}</div>
              <div style="margin-top: 20px">联系方式：{{phone}}</div>
              <div style="margin-top: 20px">家庭地址：{{address}}</div>
            <div style="align-self: start;margin-top: 40px">医生</div>
            <div style="margin-top: 20px">姓名：{{dname}}</div>
            <div style="margin-top: 20px">联系方式：{{number}}</div>
            <div style="margin-top: 20px">就职医院：{{hospital}}</div>
            <el-button style="margin-top: 50px" @click="showModel='allPatient'" type="primary">返回</el-button>
          </div>
        </div>
      </div>
    </div>


  </div>
</template>

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

export default {
  name: "PatientBreviary",
  mounted:function (){
    this.showModel='allPatient';
    this.loadPatient();
  },
  data(){
    return{
      patientData: [{
        username:'A',
        gender:'1',
        phonenumber:'111',
      }
      ],
      gender:"default",
      pname:"default",
      sex:"default",
      phone:"default",
      address:"default",
      dname:"default",
      number:"default",
      hospital:"default",
      showModel:""
    }
  },
  methods:{
    loadPatient(){
      request.get("/worker/selectAll").then(res=>{
        this.patientData=res.data;
      });
    },
    loadSpecificPatient(patientId){
      request.get('/doctor/getUserAndDoctor',{params:{userid:patientId}}).then(res=>{
        this.pname=res.data[0].username;
        this.phone=res.data[0].phonenumber;
        this.address=res.data[0].address;
        this.dname=res.data[1].username;
        this.number=res.data[1].phonenumber;
        this.hospital=res.data[1].hospitalname;
        if(res.data[0].gender==true){
          this.sex='男';
        }else {
          this.sex='女';
        }
      })
    },
    showPatientInfo(row){
      this.showModel='onePatient';
      this.loadSpecificPatient(row.userid);
    },
  }
}
</script>

<style scoped>

</style>