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

          </div>
          <div class="doctorBox">
              <p>医师：{{item.doctor?item.doctor:""}}</p>
              <p>日期：{{getTime(item.ctime)?getTime(item.ctime):""}}</p>
          </div>
          <div class="actionBar">
                 <p>审核：{{getDoctor(item.advices[0].checker)?getDoctor(item.advices[0].checker):""}}</p>
                 <p>配对：</p>
                 <p>核对：{{getDoctor(item.advices[0].checker)?getDoctor(item.advices[0].checker):""}}</p>
                 <p>发药：{{getDoctor(item.advices[0].execution_staff)?getDoctor(item.advices[0].execution_staff):""}}</p>
                 <p>药费：{{getTotalOne(item.id)?getTotalOne(item.id):0}}元</p>
          </div>
          <div style="page-break-after:always"></div>
      </div>
    </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,
      ids:String
    }, 
    data(){
      return {
        doctorList:[],
        advicePrint:{},
        patient:{},
        tableData:[],
        prescriptionInfo:[],
        hisPatient:{},
        department:[],
        prescriptions:[],
        orgname:""
      }
    },
   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,
          patient_id:this.patient_id,
          record_date:this.record_date,
          prescription_id:this.prescription_id,
          ids:this.ids
        }
        console.log("params",params)
       getPrescriptionPrint(params).then(response=>{
         if(response.data.state == 1){
            var advicePrint =  response.data.data.advicePrint
            console.log("adviceprint9999",advicePrint)
            this.advicePrint = advicePrint
            this.prescriptions = advicePrint
          }
       })
     },
     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
     },
     getTotalOne(id) {
        var total = 0
        var addtotal = 0
        for (let i = 0; i < this.prescriptions.length; i++) {
          if(id == this.prescriptions[i].id){
            if (this.prescriptions[i].advices != null) {
              for (let a = 0; a < this.prescriptions[i].advices.length; a++) {
                total = total + this.prescriptions[i].advices[a].price * this.prescriptions[i].advices[a].prescribing_number
              }
            }
          
            if (this.prescriptions[i].additionalcharge != null) {
              for (let b = 0; b < this.prescriptions[i].additionalcharge.length; b++) {
                addtotal = addtotal + this.prescriptions[i].additionalcharge[b].price * this.prescriptions[i].additionalcharge[b].count
              }
            }
              addtotal =  Math.floor(addtotal * 100) / 100
        }
       }
       return total + addtotal
      }, 


   },
   created(){
      this.getAllDoctorList()
      this.getInitData()
      this.getPrescriptionPrint()
      this.getHisPatientDetail()
      var xtuser = this.$store.getters.xt_user
      this.orgname = xtuser.org.org_name
     
   },
  //  watch:{
  //    patient_id:function(val){
  //      console.log("101000010101010",this.patient_id,this.record_date,this.prescription_id)
  //      this.getPrescriptionPrint()
  //      this.getHisPatientDetail()
  //    }
  //  }
}
</script>


<style lang="scss" scoped>
.prescription-print{
  -webkit-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 60px rgba(0, 0, 0, 0.06) inset;
    -moz-box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset; 
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.27), 0 0 40px rgba(0, 0, 0, 0.06) inset;
    margin-bottom: 20px;
    padding:20px 0px;
}
.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>
