<template>
  <div class="entering-box">
    <el-header>
      <el-page-header title @back="goBack" content="采集人录入设置"></el-page-header>
      <img src="../../assets/imageOne/24.png" alt class="entering-img" @click="save()" />
    </el-header>

    <!-- 主内容 -->
    <el-main :style="'height:' + fullHeight + 'px'">
      <el-input type="textarea" :rows="10"  placeholder="请输入内容" v-model.trim="textarea"></el-input>
    </el-main>
  </div>
</template>

<script>
export default {
  name: "entering",
  data() {
    return {
      textarea: "",
      fullHeight: document.documentElement.clientHeight
    };
  },
  watch: {
    fullHeight(val) {
      //监控浏览器高度变化
      if (!this.timer) {
        this.fullHeight = val;
        this.timer = true;
        let that = this;
        setTimeout(function() {
          //防止过度调用监测事件，导致卡顿
          that.timer = false;
        }, 400);
      }
    }
  },

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

    goBack() {
      let _this = this;
      this.$router.push("/newmessage");
      // _this.reload()
      location.reload(); //实现视图强制刷新
    },

    //点击图标保存到本地
    save() {
      let _this = this;
      if (_this.textarea !== "") {
        localStorage.setItem("userName", _this.textarea);
        this.$message({
          type: "success",
          message: "保存成功!"
        });
        _this.$router.push("/newmessage");
        const timer = setInterval(() => {
          location.reload();
        }, 1000);
      } else {
        this.$notify({
          title: "警告",
          message: "采集人不能为空",
          type: "warning",
          duration: 1000,
        });
      }
      //   localStorage.setItem("userName",_this.textarea);
    }
  }
};
</script>

<style lang="scss">
@import "../../assets/style/bus.scss";
@import "../../assets/style/scss/entering.scss";
</style>
