<template>
  <div class="main-contain">

    <div class="position">
      <bread-crumb :crumbs='crumbs'></bread-crumb>
      <el-button :loading="loading" size="small" icon="el-icon-printer" @click="printAction" type="primary">打印
      </el-button>
    </div>
    <div class="app-container">
      <div id="print_content">
        <div class="print_page_main_content">
          <div class="order-yy-name">{{orgname}}</div>
          <div class="order_title" style="padding-top:12px;"> 病程记录</div>
          <div class="row" style="border-bottom:1px solid #000; display: flex;padding-bottom: 10px;padding-top: 12px;">

            <div  style="flex:1;text-align: center;">
              姓名：
              <div  style="width: 120px;text-align: left;display:inline-block;">{{patient.name }}</div>
            </div>

            <div style="flex:1;text-align: center;">
              科别：
              <div  style="width: 120px;text-align: left;display:inline-block;">{{"血透中心"}}</div>
            </div>

            <div style="flex:1;text-align: center;" v-if="org_id == 9671 || org_id == 10215" >
              病案号：
              <div  style="width: 120px;text-align: left;display:inline-block;">
                {{patient.dialysis_no?patient.dialysis_no:"/"}}
              </div>
            </div>


            <div style="flex:1;text-align: center;" v-if="org_id!=10215 && org_id!=9671" >
              透析号：
              <div  style="width: 120px;text-align: left;display:inline-block;">
                {{patient.dialysis_no?patient.dialysis_no:"/"}}
              </div>
            </div>

            <div  style="flex:1;text-align: center;" v-if="org_id!=10215 && org_id!=9671">
              住院号：
              <div style="width: 100px;text-align: left;display:inline-block;">
                {{patient.admission_number?patient.admission_number:"/"}}
              </div>

            </div>

          </div>
          <div class="row" style="padding: 2px 0;line-height:24px;margin-top:10px;" v-for="(item,index) in this.record" :key="index">
            <div class="inline_block">
              <div>{{getTime(item.record_time,'{y}-{m}-{d} {h}:{i}')}}</div>
            </div>
            <div class="inline_block" style="margin-left: 30px">
              <div>{{item.title}}</div>
            </div>

            <div class="inline_block" style="width:100%; word-wrap: break-word; word-break: break-all;">
              <div v-html="item.content" class="printP">

              </div>
            </div>

            <div class="row" style="padding: 2px 0;line-height:24px;margin-top:10px;float:right" v-if="org_id == 0||org_id ==9671 || org_id == 10440 || org_id == 10131 || org_id==9970">
             医生签名：
             <span v-if="setAdminUserES(item.recorder?item.recorder:item.recorder) == ''">
                  {{getName(item.recorder)}}
             </span>
              <span v-else>
                <img style="height:30px;" :src="setAdminUserES(item.recorder?item.recorder:item.recorder)" alt="" srcset="">
              </span>
            </div>
          </div>

        
        </div>
      </div>
    </div>
  </div>

</template>


<script>
  import { jsGetAge, uParseTime } from '@/utils/tools'
  import BreadCrumb from '@/xt_pages/components/bread-crumb'
  import { GetCoursePrintData } from '@/api/patient'

  export default {
    name: 'coursePrint',
    components: {
      BreadCrumb
    },
    data() {
      return {
        crumbs: [
          { path: false, name: '病人管理' },
          { path: false, name: '病程打印' }
        ],

        loading: false,
        orgname: '',
        record:[],
        patient: {},
        org_id:0,
        adminUserList:[],
        operators:[],
        operatorMaps: {},
      }
    },
    created() {
      var xtuser = this.$store.getters.xt_user
      this.org_id = this.$store.getters.xt_user.org_id

      this.orgname = xtuser.org.org_name

    },
    mounted() {
      this.loading = true
      var ids = this.$route.query.ids
      var patient_id = parseInt(this.$route.query.patient_id)
      var params = {
        ids:ids,
        patient_id:patient_id,
      }

      GetCoursePrintData(params).then(rs => {
        var resp = rs.data
        if (resp.state == 1) {
          this.record = resp.data.record

          this.patient = resp.data.patient
         
          this.adminUserList = resp.data.adminUser
          this.operators = resp.data.operators
           console.log("GetCoursePrintData",this.operators)
           if (this.operators.length > 0) {
            var operatorsLen = this.operators.length
            for (var index = 0; index < operatorsLen; index++) {
              this.$set(
                this.operatorMaps,
                this.operators[index].creator,
                this.operators[index]
              )
            }
          }
          console.log("operatorMaps",this.operatorMaps)
          this.loading = false
        } else {
          this.loading = false
          this.$message.error(resp.msg)
        }
      }).catch(err => {
        this.$message.error(err)
      })
    },
    methods: {
      printAction: function() {
      const style = '@media print {.printP div{margin-bottom:5px;} .option_panel { margin: 0 5px 0 0; } .option_panel .check_box_panel { white-space: nowrap; outline: none; display: inline-block; line-height: 1; position: relative; vertical-align: middle; } .dialysis-print-order .order-title{margin:auto;font-weight:600;text-align:center;font-size:22px;padding:10px}.option_panel .check_box_panel .check_box { display: inline-block; position: relative; border: 1px solid #000; box-sizing: border-box; width: 14px; height: 12px; background-color: #fff; } .check_box_panel .did_checked::after { content: "√"; font-size: 15px; } .print_page_main_content {background-color: white;width: 960px;margin: 0 auto 50px;padding: 0 0 0 0; page-break-after: always;}.print_page_main_content .order-yy-name {margin: auto;text-align: center;font-size: 20px;letter-spacing: 5px;}.print_page_main_content .order_title {text-align: center;font-size: 23px; line-height: 50px;font-weight: 500;} .row {font-size: 20px;line-height: 20px;padding: 5px 0;}.inline_block { display: inline-block;}.under_line_two {display: inline-block;border-bottom: 1px solid #999;text-align: left;white-space: nowrap;width: 50%;}.under_line {display: inline-block;border-bottom: 1px solid #999;text-align: center;white-space: nowrap; width: 50%;}.flex {display: -webkit-box;display: -moz-box; display: -ms-flexbox; display: -webkit-flex;display: flex;align-items: center;-webkit-align-items: center;box-align: center;-moz-box-align: center;-webkit-box-align: center;text-align: center;-webkit-justify-content: space-between;justify-content: space-between;-moz-box-pack: space-between;-webkit--moz-box-pack: space-between;box-pack: space-between;}.print_page_main_content .proj_table {width: 100%;border: 1px solid;border-collapse: collapse;padding: 2px;}.print_page_main_content .proj_table tbody tr td {border: 1px solid;font-size: 16px;padding: 5px 8px;line-height: 30px;}.print_page_main_content .proj_table .inside_table {width: 100%;border: hidden; border-collapse: collapse;}.print_page_main_content .proj_table .inside_table tr td {border: 1px solid; text-align: center;font-size: 14px;padding: 6px 5px;line-height: 16px;}.print-table-no {width: 100%;text-align: center;border-collapse: collapse;font-size: 14px;}.es-img {height: 30px;}.advice-name {text-align: left !important;line-height: 16px !important;}.advice-children {display: flex;}}.margin-bottom-300 {margin-bottom:450px;}.margin-bottom-600 {margin-bottom:600px;}.margin-bottom-900 {margin-bottom:1000px;}.print-yema{ position: absolute;top: 920px;left: 50%;} .print-yema2{ position: absolute;top: 400px;left: 50%;}.print-yema3{position: absolute;top: 1230px;left: 50%;}.print-yema4{position: absolute;top:1050px;left: 50%;}.print-yema5{position: absolute;top:1370px;left: 50%;}.check_box{width:15px !important;height:15px !important;}.did_checke::after {font-size: 8px;margin-left: 2px;margin-top: 12px !important;position: absolute;}'
      printJS({
        printable: 'print_content',
        type: 'html',
        documentTitle: '  ',
        style: style,
        scanStyles: false
      })
    },
      getTime(value, temp) {
        if (value != undefined) {
          return uParseTime(value, temp)
        }
        return ''
      },
      getName(admin_user_id){
        var name = ""
        for(let i=0;i<this.adminUserList.length;i++){
          if(this.adminUserList[i].id == admin_user_id){
            name = this.adminUserList[i].name
          }
        }
        return name
      },
       setAdminUserES(id) {
        
        if (id === 0) {
          return ''
        }
        if (id in this.operatorMaps) {
          
          return this.operatorMaps[id].url
         
        } else {
          return ''
        }
        
       },
    }
  }
</script>

<style scoped>
  .print_page_main_content {
    background-color: white;
    width: 960px;
    margin: 0 auto 50px;
    padding: 0 0 0 0;
    page-break-after: always;
  }

  .print_page_main_content .order-yy-name {
    margin: auto;
    text-align: center;
    font-size: 20px;
    letter-spacing: 5px;
  }

  .print_page_main_content .order_title {
    text-align: center;
    font-size: 23px;
    line-height: 40px;
    font-weight: 500;
  }

  .row {
    font-size: 14px;
    line-height: 20px;
    padding: 5px 0;
  }

  .inline_block {
    display: inline-block;
  }

  .under_line {
    display: inline-block;
    border-bottom: 1px solid #999;
    text-align: center;
    white-space: nowrap;
    width: 50%;
  }

  .under_line::before {
    content: "\00A0";
  }

  .under_line::after {
    content: "\00A0";
  }

  .under_line_two {
    display: inline-block;
    border-bottom: 1px solid #999;
    text-align: left;
    white-space: nowrap;
    width: 50%;
  }

  .under_line_two::before {
    content: "\00A0";
  }

  .under_line_two::after {
    content: "\00A0";
  }

  .flex {
    display: -webkit-box;
    display: -moz-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    align-items: center;
    -webkit-align-items: center;
    box-align: center;
    -moz-box-align: center;
    -webkit-box-align: center;
    text-align: center;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    -moz-box-pack: space-between;
    -webkit--moz-box-pack: space-between;
    box-pack: space-between;
  }

  .print_page_main_content .proj_table {
    width: 100%;
    border: 1px solid;
    border-collapse: collapse;
    padding: 2px;
  }

  .print_page_main_content .proj_table tbody tr td {
    border: 1px solid;
    /* text-align: center; */
    font-size: 16px;
    padding: 6px 8px;
    line-height: 30px;
  }

  .print_page_main_content .proj_table .inside_table {
    width: 100%;
    border: hidden; /* 解决边框冲突 */
    border-collapse: collapse;
  }

  .print_page_main_content .proj_table .inside_table tr td {
    border: 1px solid;
    text-align: center;
    font-size: 14px;
    padding: 8px 5px;
    line-height: 16px;
  }

  .print-table-no {
    width: 100%;
    text-align: center;
    border-collapse: collapse;
    font-size: 14px;
  }

  .es-img {
    height: 30px;
  }

  .advice-name {
    text-align: left !important;
    line-height: 16px !important;
  }

  .advice-children {
    display: flex;
  }
  .margin-bottom-300 {
    margin-bottom:450px;
  }
  .margin-bottom-600 {
    margin-bottom:600px;
  }
  .margin-bottom-900 {
    margin-bottom:900px;
  }
  .print-yema{
    position: absolute;
    left: 50%;
  }
  .print-yema2{
    position: absolute;
    left: 50%;
  }
  .print-yema3{
    position: absolute;
    left: 50%;
  }
  .print-yema4{
    position: absolute;
    left: 50%;
  }
  .print-yema5{
    position: absolute;
    left: 50%;
  }
  .did_checke::after {content: "\221A";font-size: 8px;margin-left: 2px;margin-top: 2px;position: absolute;}
  .printP{
    line-height: 20px;
    font-weight: bold;
  }
</style>



