<template>
  <div class="PrescriptionD">
    <div style="margin-bottom:10px;">
      <el-button size="small" type="primary" @click="$router.back()">返回</el-button>
      <el-button size="small" v-if="showPrintHTML" type="primary" icon="el-icon-download" :disabled="loading" @click="print()">下载打印</el-button>
    </div>
    <div class="detail print-containers" ref="print">
      <div class="detail-item flex-plane-center-l">
        <div class="title">方剂名称：</div>
        <div class="right">{{info.prename}}</div>
      </div>
      <div class="detail-item flex-plane-center-l">
        <div class="title">药品明细：</div>
        <div class="right">
          <div
            v-if="showTransitionPr"
            class="zhuanfag flex-center no-print"
            @click="$router.push({path:'/index/prescribing?recipeID='+$route.query.pried+'&kjType=kj-fj'})"
          >转方</div>
          <div>
            <span
              v-for="(item,index) in info.items"
              :key="index"
            >{{item.matname}}{{item.dose}}{{item.unit}}</span>
          </div>
        </div>
      </div>
      <div class="detail-item flex-plane-center-l">
        <div class="title">功效：</div>
        <div class="right">{{info.efficacy}}</div>
      </div>
      <div class="detail-item flex-plane-center-l">
        <div class="title">主治：</div>
        <div class="right">{{info.indication}}</div>
      </div>
      <div class="detail-item flex-plane-center-l">
        <div class="title">用法：</div>
        <div class="right">{{info.preusage}}</div>
      </div>
      <div class="detail-item flex-plane-center-l">
        <div class="title">书籍名称：</div>
        <div class="right">{{info.book}}</div>
      </div>
      <div class="detail-item flex-plane-center-l">
        <div class="title">原始出处：</div>
        <div class="right">{{info.content}}</div>
      </div>
      <!-- 笔记输入框 -->
      <div class="detail-item flex-plane-center-l no-print" v-if="isCollect">
        <div class="title">个人笔记：</div>
        <div class="right flex note">
          <el-input type="textarea" :rows="6" placeholder="请输入" v-model="text" :disabled="!isEdit" />
          <el-button type="primary" @click="isEdit=!isEdit">{{ isEdit?'保存':'修改' }}</el-button>
        </div>
      </div>
    </div>

    <!-- 收藏图标 -->
    <div class="collect" v-if="false">
      <img
        src="../../assets/new-icon/collectpng.png"
        alt
        v-if="!isCollect"
        @click="isCollect=!isCollect"
      />
      <img src="../../assets/new-icon/collectpng-fill.png" alt v-else @click="isCollect=!isCollect" />
    </div>
  </div>
</template>
<script>
import { mapGetters } from 'vuex';
import { getDataByKey } from '@/api/system';
import { getPreDetal } from "@/api/knowledge.js";
import printJS from 'print-js';
export default {
  data() {
    return {
      loading: false,
      showPrintHTML: false,
      showTransitionPr: false,
      info: {},
      isCollect: false,
      isEdit: true,
      text: ""
    };
  },
  created() {
    getDataByKey({
      key: "transitionPr",
      organizationid: this.getuserinfo.organizationid,
    }).then(data => { this.showTransitionPr = data.enabled; });
    getDataByKey({
      key: "showPrintHTML",
      organizationid: this.getuserinfo.organizationid,
    }).then(data => { this.showPrintHTML = data.enabled; });
    this.getPreDetal();
  },
  computed: {
    ...mapGetters(["getuserinfo"])
  },
  methods: {
    // 获取详细信息
    async getPreDetal() {
      this.loading = true;
      let res = await getPreDetal({
        preid: this.$route.query.pried
      });
      if (res.code == 0) {
        this.info = res.data;
        this.loading = false;
      }
    },
    async print() {
      printJS({
        printable: this.$refs.print,
        type: 'html',
        documentTitle: `名医名方 - 方剂`,
        scanStyles: false,
        css: ['print/containers.css', 'print/PrescriptionD.css'],
      })
    }
  }
};
</script>
<style lang="scss" scoped>
@import "../../style/common.scss";

.PrescriptionD {
  background: #ffffff;
  border-radius: 5px;
  padding: 10px 10px;

  height: 78vh;
  position: relative;

  .collect {
    position: absolute;
    top: 10px;
    right: 20px;

    img {
      width: 50px;
    }
  }

  .back {
    width: 74px;
    height: 36px;
    background: #5386f6;
    border-radius: 4px;
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    color: #ffffff;
    cursor: pointer;
    margin-bottom: 45px;
  }

  .detail {
    .detail-item {
      font-size: 16px;
      font-family: PingFang SC;
      font-weight: 400;
      color: #333333;
      margin-bottom: 10px;

      .title {
        width: 90px;
        text-align-last: justify;
      }

      .right {
        flex: 1;
      }

      .zhuanfag {
        width: 60px;
        height: 26px;
        background: #ffae45;
        border-radius: 2px 2px 2px 2px;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 400;
        color: #ffffff;
        margin-bottom: 10px;
      }

      span {
        display: inline-block;
        margin-right: 30px;
      }
    }
  }
}

.note {
  align-items: flex-end;
}

.note ::v-deep .el-button {
  height: 36px;
  margin-left: 10px;
}
</style>
<style lang="scss" scoped>
@media screen and (min-width: 1681px) and (max-width: 1920px) {
  .PrescriptionD {
    height: 86vh;
  }
}

@media screen and (min-width: 1601px) and (max-width: 1680px) {
  .PrescriptionD {
    height: 86vh;
  }
}

@media screen and (min-width: 1361px) and (max-width: 1600px) {
  .PrescriptionD {
    height: 80vh;
  }
}

@media screen and(min-width:1281px) and (max-width: 1360px) {
  .PrescriptionD {
    height: 80vh;
  }
}
</style>