<!--  -->
<template>
  <div class="megXq_box" :style="'height:' + fullHeight + 'px'">
    <!-- 头部 -->
    <div class="megXq_box_head">
      <!-- 返回图标 -->
      <div class="head_div" @click="goBack()">
        <img src="../../assets/image/return.png" alt class="head_div_img" />
      </div>

      <!-- 标题 -->
      <div class="head_title">
        <span class="head_title_text">用户反馈</span>
      </div>

      <!-- 删除 -->
      <div class="head_del">
        <img @click="del()" src="../../assets/image/del9.png" alt class="del_img" />
      </div>
    </div>

    <!-- 主内容 -->
    <div class="megXq_box_main">
      <!-- 用户模块 -->
      <div class="megXq_main_user">
        <!-- 头像 -->
        <div class="main_user_img_box">
          <img :src=" 'bigservers/' + this.redata.user_photo" alt class="main_user_img" />
        </div>

        <div class="main_user_box">
          <!-- 用户名 -->
          <div
            class="main_user_text"
          >{{ this.redata.user_remark !== null ? this.redata.user_remark : this.redata.username }}</div>

          <!-- 用户反馈数据详情 -->
          <div class="main_user_xiangqiText">{{ this.redata.content }}</div>

          <!-- 时间 -->
          <div class="main_user_time">{{ this.redata.time }}</div>

          <!-- 回复按键 -->
          <img
            v-if="huifuShow"
            @click="show = !show"
            src="../../assets/image/huifu.png"
            alt
            class="main_user_huifu_img"
          />
        </div>
      </div>

      <!-- 隐藏的input -->
      <div class>
        <transition name="el-fade-in-linear">
          <div v-show="show" class="transition-box">
            <el-input type="textarea" :rows="2" placeholder="请输入需要回复的内容" v-model="textarea"></el-input>
          </div>
        </transition>
        <el-button v-show="show" type="success" @click="shangchuan()">提交</el-button>
      </div>

      <!-- 管理员模块 -->
      <div class v-if="textShow">
        <div class="megXq_triangle"></div>
        <div class="megXq_main_administrator">
          <div class="main_administrator_box">
            <span class="main_administrator">管理员:</span>
            <span class="main_administrator_xiangqiText">{{ this.redata.store }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    //这里存放数据
    return {
      fullHeight: document.documentElement.clientHeight,
      redata: [], //数据
      textShow: false, //管理员回复判断
      show: false, //回复功能
      textarea: "",
      huifuShow: false //是管理员查看才显示
    };
  },
  //监听属性 类似于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: {
    //动态获取浏览器高度
    get_boderHeight() {
      const that = this;
      window.onresize = () => {
        return (() => {
          window.fullHeight = document.documentElement.clientHeight;
          that.fullHeight = window.fullHeight;
        })();
      };
    },

    //返回
    goBack() {
      let _this = this;
      localStorage.removeItem("messageRet");
      localStorage.removeItem("messageID");
      // _this.$router.push("/message");
      _this.$router.replace("/message");
    },

    //删除
    del() {
      let _this = this;
      let postData = _this.$qs.parse({
        id: localStorage.getItem("messageID"),
        ret: localStorage.getItem("messageRet")
      });
      _this
        .$axios({
          method: "post",
          url: "bigservers/check_leaving",
          data: postData,
          headers: {
            "Content-Type": "multipart/form-data"
          }
        })
        .then(res => {
          this.$message({
            message: "删除成功",
            type: "success",
            duration: 1000
          });
          _this.$router.replace("/message");
           const timeA = setInterval(() => {
              location.reload();
            }, 1500);
        })
        .catch(error => {
          this.$message({
            message: "删除失败",
            type: "error",
            duration: 1000
          });
        });
    },

    //上传管理员回复的数据
    shangchuan() {
      let _this = this;
      let postData = _this.$qs.parse({
        content: _this.textarea,
        id: localStorage.getItem("messageID")
      });
      _this
        .$axios({
          method: "post",
          url: "bigservers/see_leaving",
          data: postData,
          headers: {
            "Content-Type": "multipart/form-data"
          }
        })
        .then(res => {
          this.$message({
            message: "提交回复成功",
            type: "success",
            duration: 1000
          });
          _this.textarea = "";
          // _this.$router.push("/message");
          _this.$router.replace("/message");
           const timeA = setInterval(() => {
              location.reload();
            }, 1500);
        })
        .catch(error => {
          this.$message({
            message: "提交回复失败",
            type: "error",
            duration: 1000
          });
        });
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.get_boderHeight();
    let postData = this.$qs.parse({
      id: localStorage.getItem("messageID"),
      ret: ""
    });
    this.$axios({
      method: "post",
      url: "bigservers/check_leaving",
      data: postData,
      headers: {
        "Content-Type": "multipart/form-data"
      }
    })
      .then(res => {
        this.redata = res.data[0];
        //判断管理员是否回复
        if (res.data[0].store !== null) {
          this.textShow = true;
        } else if (res.data[0] === null) {
          this.textShow = false;
        }

         //判断当前账号是否是管理员
        if (localStorage.getItem("identity") === "A") {
          if (this.redata.store === null) {
            this.huifuShow = true;
          } else if (this.redata.store !== null) {
            this.huifuShow = false;
          }
        } else {
          this.huifuShow = false;
        }
      })
      .catch(error => {
        this.$message({
          message: "获取用户反馈详情失败",
          type: "error",
          duration: 1000
        });
      });
  }
};
</script>
<style lang='scss'>
@import "../../assets/scss/bus.scss";
@import "../../assets/scss/megXq.scss";
</style>