<template>
    <div class="patient-info-container ">
      <span class="patient-info">姓名：{{patientInfo.name}} &nbsp;&nbsp; 性别：{{tranSex(patientInfo.gender)}} &nbsp;&nbsp; 年龄：{{tranAge(patientInfo.birthday)}} &nbsp;&nbsp; 透析号：{{patientInfo.dialysis_no}} </span>
    </div>
</template>

<script>
import {jsGetAge, uParseTime} from "@/utils/tools";
export default {
    name:'persionInfo',
    data(){
        return {
            patientInfo:{
                name:'',
                gender:0,
                birthday:0,
                dialysis_no:'',
            },
        }
    },
    props:{
        patient:{
            type:Object,
            default: function () {
                return {};
            }
        }
    },
    created(){
        // this.patientInfo = this.patient;
    },
    watch:{
        "patient":function(){
            if (typeof(this.patient.id) != 'undefined') {
                this.patientInfo = this.patient;
            }
        }
    },
    methods:{
      tranAge(birthday) {
        var birth = uParseTime(birthday, '{y}-{m}-{d}');
        return jsGetAge(birth, '-');
      },
      tranSex(gender) {
        var sex = "未知";
        switch (gender) {
          case 1:
            sex = "男"
            break;
          case 2:
            sex = "女"
            break;
          default:
            break;
        }
        return sex;
      }
    },
}
</script>
<style scoped>
.patient-info-container {
  margin: 10px 0px;
}
.patient-info-container .patient-info {
    font-size: 16px;
}
</style>

