<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"> &nbsp;
              透析参数
            </span>
            <span  style="float:right;">打印日期: &nbsp;
               {{$route.query.schedule_date}}
            </span>
          </div>
          <div class="table_panel">

            <table class="table">
              <thead>
              <tr>
                <td width="60">序号</td>
                <td width="100"  v-if="dialysisSett.device_number==1">透析机号</td>
                <td width="100"  v-if="dialysisSett.name==1">姓名</td>
                <td width="100"  v-if="dialysisSett.name==1">透析模式</td>
                <td width="100" v-if="dialysisSett.dialysis_no==1">透析号</td>
                <td width="100" v-if="dialysisSett.admission_number==1">住院(门诊)号</td>
                <td width="100"  v-if="dialysisSett.weight_befor==1">透前体重</td>
                <td width="100"  v-if="dialysisSett.dry_weight==1">干体重</td>
                <td width="100"  v-if="dialysisSett.blood_pressure==1">透前血压</td>
                <td width="100" v-if="dialysisSett.ultrafiltration_volume==1">目标脱水量</td>
                <td width="200" v-if="dialysisSett.anticoagulant==1">抗凝剂(首剂)(维持)(总量)</td>
                <td width="100" v-if="dialysisSett.dialysis_time ==1">透析时长</td>
                <td width="100"  v-if="dialysisSett.device_type==1">设备型号</td>
                <td width="100" v-if="dialysisSett.dialyzer_perfusion_apparatus == 1">透析器/灌流器</td>
                <td width="100"  v-if="dialysisSett.dialysis_dialyszers == 1">透析器</td>
                <td width="100" v-if="dialysisSett.dialysis_irrigation ==1">灌流器</td>
                 <td width="100" v-if="dialysisSett.displace_liqui_part==1">置换液</td>
                <td width="100"  v-if="dialysisSett.displace_liqui_value==1">置换液总量</td>
                <td width="100" v-if="dialysisSett.kalium==1">钾</td>
                <td width="100"  v-if="dialysisSett.sodium==1">钠</td>
                <td width="100" v-if="dialysisSett.calcium==1">钙</td>
                <td width="100" v-if="dialysisSett.bicarbonate == 1">碳酸氢盐</td>
                <td width="100" v-if="dialysisSett.blood_access==1">血管通路</td>
                <td width="100" v-if="dialysisSett.sealing_fluid_dispose == 1">封管液</td>
                <td width="100"  v-if="dialysisSett.glucose==1">葡萄糖</td>
                <td width="100"  v-if="dialysisSett.blood_flow_volume==1">血流量</td>
                <td>封管液</td>
                <td>促红</td>
              </tr>
              </thead>
              <tbody>
               <tr v-for="(item,i) in list" :key="i">
                <td width="50">{{i+1}}</td>
                <td width="100"  v-if="dialysisSett.device_number==1">
                   {{item.device_number.zone.name}}{{item.device_number.number}}
                </td>
                <td width="100"  v-if="dialysisSett.name==1">
                   {{item.patient.name}}
                </td>
                <td width="100">
                  <span v-if="item.mode_id == 1">HD</span>
                  <span v-if="item.mode_id == 2">HDF</span>
                  <span v-if="item.mode_id == 3">HD+HP</span>
                  <span v-if="item.mode_id == 4">HP</span>
                  <span v-if="item.mode_id == 5">HF</span>
                  <span v-if="item.mode_id == 6">SCUF</span>
                  <span v-if="item.mode_id == 7">IUF</span>
                  <span v-if="item.mode_id == 8">HFHD</span>
                  <span v-if="item.mode_id == 9">HFHD+HP</span>
                  <span v-if="item.mode_id == 10">PHF</span>
                  <span v-if="item.mode_id == 11">HFR</span>
                  <span v-if="item.mode_id == 12">HDF+HP</span>
                  <span v-if="item.mode_id == 13">CRRT</span>
                  <span v-if="item.mode_id == 19">IUF+HD</span>
                  <span v-if="item.mode_id == 20">UF</span>
                  <span v-if="item.mode_id == 21">HD+</span>
                  <span v-if="item.mode_id == 22">血浆胆红素吸附+HDF</span>
                  <span v-if="item.mode_id == 23">血浆胆红素吸附</span>
                  <span v-if="item.mode_id == 24">I-HDF</span>
                  <span v-if="item.mode_id == 25">HD高通F</span>
                  <span v-if="item.mode_id == 26">CVVH</span>
                  <span v-if="item.mode_id == 27">CVVHD</span>
                  <span v-if="item.mode_id == 28">CVVHDF</span>
                  <span v-if="item.mode_id == 29">PE</span>
                  <span v-if="item.mode_id == 30">血浆胆红素吸附+HP</span>
                  <span v-if="item.mode_id == 31">HPD</span>
                  <span v-if="item.mode_id == 32">HDP</span>
                  <span v-if="item.mode_id == 33">HFD</span>
                  <span v-if="item.mode_id == 34">HDF100</span>
                  <span v-if="item.mode_id == 35">HDF600</span>
                  <span v-if="item.mode_id == 35">HDF800</span>
                  <span v-if="item.mode_id == 35">HDF1000</span>
                 
                </td>
                <td width="100" v-if="dialysisSett.dialysis_no==1">
                   {{item.patient.dialysis_no}}
                </td>
                <td width="100" v-if="dialysisSett.admission_number==1">
                   {{item.xt_receive_treatment_asses.admission_number}}
                </td>
                <td width="100"  v-if="dialysisSett.weight_befor==1">
                  <span v-if="item.assessment_befor_dislysis.weight_before > 0">{{item.assessment_befor_dislysis.weight_before}} </span>  
                </td>
                <td width="100"  v-if="dialysisSett.dry_weight==1">
                   <span v-if="item.assessment_befor_dislysis.dry_weight > 0">{{item.assessment_befor_dislysis.dry_weight}} </span> 
                </td>
                <td width="100"  v-if="dialysisSett.blood_pressure==1">
                    <span v-if="item.assessment_befor_dislysis.systolic_blood_pressure>0">{{item.assessment_befor_dislysis.systolic_blood_pressure}}</span>
                    <span v-if="item.assessment_befor_dislysis.diastolic_blood_pressure>0">/{{item.assessment_befor_dislysis.diastolic_blood_pressure}}</span> 
                </td>
                <td width="100" v-if="dialysisSett.ultrafiltration_volume==1">
                   <span v-if="item.dialysis_solution.target_ultrafiltration>0">{{item.dialysis_solution.target_ultrafiltration}}</span>
                </td>
                <td width="200" v-if="dialysisSett.anticoagulant==1">
                  <span>{{getAnticoagualnt(item.dialysis_solution.anticoagulant)}}</span>
                  <span v-if="item.dialysis_solution.anticoagulant_shouji > 0">({{item.dialysis_solution.anticoagulant_shouji}})</span>
                  <span v-if="item.dialysis_solution.anticoagulant_weichi > 0">({{item.dialysis_solution.anticoagulant_weichi}})</span>
                  <span v-if="item.dialysis_solution.anticoagulant_zongliang > 0">({{item.dialysis_solution.anticoagulant_zongliang}})</span>
                </td>
                <td width="100" v-if="dialysisSett.dialysis_time ==1">
                   <span v-if="item.dialysis_solution.dialysis_duration_hour >0">{{item.dialysis_solution.dialysis_duration_hour}}时</span>
                   <span v-if="item.dialysis_solution.dialysis_duration_minute >0">{{item.dialysis_solution.dialysis_duration_minute}}分</span>
                </td>
                <td width="100"  v-if="dialysisSett.device_type==1">
                   <span>{{item.assessment_befor_dislysis.machine_type}}</span>
                </td>
                <td width="100" v-if="dialysisSett.dialyzer_perfusion_apparatus == 1">
                    <span>{{item.dialysis_solution.dialyzer_perfusion_apparatus}}</span>
                </td>
                <td width="100"  v-if="dialysisSett.dialysis_dialyszers == 1">
                   <span>{{item.dialysis_solution.dialysis_dialyszers}}</span>
                </td>
                <td width="100" v-if="dialysisSett.dialysis_irrigation ==1">
                     <span>{{item.dialysis_solution.dialysis_irrigation}}</span>
                </td>
                <td width="100"  v-if="dialysisSett.displace_liqui_part==1">
                  <span>{{getDisplaceLiquiPart(item.dialysis_solution.displace_liqui_part)}}</span>
                </td>
                <td width="100"  v-if="dialysisSett.displace_liqui_value==1">
                  <span v-if="item.dialysis_solution.displace_liqui_value > 0">{{item.dialysis_solution.displace_liqui_value}}</span>
                </td>
                <td width="100" v-if="dialysisSett.kalium==1">
                   <span v-if="item.dialysis_solution.kalium >0">{{item.dialysis_solution.kalium}}</span>
                </td>
                <td width="100"  v-if="dialysisSett.sodium==1">
                   <span v-if="item.dialysis_solution.sodium > 0">{{item.dialysis_solution.sodium}}</span>
                </td>
                <td width="100" v-if="dialysisSett.calcium==1">
                  <span v-if="item.dialysis_solution.calcium >0">{{item.dialysis_solution.calcium}}</span>
                </td>
                <td width="100" v-if="dialysisSett.bicarbonate == 1">
                   <span v-if="item.dialysis_solution.bicarbonate >0">{{item.dialysis_solution.bicarbonate}}</span>
                </td>
                <td width="100" v-if="dialysisSett.blood_access==1">
                  <span>{{getBloodAccessOption(item.dialysis_solution.blood_access)}}</span>
                </td>
                <td width="100" v-if="dialysisSett.sealing_fluid_dispose == 1">
                   <span> {{item.xt_assesment_after_dislysis.sealing_fluid_dispose}} </span>
                </td>
                <td width="100"  v-if="dialysisSett.glucose==1">
                   <span>{{item.dialysis_solution.amylaceum?item.dialysis_solution.amylaceum:""}}</span> 
                </td>
                <td width="100"  v-if="dialysisSett.blood_flow_volume==1">
                   <span>{{item.dialysis_solution.blood_flow_volume?item.dialysis_solution.blood_flow_volume:""}}</span> 
                </td>
                
                <td>
                  <span v-if="getBloodAccessOption(item.dialysis_solution.blood_access).indexOf('导管')!==-1">1</span>
                  <span v-else></span>
                </td>
                
                
                <td>
                  {{ item.advice_spc }}
                </td>
               </tr>
              </tbody>
            </table>
            <span>低分子肝素:{{total_one}}</span>
            <span>促红:{{ total_two }}</span>
            <span>封管液:{{ total_three }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { getDialysisParameter } from '@/api/dialysis'
  import { parseTime } from '@/utils'
  import { uParseTime } from '@/utils/tools'
  import BreadCrumb from '@/xt_pages/components/bread-crumb'
  import print from 'print-js'
  import { getDataConfig } from '@/utils/data'
  export default {
    name: 'SchedulePrint',
    data() {
      return {
        crumbs: [
          { path: false, name: '排班管理' },
          { path: false, name: '透析参数打印' }
        ],
        td_1_width: '8%',
        td_2_width: '8%',
        td_3_width: '64%',
        td_4_width: '20%',
        month: 1,
        begin_day: 1,
        total:[],
        list:[],
        schedule_date:"",
        schedule_type:0,
        partition_type:0,
        keywords:"",
        loading:false,
        tableData:[],
        numberList:[],
        partitionArr:[],
        his_config:{},
        typeList:[],
        rowList:[],
        dialysate_formulation:[],
        body_fluid_option:[],
        displace_liqui_part_option:[],
        blood_access_option:[],
        hemodialysisPipelinesOptions:[],
        tableList:[],
        list:[],
        dialysisSett:{},
        total_one:0,
        total_two:0,
        total_three:0
      }
    },
    components: {
      BreadCrumb
    },
    created() {
      this.displace_liqui_part_option = this.$store.getters.displace_liqui
      this.blood_access_option  = getDataConfig('hemodialysis', 'vascular_access_desc')
      this.getlist()
    },
    methods: {
    getlist(){
       var params = {
         schedule_date:this.$route.query.schedule_date,
         schedule_type:this.$route.query.schedule_type,
         partition_id:this.$route.query.partion_id,
         page:this.$route.query.page,
         limit:500,
         ids:this.$route.query.ids,
       }
      console.log("params",params)
      getDialysisParameter(params).then(response=>{
          if(response.data.state == 1){
            var list = response.data.data.list
            if(list!=null &&list.length>0){
                for(let i=0;i<list.length;i++){
                  list[i].sort = 0
                  list[i].sort = list[i].device_number.sort
                }
      
              }
              list.sort(this.compare('sort'))

            var total_one =0
            var total_two=0
            var total_three =0  
            console.log("listoowowowwoww",list)
            for(let i=0;i<list.length;i++){
              list[i].advice_spc =""
                for(let j=0;j<list[i].advice.length;j++){
                    total_two +=parseInt(list[i].advice[j].prescribing_number) 
                    if((list[i].advice[j].advice_name).indexOf("促红")!=-1){
                      list[i].advice_spc+= (list[i].advice[j].single_dose + "iu"+"/"+ list[i].advice[j].prescribing_number_unit)+","
                    }
                }
              this.total_two =total_two
              if(list[i].dialysis_solution.anticoagulant == 3){
                  total_one ++
              }
              this.total_one =total_one
              
              if(this.getBloodAccessOption(list[i].dialysis_solution.blood_access).indexOf('导管')!=-1){
                   total_three++
              }
              this.total_three = total_three
             
            }
            this.list = list
            this.dialysisSett = response.data.data.dialysisSett
            console.log("设置",this.dialysisSett)
          }
      }) 
     },
     getTimeOne(val) {
        if(val == ""){
        return ""
        }else {
        return uParseTime(val, '{y}-{m}-{d}')
        }
     },
      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: 16px; padding: 0px 5px; } tbody tr td { border: 1px solid; text-align: center; font-size: 14px; padding: 0px 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
       })
      },
      getAnticoagualnt(id){
       var name = ""
       if(id == 1){
         name = "无肝素"
       }
       if(id == 2){
        name = "普通肝素"
       }
       if(id == 3){
         name ="低分子肝素"
       }
       if(id == 4){
         name ="阿加曲班"
       }
       if(id == 5){
         name ="枸橼酸钠"
       }
       if(id == 6){
         name ="低分子肝素钙"
       }
       if(id == 7){
         name ="低分子肝素钠"
       }
       if(id == 8){
         name ="依诺肝素"
       }
       if(id == 9){
         name ="达肝素"
       }
       if(id == 10){
         name ="体外抗凝"
       }
       if(id == 11){
         name ="那屈肝素"
       }
       if(id == 12){
         name ="无抗凝剂"
       }
       if(id == 13){
         name ="那屈肝素钙"
       }
       return name
     },
     getBloodAccessOption(id){
       var name = ""
       for(let i=0;i<this.blood_access_option.length;i++){
         if(id == this.blood_access_option[i].id){
            name = this.blood_access_option[i].name
         }
       }
       return name
     },
     getDisplaceLiquiPart(id){
       var name = ""
       for(let i=0;i<this.displace_liqui_part_option.length;i++){
         if(id == this.displace_liqui_part_option[i].id){
            name = this.displace_liqui_part_option[i].name
         }
       }
       return name
     },
     compare(p) { //这是比较函数
        return function (m, n) {
          var a = m[p];
          var b = n[p];
          return a - b; //升序
        }
      },
    
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  .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;
  }

  }
  }
  }
  }
  }
  }
  }
  }
</style>

