<template>
<div>
  <div style="float:right">
    <el-button type="primary" size="small" @click="printThisPage">打印</el-button> 
  </div>
  <div id="dialysis-print-box">
    <div class="dialysis-print-order">
      <div class="order-yy-name"></div>
      <div class="order-title">{{ orgname }}血液透析患者诊疗阶段小结</div>
      
      <div style="padding-bottom:20px;border-bottom:1px solid #000;margin-top:40px;">
         <span>姓名:{{patientList.patient.name}}</span>  
         <span style="margin-left:20px;">年龄:{{getNewAge(patientList.patient.id_card_no)}}</span>  
         <span style="margin-left:20px;">性别:
             <span v-if="patientList.patient.gender == 1">男</span>
             <span v-if="patientList.patient.gender == 2">女</span>
         </span> 
         <span style="margin-left:20px;">诊断:{{patientList.patient.diagnose}}</span> 
      </div>
      <div style="padding:20px 0;border-bottom:1px solid #000;font-weight:bold;">
        <span>阶段评估时间:{{getTime(patientList.record_time)}}</span>  
      </div>
       <!-- <div style="padding:20px 0;border-bottom:1px solid #000;">
        <span style="font-weight:bold;">阶段小结概要:</span>  
        <div style="margin-top:20px;">
          <div style="display:flex;justify-content: space-between;">
            <span>干体重(kg):{{patientList.dry_weight}}</span>  
            <span>共透析:{{patientList.dialysis_count}}次</span>  
            <span>HD:{{patientList.hd_count}}次</span>  
            <span>HDF:{{patientList.hdf_count}}次</span>  
            <span>HP:{{patientList.hp_count}}次</span>  
            <span>其他:{{patientList.other_count}}次</span> 
          </div>
          <div style="display:flex;justify-content: space-between;margin-top:10px;">
            <span>透析器:{{patientList.dialzer_apparatus}}</span>  
            <span>灌流器:{{patientList.perfusion_apparatus}}</span> 
            <span>抗凝剂:{{getAnticoagulant(patientList.anticoagulant)}}</span>  
            <span>透析液(钾:{{patientList.kalium}} 钙:{{patientList.autunite}} Na:{{patientList.natrium}} ):</span> 
            <span>每次透析(小时):{{patientList.hour}}时{{patientList.minute}} <span v-if="patientList.minute!=''">分</span></span>
          </div>
          <div style="display:flex;justify-content: space-between;margin-top:10px;">
            <span>透前体重(kg):{{patientList.befor_weight}}</span>
            <span>透后体重(kg):{{patientList.after_weight}}</span>
            <span>透前血压(mmHg):{{patientList.befor_pressure}}</span>
            <span>透后血压(mmHg):{{patientList.after_pressure}}</span>
          </div>
        </div>
      </div> -->
      <div style="padding:20px 0;border-bottom:1px solid #000;min-height:200px;">
        <span style="font-weight:bold;">阶段小结总结:</span>
          <!-- {{patientList.template_summary_content}} -->
          <div style="line-height:24px;" v-html="patientList.template_summary_content"></div>
      </div>
     <div style="padding:20px 0;border-bottom:1px solid #000;min-height:250px;">
        <span style="font-weight:bold;">阶段小结化验结果:</span>
        <div class="borderBox">
          <div v-for="item in patientList.template_inspection_content">
            <p>{{ item.project_name }} 检查日期:{{getTime(item.arr[0].inspect_date)}}</p>
            <div style="display:flex;flex-wrap: wrap;">
              <div v-for="it in item.arr" style="width:33%;margin-bottom:10px;">
                {{ it.item_name }} <span v-if="it.unit!=''"> [{{it.unit}}] </span>:
                 {{it.inspect_value}}
                <span v-if="parseInt(it.inspect_value) < parseInt(it.range_min)">
                 ↓
                </span> 
                <span v-if="parseInt(it.inspect_value) > parseInt(it.range_max)">
                  ↑
                </span> 
              </div>
            </div>
          </div>
        </div> 
      </div>
      <!-- <div style="padding:20px 0;border-bottom:1px solid #000;min-height:200px;">
        <span style="font-weight:bold;">阶段小结个性化方案:</span>
      
         <div v-html="patientList.template_plan_content"></div>
      </div> -->
     <div style="margin-top:10px;">
       <span>记录医生:{{getPatientList(patientList.admin_user_id)}}</span>  
       <span style="margin-left:20px;">记录时间:{{getTime(patientList.record_time)}}</span>  
     </div>
    </div>
  </div>
</div>
</template>

<script>
import { getDataConfig } from '@/utils/data'
import { jsGetAge, uParseTime } from '@/utils/tools'
import LabelBox from '../dialysis/printItem/LabelBox'
import CheckBox from '../dialysis/batch_print/option_check_box'
import BreadCrumb from '@/xt_pages/components/bread-crumb'
import {getTemplateSummaryPrintDetail} from "@/api/patient"
export default {
  name: 'dialysisPrintOrderOne',
  components: {
    LabelBox,
    BreadCrumb,
    CheckBox
  },
  data() {
    return {
      crumbs: [
        { path: false, name: '透析管理' },
        { path: false, name: '打印单' }
      ],
      operators: [],
      adminUser: [],
      check: {},
      dialysisOrder: {
        DeviceNumber: []
      },
      posture_arr: [],
      operatorMaps: {},
      complications: [
        '低血压',
        '高血压',
        '心律失常',
        '头晕',
        '头痛',
        '呕吐',
        '抽搐',
        '出血',
        '心衰',
        '腹痛',
        '无'
      ],
      consciousness_arr: [],
      jilurow: 0,
      advice_jilurow: 0,
      loading: false,
      orgname: '',
      patientInfo_gender_1: false,
      patientInfo_gender_2: false,
      patientInfo_source_2: false,
      patientInfo_source_1: false,
      modeOptions: {},
      replacementWays: [],
      perfusionApparatus: [],
      anticoagulantsConfit: {},
      bloodAccessParOpera: {},
      dialysateFormulationOptions: {},

      queryParams: {
        xtdate: '',
        xtno: ''
      },
      patientInfo: {
        birth: '',
        age: '',
        DialysisSchedule: {
          device_number: { number: '' },
          device_zone: { name: '' }
        },
        gender: 0
      },
      predialysis: {
        score: '',
        internal_fistula: '',
        internal_fistula_skin: '',
        catheter: '',
        blood_access_part_opera_name: ''
      },
      afterdialysis: {
        complications_index: ''
      },
      prescription: {
        dialysate_formulation_name: '',
        device: {}
      },
      advices: [],
      users: [],
      monitors: [],
      summary: {},
      receiverTreatmentAccess: {},
      org_template_info: {},

      doctor_advices: [],
      advice_groups: [],
      schedule: [],

      AlPanel: {
        id: 0,
        name: '',
        type: 1,
        shouji: 2,
        weichi: 2,
        zongliang: 2,
        gaimingcheng: -1,
        gaijiliang: -1,
        shouji_unit: 'mg',
        weichi_unit: 'mg/h',
        zongliang_unit: 'mg',
        gaimingcheng_unit: '',
        gaijiliang_unit: ''
      },
      list: 5,
      replacement_total: '',
      actual_treatment_hour: '',
      actual_treatment_minute: '',
      anticoagulant: '',
      anticoagulant_shouji: '',
      anticoagulant_zongliang: '',
      prescription_dewatering: '',
      blood_flow_volume: '',
      dialysate_flow: '',
      bed: '',
      dialyzer_perfusion_apparatus: '',
      dialysate_formulation: '',
      blood_access: '',
      doctor: '',
      nurse: '',
      doctorAdvice: [],
      total: '',
      weight_before: '',
      dry_weight: '',
      weight_after: '',
      weightloss_after: '',
      actual_ultrafiltration: '',
      temperature: '',
      systolic_blood_pressure: '',
      diastolic_blood_pressure: '',
      mission: '',
      dialysis_summary: '',
      orderForm: {
        start_nurse: '',
        url: ''
      },
      doctorForm: {
        doctor: '',
        url: ''
      },
      finshForm: {
        finish_nurse: '',
        url: ''
      },
      tableAdvice: [],
      monitor: [],
      displace_liqui: '',
      kalium: '',
      sodium: '',
      calcium: '',
      weight_gain: '',
      afterWeightLast: '',
      anticoagulant_weichi: '',
      target_ultrafiltration: '',
      blood_access_internal_fistula: '',
      venous_catheterization: '',
      blood_access_part_opera_id: '',
      dryWeight_add: '',
      weight: '',
      vascularId: 0,
      PunctureNurse: {
        user_name: '',
        url: ''
      },
      arr: [],
      arrtwo: [],
      bloodAccess: [],
      vascularAccess: [],
      nursing_record: '',
      special_record: '',
      newTableAdvice: [],
      patientList:{},
      doctorList:[],
      anticoagulantList:[],
    }
  },
  methods: {
    getDatge(value) {
      var times = Date.parse(value) / 1000
      var timestr = uParseTime(times, '{y}年{m}月{d}日')
      return timestr
    },
    getTime(value, temp) {
      if (value == 0) {
        return ''
      }
      if (value != undefined) {
        return uParseTime(value, temp)
      }
      return ''
    },
    getTimes(time) {
      if (time === '') {
        return ''
      }
      return uParseTime(time, '{y}-{m}-{d} {h}:{i}')
    },
    printThisPage() {
        var ptime = Math.round(new Date().getTime() / 1000)
        this.print_time = uParseTime(ptime, '{y}-{m}-{d} {h}:{i}')
        const style ='@media print {.dialysis-print-order{width:960px;margin:0 auto;letter-spacing:5px} .dialysis-print-order p{margin:0 auto}.dialysis-print-order .order-yy-name{margin:auto;text-align:center;font-size:20px;letter-spacing:5px}.dialysis-print-order .order-title{margin:auto;font-weight:600;text-align:center;font-size:22px;padding:10px 20px 20px 20px}.dialysis-print-order .table-box{width:100%;line-height:23px;font-size:14px}.dialysis-print-order .print-table{width:100%;text-align:center;border-collapse:collapse;line-height:25px;font-size:14px}.dialysis-print-order .print-table-no{width:100%;text-align:center;border-collapse:collapse;font-size:14px}.dialysis-print-order .under-line{border-bottom:1px solid #999;width:95%;text-align:center;margin-left:2px}.dialysis-print-order .title-box{text-align:center;font-size:16px;border:1px solid #666}.dialysis-print-order .radio-lebel-box{font-weight:400;cursor:pointer}.dialysis-print-order .radio-no{opacity:0;outline:0;position:absolute;margin:0;width:0;height:0;z-index:-1}.dialysis-print-order .radio-inner{white-space:nowrap;cursor:pointer;outline:0;display:inline-block;line-height:1;position:relative;vertical-align:middle}.dialysis-print-order .radio-fang{display:inline-block;position:relative;border:1px solid #000;box-sizing:border-box;width:14px;height:14px;background-color:#fff;z-index:1;transition:border-color .25s cubic-bezier(.71,-.46,.29,1.46),background-color .25s cubic-bezier(.71,-.46,.29,1.46)}.dialysis-print-order .is-checked-radio::after{content:"√";font-size:15px}}.dialysis-print-order .print-table-no tr td { padding: 8px 5px; line-height: 25px; }.es-img{height: 20px; }.advice-name{text-align: left;}.advice-children{display:flex;} .dialysis-print-order .print-table tr td{padding: 0px 0px;} .print-template-two tr {line-height: 30px;}   .title-box-pro{border: 0 #fff;line-height: 40px;height: 40px;text-align: left;padding-left: 10px !important;}  .text-align-left{text-align: left !important;padding-left:10px !important;font-size: 14px !important;line-height: 25px;font-weight: bold;margin: 10px 0;}'
        printJS({
            printable: 'dialysis-print-box',
            type: 'html',
            style: style,
            scanStyles: false
        })
      
    },
  

   
  
   
  
    getAge: function(val) {
      if (val.birthday != 0) {
        return jsGetAge(val.birth, '-')
      } else {
        return ''
      }
    },
    getTemplateSummaryPrintDetail(id){
       var params ={
         id:id,
       } 
     getTemplateSummaryPrintDetail(params).then(response=>{
        if(response.data.state == 1){
          var list = response.data.data.list
          console.log("listw23222323",list)
          // let arr = JSON.parse(list.template_inspection_content)
          // list.template_inspection_content = arr
          var inspectlist = response.data.data.inspectlist
          let arr = this.unique(inspectlist,'project_name')
          list.template_inspection_content = arr
          this.patientList = list
          var doctorList = response.data.data.doctorList
          console.log("doctorlsit",doctorList)
          this.doctorList = doctorList
        }
     }) 
    },
    getNewAge(UUserCard) {
      if (UUserCard != null && UUserCard != '') {
        // 获取年龄
        var myDate = new Date()
        var month = myDate.getMonth() + 1
        var day = myDate.getDate()
        var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1
        if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
          age++
        }
        return age
      }
    },
   getTime(val) {
     if(val < 0){
        return ""
     }
     if(val == ""){
        return ""
     }else {
        return uParseTime(val, '{y}-{m}-{d}')
     }
    },
    getPatientList(id){
      var name = ""
      for(let i=0;i<this.doctorList.length;i++){
         if(id == this.doctorList[i].admin_user_id){
            name = this.doctorList[i].user_name
         }
      }
      return name
    },
   unique(data, key) {
        let lastData = [];
        data.forEach(item => {
          let status = lastData.some(project_name => project_name[key] == item[key]);
          console.log('status',status)
          if (!status) {
            // item.value0 = item.value;
            let obj = {
              project_name:'',
              arr:[]
            }
            obj.project_name = item.project_name
            obj.arr.push(item);
            lastData.push(obj);
            console.log('item',item)
          } else {
            lastData.forEach((project_name, index) => {
              if (project_name[key] === item[key]) {
                console.log('item222',item)
                project_name.arr.push(item);
              }
            });
          }
        });
        return lastData;
      },
      getAnticoagulant(id){
        
        var name = ""
        for(let i=0;i<this.anticoagulantList.length;i++){
          if(id == this.anticoagulantList[i].id){
              name = this.anticoagulantList[i].name
          }
        }
        return name
      }
  },
 
  created() {
     var anticoagulantsConfitOne = this.$store.getters.anticoagulants_confit
     const arrFour = []
     Object.keys(anticoagulantsConfitOne).map((item, index) => {
     if (index != 2) {
        arrFour.push(anticoagulantsConfitOne[item])
       }
     })
    this.anticoagulantList = arrFour
    console.log("抗凝剂",this.anticoagulantList)
    var xtuser = this.$store.getters.xt_user
    this.orgname = xtuser.org.org_name
    var id = this.$route.query.id
    
    this.getTemplateSummaryPrintDetail(id)
    
  }
}
</script>

<style>
.borderBox  p{
  font-weight: bold;
  margin: 10px 0;
}
.dialysis-print-order {
  width: 960px;
  margin: 0 auto;
}

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

.dialysis-print-order .order-title {
  margin: auto;
  font-weight: 600;
  text-align: center;
  font-size: 22px;
  padding: 10px 20px 20px 20px;
}

.dialysis-print-order .table-box {
  width: 100%;
  line-height: 23px;
  font-size: 14px;
}

.dialysis-print-order .print-table {
  width: 100%;
  text-align: center;
  border-collapse: collapse;
  line-height: 40px;
  font-size: 14px;
}

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

.dialysis-print-order .under-line {
  border-bottom: 1px solid #999;
  width: 95%;
  text-align: center;
  margin-left: 2px;
}

.dialysis-print-order .title-box {
  text-align: center;
  font-size: 16px;
}

.dialysis-print-order .radio-lebel-box {
  font-weight: 400;
  cursor: pointer;
}

.dialysis-print-order .radio-no {
  opacity: 0;
  outline: none;
  position: absolute;
  margin: 0;
  width: 0;
  height: 0;
  z-index: -1;
}

.dialysis-print-order .radio-inner {
  white-space: nowrap;
  cursor: pointer;
  outline: none;
  display: inline-block;
  line-height: 1;
  position: relative;
  vertical-align: middle;
}

.dialysis-print-order .radio-fang {
  display: inline-block;
  position: relative;
  border: 1px solid #000;
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  background-color: #fff;
  z-index: 1;
  transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
    background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
}

.dialysis-print-order .is-checked-radio::after {
  content: "√";
  font-size: 15px;
}

.dialysis-print-order .print-table-no tr td {
  padding: 8px 5px;
  line-height: 25px;
}

.dialysis-print-order .print-table tr td {
  padding: 1px 1px;
  /*line-height: 25px;*/
}

.es-img {
  height: 25px;
}

.advice-name {
  text-align: left;
}

.advice-children {
  display: flex;
}

.title-box-pro {
  border: 0 #fff;
  line-height: 25px;
  height: 25px;
  text-align: left;
  padding-left: 10px !important;
}
.title-box-pro-tr {
  border: 0 #fff;
}
.text-align-left {
  text-align: left !important;
  padding-left: 10px !important;
  font-size: 14px !important;
  line-height: 25px;
}
.print-table-tr-new td {
  line-height: 20px !important;
}
.border-top-solid {
  border: solid 1px #000;
}
.print-template-two tr {
  line-height: 30px;
}
.parent {
  text-align: left;
  padding-left: 20px !important;
}
</style>
