<!--  -->
<template>
  <div class="inventory_box" :style="'height:' + fullHeight + 'px'">
    <!-- 页头 -->
    <div class="inventory_box_headr">
      <el-page-header title @back="goBack" content="知识库详情"></el-page-header>
    </div>


    <!-- 主内容 -->
    <div class="inventory_box_main">
      <!-- 图片 -->
      <div class="inventory_box_main_tupian">
        <img
          preview="1"
          v-lazy="this.redata.img_urls === null || this.redata.img_urls === '' ? './static/picture.jpg': this.redata.img_urls"
          alt
          class="inventory_box_main_tupian_img"
        />

        <!-- 病虫害名字 -->
        <div class="inventory_box_main_tupian_name">
          <div class="inventory_box_main_tupian_nameA">{{ this.redata.name }}</div>
        </div>
      </div>

      <!-- 详情 -->
      <div class="inventory_box_main_particulars">
        <!-- 小百科 -->
        <div class="inventory_box_main_cyclopedia">
          <img src="../../assets/imageOne/38.png" alt class="inventory_box_main_cyclopedia_img" />
          <span class="inventory_box_main_cyclopedia_title">小百科</span>
        </div>

        <!-- 详情text -->
        <div class="inventory_box_main_text" v-for="item in this.msg" :key="item">{{ item }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  inject: ["reload"], //刷新页面
  //import引入的组件需要注入到对象中才能使用
  components: {
  },
  data() {
    //这里存放数据
    return {
      fullHeight: document.documentElement.clientHeight,
      redata: [], //后端传来的数据
      msg: ""
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {
    fullHeight(val) {
      //监控浏览器高度变化
      if (!this.timer) {
        this.fullHeight = val;
        this.timer = true;
        let that = this;
        setTimeout(function() {
          //防止过度调用监测事件，导致卡顿
          that.timer = false;
        }, 400);
      }
    }
  },
  //方法集合
  methods: {
    //点击返回系统设置
    goBack() {
      let _this = this;
      localStorage.removeItem("libraryID");
      // _this.$router.push("/library");
      _this.$router.replace("/library");
      // _this.reload(); //刷新页面
      // location.reload();
    },

    //动态获取浏览器高度
    get_boderHeight() {
      const that = this;
      window.onresize = () => {
        return (() => {
          window.fullHeight = document.documentElement.clientHeight;
          that.fullHeight = window.fullHeight;
        })();
      };
    },

    //切割详情字符串数据并渲染
    apply() {
      let _this = this;
      let Adata = _this.redata.prevention;
      var a = Adata.replace(/]/g, "：");
      let Bdata = new Array();
      Bdata = a.split("[");
      _this.msg = Bdata;
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.get_boderHeight();
    let postData = this.$qs.parse({
      id: localStorage.getItem("libraryID")
    });
    this.$axios({
      method: "post",
      url: "bigservers/insect_base",
      data: postData,
      headers: {
        "Content-Type": "application/json"
      }
    })
      .then(res => {
        this.redata = res.data[0];
        console.log(res.data[0].img_urls);
        if (res.data[0].prevention !== "[防治方法] null") {
          this.apply();
        }
      })
      .catch(error => {});
  }
};
</script>
<style lang='scss'>
@import "../../assets/style/bus.scss";
@import "../../assets/style/scss/inventory.scss";
</style>