<template>
  <div v-if="visibility" class="Dialog">
    <div class="DialogTit">
      <div class="back" @click="cancle()">
        <span class="iconfont">&#xe720; </span>返回
      </div>
      <h1 class="name">
        {{ patient_prop.name }} [透析号 {{ patient_prop.dialysis_no }} ]
      </h1>
      <span @click="comfirm" class="success" style="visibility: hidden;"
        >确定</span>
    </div>

    <div class="DialogContent">
      <div class="item">
        <label class="name" for="txms">本次透析日期</label>
        <div class="content">
          <span class="text" id="txms"> {{ dialysis_date }}</span>
        </div>
      </div>
      <div class="item" style="display:block;">
        <div class="name" style="width:100%;text-align:left;line-height:1.5rem;font-size:0.7rem;" for="txms">透前体重（kg）<span style="text-align:right;float: right;color:#ec6618;">{{ getBeforeWeight(predialysis)}}</span></div>
        <div class="content" style="margin-top:5px;margin-left:0;">
          <span class="text" style="text-align:left;display:block;height:0.4rem;" id="txms">透前体重:<span style="color:#ec6618;display:inline-block;text-align:center;margin:0 2px;">{{ getBeforeWeight(predialysis)}}</span>kg=
          透前总重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{predialysis.weight_before}}</span>kg-
          衣服重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{predialysis.additional_weight}}</span>kg
           </span>
        </div>
        <br>
      </div>
      <div class="item">
        <label class="name" for="txms">干体重（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ getDryWeight() }}</span>
        </div>
      </div>
      <!-- <div class="item">
        <label class="name" for="txms">衣物重（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{
            predialysis.additional_weight
          }}</span>
        </div>
      </div> -->
      <div class="item" style="display:block;">
        <div class="name" style="width:100%;text-align:left;line-height:1.5rem;font-size:0.7rem;" for="txms">体重增加（kg）<span style="text-align:right;float: right;color:#ec6618;">{{add_weight}}</span></div>
        <div class="content" style="margin-top:5px;margin-left:0;">
          <span class="text" style="text-align:left;display:block;height:0.8rem;line-height:0.6rem;" id="txms">体重增加:<span style="color:#ec6618;display:inline-block;text-align:center;margin:0 2px;">{{add_weight}}</span>kg=
          透前体重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{getBeforeWeight(predialysis)}}</span>kg -
          上次透后体重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{getLastAfterWeight(last_record)}}</span>kg
          </span>
        </div>
        <br>
      </div>
      <!-- <div class="item">
        <label class="name" for="txms">体重增加（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ add_weight }}</span>
        </div>
      </div> -->
      <div class="item" style="display:block;">
        <div class="name" style="width:100%;text-align:left;line-height:1.5rem;font-size:0.7rem;" for="txms">透后体重（kg）<span style="text-align:right;float: right;color:#ec6618;">{{getAfterWeight(record)}}</span></div>
        <div class="content" style="margin-top:5px;margin-left:0;">
          <span class="text" style="text-align:left;display:block;height:0.4rem;" id="txms">透后体重:<span style="color:#ec6618;display:inline-block;text-align:center;margin:0 2px;">{{getAfterWeight(record)}}</span>kg=
          透后总重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{record.weight_after}}</span>kg-
          衣服重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{predialysis.additional_weight}}</span>kg
           </span>
        </div>
        <br>
      </div>
      <!-- <div class="item">
        <label class="name" for="txms">透后体重（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ getAfterWeight(record)}}</span>
        </div>
      </div> -->
      <div class="item">
        <label class="name" for="txms">体重减少（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ weight_loss }}</span>
        </div>
      </div>
      <div class="item" style="display:block;">
        <div class="name" style="width:100%;text-align:left;line-height:1.5rem;font-size:0.7rem;" for="txms">上次透后体重（kg）<span style="text-align:right;float: right;color:#ec6618;">{{getLastAfterWeight(last_record)}}</span></div>
        <div class="content" style="margin-top:5px;margin-left:0;">
          <span class="text" style="text-align:left;display:block;height:0.4rem;" id="txms">上次透后体重:<span style="color:#ec6618;display:inline-block;text-align:center;margin:0 2px;">{{getLastAfterWeight(last_record)}}</span>kg=
          上次透后总重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{last_record.weight_after}}</span>kg-
          上次衣服重:<span style="color:#ec6618;display:inline-block;text-align:center;center;margin:0 2px;">{{last_predialysis.additional_weight}}</span>kg
           </span>
        </div>
        <br>
      </div>
      <!-- <div class="item">
        <label class="name" for="txms">上次透后体重（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{
           getLastAfterWeight(last_record)
          }}</span>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script>
import { parseTime } from '@/utils'

export default {
  name: 'LongAdviceSubMenu',
  created () {
    if (this.predialysis.weight_before > 0 && this.last_record.weight_after > 0) {
      this.add_weight = parseFloat(
        (this.predialysis.weight_before - this.predialysis.additional_weight) - (this.last_record.weight_after - this.last_predialysis.additional_weight)
      ).toFixed(2)
    }
    let loss = ''
    if (this.predialysis.weight_before > 0 && this.record.weight_after > 0) {
      loss = parseFloat(this.predialysis.weight_before - this.record.weight_after).toFixed(2)
      loss = loss > 0 ? loss : ''
    }
    this.weight_loss = this.record.weight_loss ? this.record.weight_loss : loss
  },
  data () {
    return {
      result: [],
      id: 0,
      selectName: '',
      add_weight: 0,
      weight_loss: ''
    }
  },
  props: {
    predialysis: {
      type: Object,
      default: null

    },
    visibility: {
      type: Boolean,
      default: false
    },
    last_predialysis: {
      type: Object
    },
    record: {
      type: Object
    },
    last_record: {
      type: Object
    },
    patient_prop: {
      type: Object
    },
    prescription_prop: {
      type: Object
    },
    dry_weight: {
      type: Object
    }
  },
  computed: {
    dialysis_date: function () {
      return parseTime(this.$route.query.date, '{y}/{m}/{d}')
    }
  },
  methods: {
    getDryWeight () {
      if (this.dry_weight != null && this.dry_weight.id > 0) {
        return this.dry_weight.dry_weight
      } else {
        if (this.last_predialysis != null && this.last_predialysis.id > 0) {
          return this.last_predialysis.dry_weight
        } else {
          return ''
        }
      }
    },
    getBeforeWeight (predialysis) {
      if (predialysis.id > 0) {
        if (predialysis.weight_before > 0) {
          return parseFloat(predialysis.weight_before - predialysis.additional_weight).toFixed(1)
        } else {
          return ''
        }
      }
    },
    getAfterWeight (record) {
      if (record.id > 0) {
        if (record.weight_after > 0) {
          return parseFloat(record.weight_after - this.predialysis.additional_weight).toFixed(1)
        } else {
          return ''
        }
      }
    },
    getLastAfterWeight (last_record) {
      if (last_record.id > 0) {
        if (last_record.weight_after > 0) {
          let additional_weight = 0
          if (this.last_predialysis.additional_weight != undefined) {
            additional_weight = this.last_predialysis.additional_weight
          }
          return parseFloat(last_record.weight_after - additional_weight).toFixed(1)
        } else {
          return ''
        }
      }
    },
    cancle: function () {
      this.$emit('menu-msg-tip')
    },
    comfirm: function () {
      this.$emit('menu-msg-tip')
    },
    getValue: function () {
      let form = {}

      let results = []

      for (let i = 0; i < this.propsForm.list.length; i++) {
        for (let a = 0; a < this.propsForm.result.length; a++) {
          if (this.propsForm.list[i].id == this.propsForm.result[a]) {
            results.push(this.propsForm.list[i])
          }
        }
      }

      var obj5 = {}
      results = results.reduce((cur, next) => {
        obj5[next.id] ? '' : (obj5[next.id] = true && cur.push(next))
        return cur
      }, [])

      results

      return results
    }
  },
  watch: {
    visibility (val) {
      // 初始化数据操作
    }
  }
}
</script>

<style style="stylesheet/scss" lang="scss" scoped>
.optionsBox {
  background: #fff;
  max-height: 10rem;
  min-height: 5rem;
  @media only screen and (max-width: 812px) {
    min-height: 8rem !important;
  }
  ul {
    overflow-y: scroll;
    max-height: 9rem;
    li {
      height: 1.1rem;
      line-height: 1.1rem;
      border-bottom: 1px #e5e5e5 solid;
      padding: 0 0.38rem;
      font-size: 0.36rem;
      color: $title-color;
    }
    .tick {
      position: relative;
      &::before {
        content: "";
        display: inline-block;
        border: 2px solid $main-color;
        border-top-width: 0;
        border-right-width: 0;
        width: 0.3rem;
        height: 0.15rem;
        -webkit-transform: rotate(-50deg);
        position: absolute;
        top: 0.38rem;
        right: 0.44rem;
      }
    }
  }
}
.CheckBox {
  background: #fff;
  max-height: 6.8rem;
  min-height: 5rem;
  overflow-y: scroll;
  @media only screen and (max-width: 812px) {
    max-height: 8rem !important;
    min-height: 8rem !important;
  }

  ul {
    li {
      line-height: 1rem;
    }
  }
}
</style>
