<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">
        <label class="name" for="txms">透前体重（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ getBeforeWeight(predialysis)}}</span>
        </div>
      </div>
      <div class="item">
        <label class="name" for="txms">干体重（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ last_predialysis.dry_weight }}</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">
        <label class="name" for="txms">体重增加（kg）</label>
        <div class="content">
          <span class="text" id="txms">{{ add_weight }}</span>
        </div>
      </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">{{ record.weight_loss }}</span>
        </div>
      </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.last_record.weight_after
      ).toFixed(2);
    }
  },
  data() {
    return {
      result: [],
      id: 0,
      selectName: "",
      add_weight: 0
    };
  },
  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
    }
  },
  computed: {
    dialysis_date: function() {
      return parseTime(this.$route.query.date, "{y}/{m}/{d}");
    }
  },
  methods: {
    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(record){

      if(record.id > 0){
        if(record.weight_after > 0) {
          let additional_weight = 0
          if(this.predialysis.additional_weight != undefined){
            additional_weight = this.predialysis.additional_weight
          }
          return parseFloat(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>
