<template>
  <div class="plate-box">
    <h2 class="title"><span class="line"></span><p>{{title}}</p><span class="line"></span> </h2>
    <div class="plate">
      <ul>
        <li v-if="isShow('透析模式')">
          <label>透析模式 : </label>
          <span class="content">{{dialysis_mode}}</span>
        </li>
        <li v-if="isShow('目标超滤量')">
          <label>目标超滤量 : </label>
          <span class="content">{{target_ultrafiltration != '0'?target_ultrafiltration:''}}</span>
          <span class="unit">{{target_ultrafiltration != '0'?"L":''}}</span>
        </li>
        <li v-if="isShow('首剂')">
          <label>首剂 : </label>
          <span class="content">{{anticoagulant_shouji != '0'?anticoagulant_shouji:''}}</span>
          <span class="unit">{{anticoagulant_shouji != '0'?"mg":''}}</span>
        </li>
        <li v-if="isShow('钙')">
          <label>钙: </label>
          <span class="content">{{calcium != '0'?calcium:""}}</span>
          <span class="unit">{{calcium != '0'?"mmol/L":""}}</span>
        </li>
        <li  v-if="isShow('置换量')">
          <label>置换量 : </label>
          <span class="content">{{replacement_total != '0'?replacement_total:""}}</span>
          <span class="unit">{{replacement_total != '0'?"L":""}}</span>
        </li>

        <li v-if="isShow('葡萄糖')">
          <label>葡萄糖 : </label>
          <span class="content">{{glucose != '0'?glucose:""}}</span>
          <span class="unit">{{glucose != '0'?"mmol/L":""}}</span>
        </li>
      <!-- </ul>
      <ul> -->
        <li v-if="isShow('透析时长')">
          <label>透析时长 : </label>
          <span class="content">{{dialysis_duration != '0'?dialysis_duration:""}}</span>
        </li>
        <li v-if="isShow('透析液配方')">
          <label>透析液配方 : </label>
          <span class="content">{{dialysate_formulation}}</span>
        </li>
        <li v-if="isShow('维持')">
          <label>维持 : </label>
          <span class="content">{{anticoagulant_weichi != '0'?anticoagulant_weichi:""}}</span>
          <span class="unit">{{anticoagulant_weichi != '0'?"mg/h":""}}</span>
        </li>
        <li v-if="isShow('钾')">
          <label>钾 : </label>
          <span class="content">{{kalium != '0'?kalium:""}}</span>
          <span class="unit">{{kalium != '0'?"mmol/L":""}}</span>
        </li>
        <li v-if="isShow('碳酸氢盐')">
          <label>碳酸氢盐 : </label>
          <span class="content">{{bicarbonate != '0'?bicarbonate:""}}</span>
          <span class="unit">{{bicarbonate != '0'?"mmol/L":""}}</span>
        </li>
        <!-- <li>
          <label>干体重 : </label>
          <span class="content">{{dry_weight}}</span>
          <span class="unit">kg</span>
        </li> -->
        <li v-if="isShow('透析液温度')">
          <label>透析液温度 : </label>
          <span class="content">{{dialysate_temperature != '0'?dialysate_temperature:""}}</span>
          <span class="unit">{{dialysate_temperature != '0'?"℃":""}}</span>
        </li>
      <!-- </ul>
      <ul> -->
        <li v-if="isShow('血流量')">
          <label>血流量 : </label>
          <span class="content">{{blood_flow_volume != '0'?blood_flow_volume:''}}</span>
          <span class="unit">{{blood_flow_volume != '0'?"ml/min":''}}</span>
        </li>
        <li v-if="isShow('抗凝剂')">
          <label>抗凝剂 : </label>
          <span class="content">{{anticoagulant}}</span>
        </li>
        <li v-if="isShow('总量')">
          <label>总量: </label>
          <span class="content">{{anticoagulant_zongliang != '0'?anticoagulant_zongliang:""}}</span>
          <span class="unit" v-if="this.prescription.anticoagulant == 2">{{anticoagulant_zongliang != '0'?"mg":""}}</span>
          <span class="unit" v-if="this.prescription.anticoagulant == 3">{{anticoagulant_zongliang != '0'?"IU":""}}</span>
          <span class="unit" v-if="this.prescription.anticoagulant == 1">{{anticoagulant_zongliang != '0'?"mg":""}}</span>
          <span class="unit" v-if="this.prescription.anticoagulant == 4">{{anticoagulant_zongliang != '0'?"mg":""}}</span>
          <span class="unit" v-if="this.prescription.anticoagulant == 5">{{anticoagulant_zongliang != '0'?"mg":""}}</span>

        </li>
        <li v-if="isShow('钠')">
          <label>钠 : </label>
          <span class="content">{{sodium != '0'?sodium:""}}</span>
          <span class="unit">{{sodium != '0'?"mmol/L":""}}</span>
        </li>
        <li v-if="isShow('透析液流量')">
          <label>透析液流量 : </label>
          <span class="content">{{dialysate_flow != '0'?dialysate_flow:""}}</span>
          <span class="unit">{{dialysate_flow != '0'?"ml/min":""}}</span>
        </li>

      <!-- </ul>
      <ul> -->
        <li v-if="isShow('透析器/灌流器')">
          <label>透析器/灌流器 : </label>
          <span class="content">{{dialyzer_perfusion_apparatus}}</span>
          <span class="unit"></span>
        </li>
        <li v-if="isShow('体液过多症状')">
          <label>体液过多症状: </label>
          <span class="content">{{body_fluid}}</span>
          <span class="unit"></span>
        </li>
        <li v-if="isShow('透析前使用特殊药物')">
          <label>透析前使用特殊药物: </label>
          <span class="content">{{special_medicine}}</span>
          <span class="unit"></span>
        </li>
        <li v-if="isShow('透析前使用其他特殊药物')">
          <label>透析前使用其他特殊药物: </label>
          <span class="content">{{special_medicine_other}}</span>
          <span class="unit"></span>
        </li>
        <li v-if="isShow('置换液')">
          <label>置换液: </label>
          <span class="content">{{displace_liqui}}</span>
          <span class="unit"></span>
        </li>
        <li v-if="isShow('血管通路')">
          <label>血管通路: </label>
          <span class="content">{{blood_access}}</span>
          <span class="unit"></span>
        </li>
        <li v-if="isShow('实际超滤量')">
          <label>实际超滤量: </label>
          <span class="content">{{ultrafiltration != '0'? ultrafiltration:''}}</span>
          <span class="unit">{{ultrafiltration != '0'?"L":""}}</span>

        </li>
        <li v-if="isShow('目标KT/V')">
          <label>目标KT/V: </label>
          <span class="content">{{target_ktv != '0'? target_ktv:''}}</span>
        </li>

        <li v-if="isShow('电导度')">
          <label>电导度 : </label>
          <span class="content">{{conductivity != '0'?conductivity:""}}</span>
          <span class="unit">{{conductivity != '0'?"mS/m":""}}</span>
        </li>

      </ul>
    </div>
    <div class="note">备注 : <span>{{note}}</span></div>
  </div>
</template>

<script>
import {getDataConfig} from '@/utils/data'
export default {
  name: 'DialysisPrescription',
  data () {
    return {
      title: '透析处方',
      perfusion_apparatus_map: {},
      dialysateFormulationMap: {}
    }
  },
  props: {
    prescription: {
      type: Object
    },
    solution: {
      type: Object
    },
    device_number_map: {
      type: Object
    }
  },
  computed: {
    target_ultrafiltration: function () {
      var v = this.getValueStr('target_ultrafiltration', 'target_ultrafiltration')
      v = this.getFloat(v)
      return v.length == 0 ? '0' : v
    },
    dialysis_mode: function () {
      var mode = this.getValueStr('mode_id', 'mode_id')
      if (mode.length == 0) {
        return ''
      }
      if (this.$store.getters.treatment_mode[mode] != undefined) {
        return this.$store.getters.treatment_mode[mode].name
      }
      return ''
    },
    perfusion_apparatus: function () {
      var v = this.getValueStr('perfusion_apparatus', 'perfusion_apparatus')
      if (v.length == 0) {
        return ''
      }
      if (this.perfusion_apparatus_map[v] != undefined) {
        return this.perfusion_apparatus_map[v].name
      }
      return ''
    },
    displace_liqui: function () {
      var v = this.getValueStr('displace_liqui', 'displace_liqui')
      return v.length == 0 ? '0' : v
    },
    anticoagulant_shouji: function () {
      var v = this.getValueStr('anticoagulant_shouji', 'anticoagulant_shouji')
      return v.length == 0 ? '0' : v
    },
    kalium: function () {
      var v = this.getValueStr('kalium', 'kalium')
      v = this.getFloat(v)
      return v == 0 ? '0' : v
    },
    replacement_total: function () {
      var v = this.getValueStr('replacement_total', 'replacement_total')
      return v.length == 0 ? '0' : v
    },
    bicarbonate: function () {
      var v = this.getValueStr('bicarbonate', 'bicarbonate')
      return v.length == 0 ? '0' : v
    },
    dialysate_flow: function () {
      var v = this.getValueStr('dialysate_flow', 'dialysate_flow')
      return v.length == 0 ? '0' : v
    },
    dialysis_duration: function () {
      var dialysis_duration_hour = (this.getValueStr('dialysis_duration_hour', 'dialysis_duration_hour'))
      var dialysis_duration_minute = (this.getValueStr('dialysis_duration_minute', 'dialysis_duration_minute'))
      if (dialysis_duration_hour.length == 0 && dialysis_duration_minute.length == 0) {
        return '0'
      } else {
        var time = dialysis_duration_hour + 'h' + dialysis_duration_minute + 'min'
        return time.length == 0 ? '0' : time
      }
    },
    blood_flow_volume: function () {
      var v = this.getValueStr('blood_flow_volume', 'blood_flow_volume')
      return v.length == 0 ? '0' : v
    },
    replacement_way: function () {
      return this.getValueStr('replacement_way', 'replacement_way')
    },
    anticoagulant_weichi: function () {
      var v = this.getValueStr('anticoagulant_weichi', 'anticoagulant_weichi')
      return v.length == 0 ? '0' : v
    },
    sodium: function () {
      var v = this.getValueStr('sodium', 'sodium')
      console.log(v)
      v = this.getFloat(v)
      console.log(v)
      return v == 0 ? '0' : v
    },
    glucose: function () {
      var v = this.getValueStr('glucose', 'glucose')
      return v.length == 0 ? '0' : v
    },
    dialysate_temperature: function () {
      var v = this.getValueStr('dialysate_temperature', 'dialysate_temperature')
      return v.length == 0 ? '0' : v
    },
    dialyzer: function () {
      var v = this.getValueStr('dialyzer', 'hemodialysis_machine')
      if (v.length == 0) {
        return ''
      }
      if (this.device_number_map[v] != undefined) {
        return this.device_number_map[v].name
      }
      return ''
    },
    dialysate_formulation: function () {
      var v = this.getValueStr('dialysate_formulation', 'dialysate_formulation')
      if (v.length == 0) {
        return ''
      }
      if (v in this.dialysateFormulationMap) {
        return this.dialysateFormulationMap[v].name
      }
      return ''
    },
    prescription_dewatering: function () {
      var v = this.getValueStr('prescription_dewatering', 'dewater')
      return v.length == 0 ? '0' : v
    },
    anticoagulant: function () {
      var v = this.getValueStr('anticoagulant', 'anticoagulant')
      if (v.length == 0) {
        return ''
      }
      if (this.$store.getters.anticoagulants_confit[v] != undefined) {
        return this.$store.getters.anticoagulants_confit[v].name
      }
      return ''
    },
    anticoagulant_zongliang: function () {
      var v = this.getValueStr('anticoagulant_zongliang', 'anticoagulant_zongliang')
      return v.length == 0 ? '0' : v
    },
    calcium: function () {
      var v = this.getValueStr('calcium', 'calcium')
      v = this.getFloat(v)
      return v == 0 ? '0' : v
    },

    conductivity: function () {
      var v = this.getValueStr('conductivity', 'conductivity')
      return v.length == 0 ? '0' : v
    },
    dialyzer_perfusion_apparatus: function () {
      return this.getValueStr('dialyzer_perfusion_apparatus', 'dialyzer_perfusion_apparatus')
    },
    note: function () {
      return this.getValueStr('remark', 'remark')
    },
    body_fluid: function () {
      var id = this.getValueStr('body_fluid', 'body_fluid')
      if (id == 0) {
        return ''
      }
      var bodyFluidOptions = this.$store.getters.body_fluid
      for (let i = 0; i < bodyFluidOptions.length; i++) {
        if (bodyFluidOptions[i].id == id) {
          return bodyFluidOptions[i].name
        }
      }
    },
    special_medicine: function () {
      var id = this.getValueStr('special_medicine', 'special_medicine')
      if (id == 0) {
        return ''
      }
      var special_medicine = this.$store.getters.special_medicine
      for (let i = 0; i < special_medicine.length; i++) {
        if (special_medicine[i].id == id) {
          return special_medicine[i].name
        }
      }
    },
    special_medicine_other: function () {
      return this.getValueStr('special_medicine_other', 'special_medicine_other')
    },
    blood_access: function () {
      var id = this.getValueStr('blood_access', 'blood_access')
      if (id == 0) {
        return ''
      }
      var blood_access = this.$store.getters.blood_access
      console.log('blood_access', blood_access)
      for (let i = 0; i < blood_access.length; i++) {
        if (blood_access[i].id == id) {
          return blood_access[i].name
        }
      }
    },
    displace_liqui: function () {
      var id = this.getValueStr('displace_liqui_part', 'displace_liqui_part')
      var displace_liqui_value = this.getValueStr('displace_liqui_value', 'displace_liqui_value')
      var displace_liqui_part = ''
      var displace_liqui = this.$store.getters.displace_liqui
      for (let i = 0; i < displace_liqui.length; i++) {
        if (displace_liqui[i].id == id) {
          displace_liqui_part = displace_liqui[i].name
        }
      }
      return displace_liqui_part + displace_liqui_value + 'L'
    },
    ultrafiltration: function () {
      var v = this.getValueStr('ultrafiltration', 'ultrafiltration')
      v = this.getFloat(v)
      return v.length == 0 ? '0' : v
    },
    target_ktv: function () {
      var v = this.getValueStr('target_ktv', 'target_ktv')
      return v.length == 0 ? '0' : v
    }
  },
  created () {
    var perfusion_apparatus = this.$store.getters.perfusion_apparatus
    var map = {}
    for (let index = 0; index < perfusion_apparatus.length; index++) {
      const p = perfusion_apparatus[index]
      map[p.id] = p
    }
    this.perfusion_apparatus_map = map

    var dialysateFormulationOptions = getDataConfig('hemodialysis', 'dialysate_formulation')
    for (var index in dialysateFormulationOptions) {
      this.dialysateFormulationMap[dialysateFormulationOptions[index].id] = dialysateFormulationOptions[index]
    }
  },
  methods: {
    isShow (name) {
      var filedList = this.$store.getters.user.fileds
      for (let i = 0; i < filedList.length; i++) {
        if (filedList[i].module == 1 && filedList[i].filed_name_cn == name && filedList[i].is_show == 1) {
          return true
        }
      }
      return false
    },
    getValueStr (pkey, skey) {
      if ((this.prescription == null || this.prescription.id == '') && (this.solution == null || this.solution.id == '')) {
        return ''
      } else if (this.prescription != null && this.prescription.id != '') {
        if (this.prescription[pkey] == null || this.prescription[pkey] == undefined) {
          return ''
        }
        return this.prescription[pkey] + ''
      } else {
        if (this.solution[skey] == null || this.solution[skey] == undefined) {
          return ''
        }
        return this.solution[skey] + ''
      }
    },
    getFloat: function (x) {
      if (x != '.') {
        var f = Math.round(x * 100) / 100
        var s = f.toString()
        var rs = s.indexOf('.')
        if (rs <= 0) {
          rs = s.length
          s += '.'
        }
        while (s.length <= rs + 1) {
          s += '0'
        }
        return s
      } else {
        return '0.0'
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
