<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:left;">打印日期: &nbsp;
                 {{$route.query.schedule_date}}
              </span>
            </div>
            <div class="table_panel">
  
              <table class="table">
                <thead>
                <tr>
                  <td width="60" v-if="gatherSetting.index_number == 1">序号</td>
                  <td width="100"  v-if="gatherSetting.name==1">姓名</td>
                  <td width="100"  v-if="gatherSetting.dialysis_no==1">透析号</td>
                  <td width="100"  v-if="gatherSetting.admission_number==1">住院(门诊)号</td>
                  <td width="100" v-if="gatherSetting.mode_type==1">透析模式</td>
                  <td width="100" v-if="gatherSetting.dialysis_dialyszers == 1">透析器</td>
                  <td width="100"  v-if="gatherSetting.dialysis_irrigation ==1">灌流器</td>
                  <td width="100"  v-if="gatherSetting.dialysis_irrigation ==1">滤过器</td>
                  <td width="100"  v-if="gatherSetting.change_nurse ==1">换药包/穿刺针</td>
                  <td width="100" v-if="gatherSetting.anticoagulant==1">抗凝剂(首剂)(维持)(总量)</td>
                  <td width="200" v-if="gatherSetting.tube==1">封管液</td>
                  <td width="100" v-if="gatherSetting.kalium==1">钾</td>
                  <td width="100"  v-if="gatherSetting.calcium==1">钙</td>
                  <td width="100" v-if="gatherSetting.cuhong == 1">促红素</td>
                  <td width="100"  v-if="gatherSetting.zuoka == 1">左卡</td>
                  <td width="100" v-if="gatherSetting.niaojimei == 1">尿激酶</td>
                  <td width="100" v-if="gatherSetting.putaosuangai == 1">葡萄糖酸钙</td>
                 
                </tr>
                </thead>
                <tbody>
                 <tr v-for="(item,i) in list" :key="i">
                   <td width="60" v-if="gatherSetting.index_number == 1">{{ i+1 }}</td>
                  <td width="100"  v-if="gatherSetting.name==1">
                    {{item.patient.name}}
                  </td>
                  <td width="100"  v-if="gatherSetting.dialysis_no==1">
                    {{item.patient.dialysis_no}}
                  </td>
                  <td width="100"  v-if="gatherSetting.admission_number==1">
                    {{item.xt_receive_treatment_asses.admission_number}}
                  </td>
                  <td width="100" v-if="gatherSetting.mode_type==1">
                    <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="gatherSetting.dialysis_dialyszers == 1">
                    {{item.dialysis_prescription.dialysis_dialyszers}}
                  </td>
                  <td width="100"  v-if="gatherSetting.dialysis_irrigation ==1">
                    <span>{{item.dialysis_prescription.dialysis_irrigation}}</span>
                  </td>
                  <td width="100"  v-if="gatherSetting.dialysis_irrigation ==1">
                    <span>{{item.dialysis_prescription.dialysis_strainer}}</span>
                  </td>
                  <td width="100"  v-if="gatherSetting.change_nurse ==1"> 
                    <span v-if="(getBloodAccessOption(item.dialysis_prescription.blood_access)).indexOf('导管')!=-1">1</span>
                    <span v-if="(getBloodAccessOption(item.dialysis_prescription.blood_access)).indexOf('导管')==-1">0</span>
                        /
                    <span v-if="(getBloodAccessOption(item.dialysis_prescription.blood_access)).indexOf('内瘘')==-1">0</span>
                    <span v-if="(getBloodAccessOption(item.dialysis_prescription.blood_access)).indexOf('内瘘')!=-1">1</span>
                  </td>
                  <td width="100" v-if="gatherSetting.anticoagulant==1">
                    <span>{{getAnticoagualnt(item.dialysis_prescription.anticoagulant)}}</span>
                    <span v-if="item.dialysis_prescription.anticoagulant_shouji > 0">({{item.dialysis_prescription.anticoagulant_shouji}})</span>
                    <span v-if="item.dialysis_prescription.anticoagulant_weichi > 0">({{item.dialysis_prescription.anticoagulant_weichi}})</span>
                    <span v-if="item.dialysis_prescription.anticoagulant_zongliang > 0">({{item.dialysis_prescription.anticoagulant_zongliang}})</span>
                 </td>
                  <td width="200" v-if="gatherSetting.tube==1">
                    <span v-if="getBloodAccessOption(item.dialysis_prescription.blood_access).indexOf('导管')!==-1">1</span>
                  </td>
                  <td width="100" v-if="gatherSetting.kalium==1">
                    <span v-if="item.dialysis_prescription.kalium>0">{{item.dialysis_prescription.kalium}}</span>
                 </td>
                  <td width="100"  v-if="gatherSetting.calcium==1">
                    <span v-if="item.dialysis_prescription.calcium>0">{{item.dialysis_prescription.calcium}}</span>
                 </td>
                  <td width="100" v-if="gatherSetting.cuhong == 1">
                    {{ item.advice_spc }}
                 </td>
                  <td width="100"  v-if="gatherSetting.zuoka == 1">
                    {{ item.advice_spc_one }}
                 </td>
                  <td width="100" v-if="gatherSetting.niaojimei == 1">
                    {{ item.advice_spc_two }}
                 </td>
                  <td width="100" v-if="gatherSetting.putaosuangai == 1">
                    {{ item.advice_spc_three }}
                 </td>
                 
                 </tr>
                </tbody>
              </table>
            
            </div>
          </div>
        </div>
      </div>
    </div>
  </template>
  
  <script>
    import { getDialysisGatherList } 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,
          org_id:'',
          gatherSetting:{}
        }
      },
      components: {
        BreadCrumb
      },
      created() {
        this.org_id = this.$store.getters.xt_user.org.id
        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)
        getDialysisGatherList(params).then(response=>{
            if(response.data.state == 1){
             this.gatherSetting = response.data.data.gatherSetting
              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 =""
                  list[i].advice_spc_one =""
                  list[i].advice_spc_two =""
                  list[i].advice_spc_three = ""
                   for(let j=0;j<list[i].advice.length;j++){
                       if((list[i].advice[j].advice_name).indexOf("促红")!=-1){
                          list[i].advice_spc+= (list[i].advice[j].single_dose + list[i].advice[j].single_dose_unit+"/"+ list[i].advice[j].prescribing_number_unit)+","
                       }

                       if((list[i].advice[j].advice_name).indexOf("左卡")!=-1){
                          list[i].advice_spc_one+= (list[i].advice[j].single_dose + list[i].advice[j].single_dose_unit+"/"+ list[i].advice[j].prescribing_number_unit)+","
                       }

                       if((list[i].advice[j].advice_name).indexOf("尿激酶")!=-1){
                          list[i].advice_spc_two+= (list[i].advice[j].single_dose + list[i].advice[j].single_dose_unit+"/"+ list[i].advice[j].prescribing_number_unit)+","
                       }

                       if((list[i].advice[j].advice_name).indexOf("葡萄糖酸钙")!=-1){
                          list[i].advice_spc_three+= (list[i].advice[j].single_dose + list[i].advice[j].single_dose_unit+"/"+ list[i].advice[j].prescribing_number_unit)+","
                       }

                   }
                }
              this.list = list
            
            }
        }) 
       },
       getTimeOne(val) {
          if(val == ""){
          return ""
          }else {
          return uParseTime(val, '{y}-{m}-{d}')
          }
       },
        printAction: function() {
          if(this.org_id != 10490 && this.org_id != 0){
            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
            })
          }else{
            // 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; } }'
            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
            })
          }
          
        },
        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>
  
  