<template>
    <div id='prescription-print' class="prescription-print">
        <div class="printTitle">血液透析中心处方笺</div>
        <div class="infoTitle">
            <p>姓名：{{patient.name}}</p>
            <p>性别：
               <span v-if="patient.gender == 1">男</span>
               <span v-if="patient.gender == 2">女</span>
            </p>
            <p>年龄：{{patient.age}}岁</p>
        </div>
        <div class="infoMain">
            <div style="margin-bottom: 10px;">门诊号：{{this.hisPatient.number?this.hisPatient.number:""}}</div>
            <div style="margin-bottom: 10px;">科室：{{getDepart(this.hisPatient.departments?this.hisPatient.departments:"")}}</div>
            <div style="margin-bottom: 10px;">医保卡号：{{this.hisPatient.number?this.hisPatient.number:""}}</div>
            <div style="margin-bottom: 10px;">电话：{{patient.phone}}</div>
            <div>地址：{{patient.home_address}}</div>
            <div style="display:flex;width:50%;">临床诊断：{{patient.diagnose}}</div>
        </div>
        <div class="prescriptionBox">
            <div class="Rp">Rp:</div>
            <div class="drugsBox" v-for="(item,index) in advicePrint" :key="index">
                <div class="drugsOne">{{item.advice_name?item.advice_name:""}}&nbsp;&nbsp;{{item.single_dose}}{{item.single_dose_unit}}&nbsp;×&nbsp; {{item.prescribing_number}}{{item.prescribing_number_unit}}</div>
                <div style="margin-left:100px;"><span>用法：{{item.single_dose}}{{item.single_dose_unit}}</span>&nbsp;&nbsp;<span>{{item.execution_frequency}}</span>&nbsp;&nbsp;<span>{{item.advice_desc}}</span></div>
            </div>

            
        </div>
        <div class="doctorBox">
            <p>医师：{{getDoctor(advicePrint[0].advice_doctor)?getDoctor(advicePrint[0].advice_doctor):""}}</p>
            <p>日期：{{getTime(advicePrint[0].advice_date)?getTime(advicePrint[0].advice_date):""}}</p>
        </div>
        <div class="actionBar">
            <p>审核：{{getDoctor(advicePrint[0].advice_doctor)?getDoctor(advicePrint[0].advice_doctor):""}}</p>
            <p>配对:</p>
            <p>核对：{{getDoctor(advicePrint[0].checker)?getDoctor(advicePrint[0].checker):""}}</p>
            <p>发药：{{getDoctor(advicePrint[0].execution_staff)?getDoctor(advicePrint[0].execution_staff):""}}</p>
            <p>药费：{{advicePrint[0].price?advicePrint[0].price:""}}</p>
        </div>
    </div>
</template>
<script>
import { jsGetAge, uParseTime } from '@/utils/tools'
import {getAllDoctorList,getPrescriptionPrint,getHisPatientDetail} from "@/api/project/project"
import {getInitData} from "@/api/his/his"
export default {
    props:{
      patient_id:Number,
      record_date:String,
      prescription_id:Number
    }, 
    data(){
      return {
        doctorList:[],
        advicePrint:{},
        patient:{},
        tableData:[],
        prescriptionInfo:[],
        hisPatient:{},
        department:[]
      }
    },
   methods:{
     
     getAllDoctorList(){
      getAllDoctorList().then(response=>{
        if(response.data.state == 1){
               var doctor =  response.data.data.doctor
               
               this.doctorList = doctor
             }
         })   
     },

      getDoctor(id){
        var name = ""
        for(let i=0;i<this.doctorList.length;i++){
          if(id == this.doctorList[i].admin_user_id){
              name = this.doctorList[i].user_name
          }
        }
        return name
      },
      getTime(value, temp) {
        if (value != undefined) {
            return uParseTime(value, temp)
        }
        return ''
     },
       getPrescriptionPrint(){
         var params = {
          patient_id:this.patient_id,
          record_date:this.record_date,
          prescription_id:this.prescription_id,
        }
        console.log("params---",params)
       getPrescriptionPrint(params).then(response=>{
         if(response.data.state == 1){
            var advicePrint =  response.data.data.advicePrint
            console.log("adviceprint",advicePrint)
            this.advicePrint = advicePrint
            var patient =  response.data.data.patient
            console.log("patient",patient)
            this.patient = patient
            var doctorPorject = response.data.data.doctorPorject
          
            var arr = doctorPorject.project
              console.log("我的中谷歌",arr)
            for(let i=0;i<arr.length;i++){
              console.log("arr",arr[i].project_name)
            }
            this.tableData = arr
            console.log("3333",this.tableData)
            var prescriptioninfo = response.data.data.prescriptionInfo
            console.log("prescriptioninfo",prescriptioninfo)
            this.prescriptionInfo = prescriptioninfo
          }
       })
     },
     getHisPatientDetail(){
          const params = {
              patient_id:this.patient_id
          }
       getHisPatientDetail(params).then(response=>{
          if(response.data.state == 1){
             var hisPatient =  response.data.data.hisPatient
             console.log("挂号病人",hisPatient)
             this.hisPatient = hisPatient
          }
       })
     },
     getInitData(){
       getInitData().then(response=>{
          if(response.data.state == 1){
            this.department = response.data.data.department
           
          }
       })
     },
     getDepart(id){
         var name = ""
       for(let i=0;i<this.department.length;i++){
           if(id == this.department[i].id){
               name = this.department[i].name
           }
       }
       return name
     }
   },
   created(){
      this.getAllDoctorList()
      this.getInitData()
   },
   watch:{
     patient_id:function(val){
       console.log("999999888888",this.patient_id,this.record_date,this.prescription_id)
       this.getPrescriptionPrint()
       this.getHisPatientDetail()
     }
   }
}
</script>


<style lang="scss" scoped>
.printTitle{
    font-size: 22px;
    text-align: center;
    font-weight: bold;
}
.infoTitle{
    display: flex;
    border-bottom: 2px solid #000;
    margin-top:10px;
    line-height: 24px;
    padding:0 10px;
}
.infoTitle p{
    width: 200px;
}
.infoMain{
    display: flex;
    flex-wrap: wrap;
    border-bottom: 2px solid #000;
    padding:0 10px;
}
.infoMain div{
    width: 50%;
    line-height: 24px;
}
.prescriptionBox{
    padding:0 10px;
    min-height:450px;
}
.Rp{
    font-size: 22px;
    font-weight: bold;
}
.drugsBox{
    padding-left: 40px;
    margin-bottom: 10px;
}
.drugsBox div{
    line-height: 20px;
}
.drugsOne{
    line-height: 24px;
}
.drugsOne span{
    margin-right: 20px;
}
.doctorBox{
    display: flex;
    justify-content: space-between;
    padding:0 10px;
    line-height: 24px;
    border-bottom: 2px solid #000;
}
.actionBar{
    display: flex;
    justify-content: space-between; 
    line-height: 24px;
    padding:0 10px;
}
.actionBar p{
    width:150px;
}
</style>
