<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>印单日期：{{print_date}}</p>
                    </div>
                    <div class="table_panel">
                        <table class="table">
                            <thead>
                                <tr>
                                    <td>姓名</td>
                                    <td>透析模式</td>
                                    <td width="120" v-for="(item,index) in tableName" :key="index">
                                       {{item.type_name}}
                                    </td>
                                    <td>
                                      抗凝剂(首剂)(维持)(总量)
                                    </td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr v-for="(it,i) in tableData" :key="i">
                                    <td>{{it.patient.name}}</td>
                                    <td>{{it.treatment_mode.name}}</td>
                                    <td v-for="(item,index) in tableName" :key="index"
                                     >{{getCount(it.patient.id,item.good_id)}}
                                    </td>
                                    <td>
                                     <span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 0"></span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 1">无肝素</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 2">普通肝素</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 3">低分子肝素</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 4">阿加曲班</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 5">枸橼酸钠</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 6">低分子肝素钙</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 7">低分子肝素钠</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 8">依诺肝素</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 9">达肝素</span>
                                        <span v-if="getAnticoagulant(it.patient.id) == 10">体外抗凝</span>
                                    </span>
                                    <span>
                                    {{getAnticoagulantShouji(it.patient.id)?getAnticoagulantShouji(it.patient.id):''}}
                                    <span v-if="getAnticoagulant(it.patient.id) == 1 && getAnticoagulantShouji(it.patient.id)!=''">mg</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 2  && getAnticoagulantShouji(it.patient.id)!=''">iu/h</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 3  && getAnticoagulantShouji(it.patient.id)!=''">iu</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 4  && getAnticoagulantShouji(it.patient.id)!=''">mg</span>
                                    <span v-if="getAnticoagulant(it.patient.id)== 5  && getAnticoagulantShouji(it.patient.id)!=''">mg</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 6  && getAnticoagulantShouji(it.patient.id)!=''">iu</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 7  && getAnticoagulantShouji(it.patient.id)!=''">iu</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 8  && getAnticoagulantShouji(it.patient.id)!=''">iu</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 9  &&getAnticoagulantShouji(it.patient.id)!=''">iu</span>
                                    <span v-if="getAnticoagulant(it.patient.id) == 10 && getAnticoagulantShouji(it.patient.id)!=''">mg</span>
                                   </span>
                                    <span>
                                      {{getAnticoagulantWeichi(it.patient.id)?getAnticoagulantWeichi(it.patient.id):''}}
                                      <span v-if="getAnticoagulant(it.patient.id) == 1 && getAnticoagulantWeichi(it.patient.id)!=''">mg/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 2 && getAnticoagulantWeichi(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 3 && getAnticoagulantWeichi(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 4 && getAnticoagulantWeichi(it.patient.id)!=''">mg/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 5 && getAnticoagulantWeichi(it.patient.id)!=''">ml/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 6 && getAnticoagulantWeichi(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 7 && getAnticoagulantWeichi(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 8 && getAnticoagulantWeichi(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 9 && getAnticoagulantWeichi(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 10 && getAnticoagulantWeichi(it.patient.id)!=''">mg</span>
                                    </span>
                                    <span>
                                        {{getAnticoagulantZongliang(it.patient.id)?getAnticoagulantZongliang(it.patient.id):''}}
                                      <span v-if="getAnticoagulant(it.patient.id) == 1 && getAnticoagulantZongliang(it.patient.id)!=''">mg</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 2 && getAnticoagulantZongliang(it.patient.id)!=''">iu</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 3 && getAnticoagulantZongliang(it.patient.id)!=''">iu</span>
                                      <span v-if="getAnticoagulant(it.patient.id)== 4 && getAnticoagulantZongliang(it.patient.id)!=''">mg</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 5 && getAnticoagulantZongliang(it.patient.id)!=''">mg</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 6 && getAnticoagulantZongliang(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 7 && getAnticoagulantZongliang(it.patient.id)!=''">iu</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 8 && getAnticoagulantZongliang(it.patient.id)!=''">iu</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 9 && getAnticoagulantZongliang(it.patient.id)!=''">iu/h</span>
                                      <span v-if="getAnticoagulant(it.patient.id) == 10 && getAnticoagulantZongliang(it.patient.id)!=''">mg</span>
                                    </span>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import print from 'print-js'
import {getBatchCollection,getAllMaterial} from "@/api/consumable"
const moment = require('moment')
export default {
    components:{
        BreadCrumb
    },
    data(){
        return{
            crumbs: [
                { path: false, name: '耗材药品' },
                { path: false, name: '汇总打印' }
            ],
            tableName:[],
            consuMables:[],
            tableData:[],
            print_date:"",
            start_time:"",
            prescriptionList:[],
            reduceList:[],
        }
    },
    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
            })
        },
         getAllMaterial(){
          var startime  = moment(new Date()).add('year',0).format("YYYY-MM-DD")
          this.start_time = startime
           const params = {
              startime:this.start_time
           }
          getAllMaterial(params).then(response=>{
             if(response.data.state == 1){
               var material =  response.data.data.material
               this.tableName = material
             }
          })
        },
        getCount(patientid,goodid){
           var count = 0
           for(let i=0;i<this.reduceList.length;i++){
              if(patientid == this.reduceList[i].patient_id && goodid == this.reduceList[i].good_id){
                 count = this.reduceList[i].count
              }
           }
           return count
        },
     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 startime  = moment(new Date()).add('year',0).format("YYYY-MM-DD")
      this.print_date = startime
        //获取今日所有耗材
      this.getAllMaterial()
    },
    mounted(){
      var ids = this.$store.getters.temp_params.batch_print_dialysis_record_ids
       var start = this.$route.query.start
      this.start_time = start
      const params = {
         startime:this.start_time,
         ids:ids.join(',')
      }
      //获取汇总打印
      getBatchCollection(params).then(response=>{
         if(response.data.state == 1){
            var schedule = response.data.data.schedule
            this.tableData = schedule
           var consumables = response.data.data.consumables
           this.consuMables = consumables
           var prescripiton = response.data.data.prescripiton
           this.prescriptionList = prescripiton
           var reducelist = response.data.data.reducelist
           this.reduceList = reducelist
         }
      })
    }
   
}
</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: 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>
