<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">{{day}}排班提醒</span>
          </div>
          <div class="table_panel">
            <table class="table">
              <thead>
                <tr>
                  <!-- <td :width="td_1_width">姓名</td>
                  <td :width="td_1_width">分区</td>
                  <td :width="td_1_width">班次</td>
                  <td :width="td_1_width">机号</td>
                  <td :width="td_1_width">透析模式</td>
                  <td :width="td_2_width">透析器</td>
                  <td :width="td_2_width">抗凝剂</td>
                  <td :width="td_2_width">低分子肝素</td>
                  <td :width="td_4_width">长期医嘱</td> -->
                  <td width="100">姓名</td>
                  <td width="70">分区</td>
                  <td width="70">班次</td>
                  <td width="70">机号</td>
                  <td width="120">透析模式</td>
                  <td width="100">透析器</td>
                  <td width="120">抗凝剂</td>
                  <td width="100">总量</td>
                  <td width="300">长期医嘱</td>
                </tr>
              </thead>
              <tbody>
              <tr v-for="(main_collection, index) in scheduleData" :key="index">
                <td :width="td_1_width">{{ main_collection.patient}}</td>
                <td :width="td_1_width">{{ main_collection.zone.name }}</td>
                <td :width="td_1_width">
                  {{getSchedulesType(main_collection.schedule_type)}}
                </td>
                <td :width="td_1_width">
                  {{main_collection.number.number}}

                </td>
                <td :width="td_1_width">
                  {{modeOptions[main_collection.mode_id].name}}
                </td>
                <td :width="td_1_width">
                  {{main_collection.prescription.dialyzer_perfusion_apparatus}}


                </td>
                <td :width="td_1_width">
                  {{ main_collection.prescription.anticoagulant ? anticoagulants_confit[main_collection.prescription.anticoagulant].name : ''}}

                </td>
                <td :width="td_1_width">
                  <span v-if="main_collection.prescription.anticoagulant == 1">{{main_collection.prescription.anticoagulant_zongliang?main_collection.prescription.anticoagulant_zongliang+'mg':''}}</span>
                  <span v-if="main_collection.prescription.anticoagulant == 2">{{main_collection.prescription.anticoagulant_zongliang?main_collection.prescription.anticoagulant_zongliang+'iu':''}}</span>
                  <span v-if="main_collection.prescription.anticoagulant == 3">{{main_collection.prescription.anticoagulant_zongliang?main_collection.prescription.anticoagulant_zongliang+'iu':''}}</span>
                  <span v-if="main_collection.prescription.anticoagulant == 4">{{main_collection.prescription.anticoagulant_zongliang?main_collection.prescription.anticoagulant_zongliang+'mg':''}}</span>
                </td>
                <td :width="td_4_width" >
                  <span style="white-space: pre">{{getAdvice(main_collection.doctor_advice)}}</span>
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { getScheduleWeekDay } from '@/api/schedule'
  import { parseTime } from '@/utils'
  import BreadCrumb from '@/xt_pages/components/bread-crumb'
  import print from 'print-js'

  export default {
    name: 'SchedulePrint',
    data() {
      return {
        crumbs: [
          { path: false, name: '排班提醒' },
          { path: false, name: '排班提醒打印' }
        ],
        scheduleData:[],
        week_type: 0,
        day:'',
        td_1_width: '10%',
        td_2_width: '10%',
        td_3_width: '25%',
        td_4_width: '45%',
        modeOptions: null,
        anticoagulants_confit:null,
      }
    },
    components: {
      BreadCrumb
    },
    created() {

      this.modeOptions = this.$store.getters.treatment_mode
      this.anticoagulants_confit = this.$store.getters.anticoagulants_confit
      this.week_type = this.$route.query.week_type



      getScheduleWeekDay({week_type: this.week_type}).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
          this.scheduleData = resp.data.schdules
        } else {
          this.$message.error(resp.msg)
        }
      }).catch(err => {
        this.$message.error(err)
      })
    },
    methods: {
      getAdvice:function(doctor_advice) {
        console.log(doctor_advice)

        let name = ""
        for (let i = 0; i< doctor_advice.length; i++){

          let prescribing_number = ''
          let single_dose = ''
          let drug_spec = ''

          if (doctor_advice[i].prescribing_number > 0) {
            prescribing_number = doctor_advice[i].prescribing_number + doctor_advice[i].prescribing_number_unit
          }
          if (doctor_advice[i].single_dose > 0) {
            single_dose = ' 单次用量 ' + doctor_advice[i].single_dose + doctor_advice[i].single_dose_unit
          }

          if (doctor_advice[i].drug_spec > 0) {
            drug_spec =  doctor_advice[i].drug_spec + doctor_advice[i].drug_spec_unit
          }


          name = name + doctor_advice[i].advice_name +" "+ drug_spec+" "+ prescribing_number + " "+single_dose+" " + doctor_advice[i].delivery_way+" "+ doctor_advice[i].execution_frequency +" " + doctor_advice[i].remark +"\n"

          // if (doctor_advice[i].child.length > 0){
          //   for (let a = 0 ; a < doctor_advice[a].child.length; a++){
          //     if(doctor_advice[i].child[a].prescribing_number > 0){
          //       doctor_advice[i].child[a]['presc'] = doctor_advice[i].child[a].prescribing_number + doctor_advice[i].child[a].prescribing_number_unit
          //     }else{
          //       doctor_advice[i].child[a]['presc'] = ''
          //     }
          //
          //     if(doctor_advice[i].child[a].single_dose > 0){
          //       doctor_advice[i].child[a]['single'] = " "+' 单次用量 '+" "+doctor_advice[i].child[a].single_dose + doctor_advice[i].child[a].single_dose_unit
          //     }else{
          //       doctor_advice[i].child[a]['single'] = ''
          //     }
          //     name = name+"▲"+doctor_advice[i].child[a].advice_name+""
          //       + doctor_advice[i].child[a].advice_desc
          //       + doctor_advice[i].child[a].drug_spec_unit
          //       + doctor_advice[i].child[a].presc
          //       + doctor_advice[i].child[a].single
          //
          //
          //   }
          //   return  doctor_advice[i].advice_name +"  "+ doctor_advice[i].advice_desc+" "
          //     + doctor_advice[i].drug_spec_unit
          //     + prescribing_number
          //     + " "+single_dose+" "+ " "+doctor_advice[i].delivery_way+" "+ doctor_advice[i].execution_frequency + doctor_advice[i].remark +name
          //
          // }else{
          //
          //
          //
          // }


        }
        return name

      },
      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
        })
      }, getSchedulesType: function(type) {
        let type_name = ''
        switch (type) {
          case 1:
            type_name = '上午'
            break
          case 2:
            type_name = '下午'
            break
          case 3:
            type_name = '晚上'
            break
        }
        return type_name
      }
    }
  }
</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>
