<!--健康信息上报模块-->
<template>
  <div>
    <h2 style="color: #3898EC">请上报您最近的健康信息</h2>
<!--    基本信息表单-->
    <el-input v-model="username"  placeholder="姓名" disabled/>
    <el-icon></el-icon>
    <el-input v-model="age" placeholder="年龄"/>
    <el-icon></el-icon>
    <el-input v-model="height" placeholder="身高cm"/>
    <el-icon></el-icon>
    <el-input v-model="weight" placeholder="体重kg"/>
    <el-icon></el-icon>
    <el-input v-model="heartRate" placeholder="心率"/>
    <el-icon></el-icon>
    <el-input v-model="highpressure" placeholder="最高血压值"/>
    <el-icon></el-icon>
    <el-input v-model="lowpressure" placeholder="最低血压值"/>
    <el-icon></el-icon>
<!--    功能与按钮-->
    <el-input type="textarea" v-model="userId" disabled/>
      <span class="dialog-footer">
        <el-button @click="clearPost">清空</el-button>
        <el-button type="primary" @click="saveHealth">确认上报</el-button>
      </span>
    <el-dialog v-model="dialogVisible" title="确定" width="30%" :before-close="handleClose">
      <span>{{info}}</span>
      <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">确认</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

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

export default {
  name: "postHealth",
  created() {
    this.loadHealth()
  },
  data(){
    return{
      health:[],
      // 基本信息数据
      username:this.$store.getters.username,
      age:"",
      height:"",
      weight:"",
      highpressure:"",
      lowpressure:"",
      timeForTakeNucleicAcidTests:"",
      temperature:"",
      userId:this.$store.getters.userid,
      heartRate:"",
      havingTakenCovidTest:false,
      // 可见性等功能控制
      dialogVisible:false,
      //上报信息反馈
      info:"",
    }
  },
  methods:{
    // 导入一些初始化的身体健康信息
    loadHealth(){
      request.get("/dailyReport/print",{params:{userid:this.userId}}).then(res=>{
            this.age=res.data[1].age
            this.height=res.data[1].height,
            this.weight=res.data[1].weight
      })
    },
    //上传健康信息
    saveHealth(){
      request.post("/dailyReport/add",{
        uid:this.userId,age:this.age,height:this.height,weight:this.weight,temperature:this.temperature,
        lowpressure:this.lowpressure,highpressure:this.highpressure,heartRate:this.heartRate,covidTest:this.havingTakenCovidTest})
          .then(res=>{this.info=res.msg;this.dialogVisible = true})
    },
    clearPost(){
      this.age = "";
      this.height="";
      this.weight="";
      this.heartRate="";
      this.highpressure="";
      this.lowpressure="";
    }
  }
}
</script>
