<template>
    <div class="main-contain">
        <div class="position">
        <bread-crumb :crumbs="crumbs"></bread-crumb>
        <el-row style="float:right;">
            <el-col :span="24">
            <el-button size="small" icon="el-icon-printer" type="primary" @click="printAction">打印</el-button>
            </el-col>
        </el-row>
        </div>
        <div class="app-container" style="background-color: white;">
            <div id="print_content">
                <div class="print_main_content">
                    <div class="order_title_panl">
                        <span class="main_title">透析参数打印单</span>
                    </div>
                    <div style="display:flex;justify-content: space-between;margin-bottom:10px;">
                        <p>印单日期：{{nowDate}}</p>
                    </div>
                    <div class="table_panel">
                      <table class="table">
                         <thead>
                           <tr>
                             <td width="50">姓名</td>
                             <td width="50">透析模式</td>
                             <td width="50">上次透后体重(kg)</td>
                             <td width="50">透前体重(kg)</td>
                             <td width="50">干体重(kg)</td>
                             <td width="50">透前血压(mmhg)</td>
                             <td width="50">目标超滤量</td>
                             <td width="50">血流量(ml/min)</td>
                             <td width="50">抗凝剂(首剂)(维持)(总量)</td>
                             <td width="50">透析器/灌流器</td>
                           </tr>
                           <tr v-for="(item,index) in tableData" :key="index">
                             <td>{{item.patient.name}}</td>
                             <td>{{item.treatment_mode.name}}</td>
                             <td>{{getLastWeight(item.patient.id)?getLastWeight(item.patient.id):''}}</td>
                             <td>{{getWeightBefor(item.patient.id)?getWeightBefor(item.patient.id):''}}</td>
                             <td>{{getDryWeight(item.patient.id)?getDryWeight(item.patient.id):''}}</td>
                             <td>{{getSysBloodPressure(item.patient.id)?getSysBloodPressure(item.patient.id):''}}</td>
                             <td>{{getTargetUltrafiltration(item.patient.id)?getTargetUltrafiltration(item.patient.id):''}}</td>
                             <td>{{getBloodFlowVolume(item.patient.id)?getBloodFlowVolume(item.patient.id):''}}</td>
                             <td>
                               <span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 0"></span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 1">无肝素</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 2">普通肝素</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 3">低分子肝素</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 4">阿加曲班</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 5">枸橼酸钠</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 6">低分子肝素钙</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 7">低分子肝素钠</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 8">依诺肝素</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 9">达肝素</span>
                                 <span v-if="getAnticoagulant(item.patient.id) == 10">体外抗凝</span>
                               </span>
                               <span>
              
                                  {{getAnticoagulantShouji(item.patient.id)?getAnticoagulantShouji(item.patient.id):''}}
                                  <span v-if="getAnticoagulant(item.patient.id) == 1 && getAnticoagulantShouji(item.patient.id)!=''">mg</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 2  && getAnticoagulantShouji(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 3  && getAnticoagulantShouji(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 4  && getAnticoagulantShouji(item.patient.id)!=''">mg</span>
                                  <span v-if="getAnticoagulant(item.patient.id)== 5  && getAnticoagulantShouji(item.patient.id)!=''">mg</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 6  && getAnticoagulantShouji(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 7  && getAnticoagulantShouji(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 8  && getAnticoagulantShouji(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 9  &&getAnticoagulantShouji(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 10 && getAnticoagulantShouji(item.patient.id)!=''">mg</span>
                                </span>
                                <span>
                                  {{getAnticoagulantWeichi(item.patient.id)?getAnticoagulantWeichi(item.patient.id):''}}
                                  <span v-if="getAnticoagulant(item.patient.id) == 1 && getAnticoagulantWeichi(item.patient.id)!=''">mg/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 2 && getAnticoagulantWeichi(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 3 && getAnticoagulantWeichi(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 4 && getAnticoagulantWeichi(item.patient.id)!=''">mg/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 5 && getAnticoagulantWeichi(item.patient.id)!=''">ml/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 6 && getAnticoagulantWeichi(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 7 && getAnticoagulantWeichi(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 8 && getAnticoagulantWeichi(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 9 && getAnticoagulantWeichi(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 10 && getAnticoagulantWeichi(item.patient.id)!=''">mg</span>
                                </span>
                                <span>
                                    {{getAnticoagulantZongliang(item.patient.id)?getAnticoagulantZongliang(item.patient.id):''}}
                                  <span v-if="getAnticoagulant(item.patient.id) == 1 && getAnticoagulantZongliang(item.patient.id)!=''">mg</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 2 && getAnticoagulantZongliang(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 3 && getAnticoagulantZongliang(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id)== 4 && getAnticoagulantZongliang(item.patient.id)!=''">mg</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 5 && getAnticoagulantZongliang(item.patient.id)!=''">mg</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 6 && getAnticoagulantZongliang(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 7 && getAnticoagulantZongliang(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 8 && getAnticoagulantZongliang(item.patient.id)!=''">iu</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 9 && getAnticoagulantZongliang(item.patient.id)!=''">iu/h</span>
                                  <span v-if="getAnticoagulant(item.patient.id) == 10 && getAnticoagulantZongliang(item.patient.id)!=''">mg</span>
                                </span>
                             </td>
                             <td>
                               <span>{{getDialyzerPerfusionApparatus(item.patient.id)?getDialyzerPerfusionApparatus(item.patient.id):''}}</span></td>
                           </tr>
                         </thead>
                      </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
const moment = require('moment')
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import print from 'print-js'
import {getDialysisBatchParameters} from '@/api/consumable'
export default {
    components:{
        BreadCrumb
    },
    data(){
        return{
            crumbs: [
                { path: false, name: '耗材药品' },
                { path: false, name: '打印' }
            ],
            tableData:[],
            nowDate:"",
            start_time:"",
            prescriptionList:[],
            dialysisBefor:[]
        }
    },
    methods:{
        printAction: function() {
            const style = '@media print { .print_main_content { background-color: white; width:960px;  margin:0 auto; padding: 0 0 20px 0; } .order_title_panl { text-align: center; } .main_title { font-size: 18px; line-height: 40px; font-weight: 500; } .table_panel { } .table { width: 100%; border: 1px solid; border-collapse: collapse; padding: 2px; } thead tr td { border: 1px solid; text-align: center; font-size: 20px; padding: 15px 5px; } tbody tr td { border: 1px solid; text-align: center; font-size: 18px; padding: 10px 5px; } .proj { padding: 5px 0; text-align: left; } .proj_title { font-size: 16px; font-weight: 500; line-height: 25px; } .proj_item { font-size: 15px; line-height: 20px; } .zone_name { font-weight: 500; } }'

            printJS({
            printable: 'print_content',
            type: 'html',
            documentTitle: '  ',
            style: style,
            scanStyles: false
            })
        },

         getLastWeight(id){
       var lastweight = ""
        for(let i=0;i<this.dialysisBefor.length;i++){
          if(this.dialysisBefor[i].patient_id == id){
             lastweight = this.dialysisBefor[i].weight_after_last_transparency
          }
        }
        return lastweight
     },
     getWeightBefor(id){
       var assessmentBeforWeight = ""
        for(let i=0;i<this.dialysisBefor.length;i++){
          if(this.dialysisBefor[i].patient_id == id){
             assessmentBeforWeight = this.dialysisBefor[i].weight_before
          }
        }
       return assessmentBeforWeight
     },
     getDryWeight(id){
        var dryWeight = ""
        for(let i=0;i<this.dialysisBefor.length;i++){
          if(this.dialysisBefor[i].patient_id == id){
             dryWeight = this.dialysisBefor[i].dry_weight
          }
        }
       return dryWeight
     },
     getSysBloodPressure(id){
       var sysBloodPressure = ""
        for(let i=0;i<this.dialysisBefor.length;i++){
          if(this.dialysisBefor[i].patient_id == id){
             sysBloodPressure = this.dialysisBefor[i].systolic_blood_pressure
          }
        }
        return sysBloodPressure
     },
     getTargetUltrafiltration(id){
       var targetUltrafiltration = ""
       for(let i=0;i<this.prescriptionList.length;i++){
          if(this.prescriptionList[i].patient_id == id){
             targetUltrafiltration = this.prescriptionList[i].target_ultrafiltration
          }
        }
        return targetUltrafiltration
     },
     getBloodFlowVolume(id){
       var bloodFlowVolume = ""
       for(let i=0;i<this.prescriptionList.length;i++){
          if(this.prescriptionList[i].patient_id == id){
             bloodFlowVolume = this.prescriptionList[i].blood_flow_volume
          }
        }
       return bloodFlowVolume
     },
     getDialyzerPerfusionApparatus(id){
       var dialyzerPerfusionApparatus = ""
        for(let i=0;i<this.prescriptionList.length;i++){
          if(this.prescriptionList[i].patient_id == id){
             dialyzerPerfusionApparatus = this.prescriptionList[i].dialyzer_perfusion_apparatus
          }
        } 
      return dialyzerPerfusionApparatus
     },
     getAnticoagulant(id){
       var anticoagulant = ""
        for(let i=0;i<this.prescriptionList.length;i++){
          if(this.prescriptionList[i].patient_id == id){
             anticoagulant = this.prescriptionList[i].anticoagulant
          }
        } 
       return anticoagulant
     },
     getAnticoagulantShouji(id){
       var shouji = ""
       for(let i=0;i<this.prescriptionList.length;i++){
         if(this.prescriptionList[i].patient_id == id){
            shouji = this.prescriptionList[i].anticoagulant_shouji
          }
        } 
       return shouji
     },
     getAnticoagulantWeichi(id){
        var weichi = ""
        for(let i=0;i<this.prescriptionList.length;i++){
         if(this.prescriptionList[i].patient_id == id){
            weichi = this.prescriptionList[i].anticoagulant_weichi
        } 
       return weichi
      }
     },
     getAnticoagulantZongliang(id){
       var zongliang = ""
       for(let i=0;i<this.prescriptionList.length;i++){
         if(this.prescriptionList[i].patient_id == id){
            zongliang = this.prescriptionList[i].anticoagulant_zongliang
          }
        } 
       return zongliang
     }
    },
   created(){
     var nowDate  = moment(new Date()).add('year',0).format("YYYY-MM-DD")
     this.nowDate = nowDate
     var startime =  this.$route.query.startime
     console.log("startime",startime)
     this.start_time = startime
   },
   mounted(){
     var ids = this.$store.getters.temp_params.batch_print_dialysis_record_ids
     console.log("打印数据",ids)
     getDialysisBatchParameters(ids.join(','),this.start_time).then(response=>{
        if(response.data.state == 1){
          var schedule =  response.data.data.schedule
          console.log("schedule",schedule)
          this.tableData = schedule
          var prescription = response.data.data.prescription
          this.prescriptionList = prescription
          console.log("prescription",prescription)
          var dialysbefor = response.data.data.dialysbefor
          console.log("dialysbefor",dialysbefor)
          this.dialysisBefor = dialysbefor
        } 
     })
   }
}
</script>


<style rel="stylesheet/scss" lang="scss" scoped>
.print_main_content {
  background-color: white;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 0 20px 0;

  .order_title_panl {
    text-align: center;

    .main_title {
      font-size: 18px;
      line-height: 40px;
      font-weight: 500;
    }
  }
  .table_panel {
    .table {
      width: 100%;
      border: 1px solid;
      border-collapse: collapse;
      padding: 2px;

      thead {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 14px;
            padding: 15px 5px;
          }
        }
      }
      tbody {
        tr {
          td {
            border: 1px solid;
            text-align: center;
            font-size: 14px;
            padding: 10px 5px;

            .proj {
              padding: 5px 0;
              text-align: left;

              .proj_title {
                font-size: 16px;
                font-weight: 500;
                line-height: 25px;
              }

              .proj_item {
                font-size: 15px;
                line-height: 20px;

                .zone_name {
                  font-weight: 500;
                }
              }
            }
          }
        }
      }
    }
  }
}
</style>
