<template>
  <!-- 安全合理用药 -->
  <div class="safeDrug">
    <div class="patiens-msg mr-t10" v-if="rationalMed.length>0">
      <div class="p">
        <!-- {{item.matname}}({{item.matbzjj}}) -->
        <!-- <div class="patiens-name">{{item.matname}}</div> -->
        <div class="patiens-cate" v-if="raDoseShow">超剂量药品：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed10" :key="index">
          <span v-if="item.showDose">
            <span class="matname">{{item.matname}}</span>
            <span style="color:red;">({{item.matmindosage}}-{{item.matmaxdosage}})</span>
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed2.length>0">
        <div class="patiens-cate">慎忌禁用药：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed2" :key="index">
          <span v-if="item.matsjj">
            <span class="matname">{{item.matname}}</span>
            ({{item.matsjj}})
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed3.length>0">
        <div class="patiens-cate">孕妇慎忌禁：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed3" :key="index">
          <span v-if="item.matyfsjj">
            <span class="matname">{{item.matname}}</span>
            <span :style="{color:item.matyfsj==3?'red':''}">({{item.matyfsjj |fyfsjj}})</span>
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed4.length>0">
        <div class="patiens-cate">服药饮食禁忌：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed4" :key="index">
          <span v-if="item.matysjj">
            <span class="matname">{{item.matname}}</span>
            ({{item.matysjj?item.matysjj:'无'}})
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed5.length>0">
        <div class="patiens-cate">药物毒性说明：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed5" :key="index">
          <span v-if="item.matdxsm">
            <span class="matname" style="color:red;">{{item.matname}}</span>
            ({{item.matdxsm?item.matdxsm:'无'}})
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed6.length>0">
        <div class="patiens-cate">病证用药禁忌：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed6" :key="index">
          <span v-if="item.matbzjj">
            <span class="matname">{{item.matname}}</span>
            ({{item.matbzjj?item.matbzjj:'无'}})
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed7.length>0">
        <div class="patiens-cate">十八反：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed7" :key="index">
          <!-- <span v-if='item.matsbf'>{{fsbf(item.matsbf,item.matname)}}</span> -->
          <span v-if="item.matsbf">
            <span style="color:red;">{{item.matname}}</span>
            反{{item.matsbf}}
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed8.length>0">
        <div class="patiens-cate">十九畏：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed8" :key="index">
          <!-- <span v-if="item.matsjw">{{fsjw(item.matsjw,item.matname)}}</span> -->
          <span v-if="item.matsjw">
            <span style="color:red;">{{item.matname}}</span>
            畏{{item.matsjw}}
          </span>
        </div>
      </div>

      <div class="p" v-if="rationalMed9.length>0">
        <div class="patiens-cate">用药不宜：</div>
        <div class="patiens-desc" v-for="(item,index) in rationalMed9" :key="index">
          <span v-if="item.matby">{{fmatby(item.matby,item.matname) }}</span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      rationalMed: [],
      rationalMed1: [],
      rationalMed2: [],
      rationalMed3: [],
      rationalMed4: [],
      rationalMed5: [],
      rationalMed6: [],
      rationalMed7: [],
      rationalMed8: [],
      rationalMed9: [],
      rationalMed10: [],
      raDoseShow: false
    };
  },
  created() {
    this.resetData();
  },
  mounted() {
    this.getSvaeMed();
  },
  beforeDestroy() {
    this.resetData();
  },

  watch: {
    rationalMed10: {
      deep: true,
      immediate: true,
      handler: function() {
        this.countDose();
      }
    }
  },
  filters: {
    ftsjj(value) {
      if (value == 1) {
        return "慎用";
      }
      if (value == 2) {
        return "忌用";
      }
      if (value == 3) {
        return "禁用";
      }
    },
    fyfsjj(value) {
      if (value == 1) {
        return "孕妇慎用";
      }
      if (value == 2) {
        return "孕妇忌用";
      }
      if (value == 3) {
        return "孕妇禁用";
      }
    }
  },
  methods: {
    // 获取安全合理用药信息
    getSvaeMed(data) {
      setTimeout(() => {
        this.rationalMed = this.$parent.$parent.$parent.rationalMed;
        this.rationalMed1 = this.$parent.$parent.$parent.rationalMed1;
        this.rationalMed2 = this.$parent.$parent.$parent.rationalMed2;
        this.rationalMed3 = this.$parent.$parent.$parent.rationalMed3;
        this.rationalMed4 = this.$parent.$parent.$parent.rationalMed4;
        this.rationalMed5 = this.$parent.$parent.$parent.rationalMed5;
        this.rationalMed6 = this.$parent.$parent.$parent.rationalMed6;
        this.rationalMed7 = this.$parent.$parent.$parent.rationalMed7;
        this.rationalMed8 = this.$parent.$parent.$parent.rationalMed8;
        this.rationalMed9 = this.$parent.$parent.$parent.rationalMed9;
        this.rationalMed10 = this.$parent.$parent.$parent.rationalMed10;
      }, 100);
    },
    resetData() {
      this.rationalMed = [];
      this.rationalMed1 = [];
      this.rationalMed2 = [];
      this.rationalMed3 = [];
      this.rationalMed4 = [];
      this.rationalMed5 = [];
      this.rationalMed6 = [];
      this.rationalMed7 = [];
      this.rationalMed8 = [];
      this.rationalMed9 = [];
      this.rationalMed10 = [];
      this.raDoseShow = false;
    },
    countDose() {
      let show = false;
      this.rationalMed10.forEach(item => {
        if (item.showDose) {
          show = true;
        }
      });
      this.$forceUpdate();
      this.raDoseShow = show;
    }
  }
};
</script>
<style lang="scss" scoped>
.patiens-msg {
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 400;
  color: #333333;

  .p {
    margin-bottom: 5px;
    cursor: default;

    .patiens-name {
      color: #5386f6;
      font-weight: bold;
      font-size: 16px;
    }

    .patiens-desc {
      display: inline-block;

      .matname {
        color: #5386f6;
      }
    }

    .patiens-cate {
      font-weight: bold;
    }
  }
}
</style>