<!--  -->
<template>
  <div class="authenticate_box" :style="'height:' + fullHeight + 'px'">
    <!-- 头部 -->
    <div class="authenticate_headrBox">
      <div class="authenticate_divBox">
        <img
          src="../../assets/image/new/30.png"
          alt
          class="authenticate_headrBox-img"
          @click="goBack()"
        />
        <div class="authenticate_headrBox-tlt">鉴定</div>
        <img
          @click="newAuthenticate()"
          src="../../assets/image/new/14.png"
          alt
          class="authenticate_headrBox-img"
        />
      </div>
    </div>

    <!-- 主内容 -->
    <mescroll-vue
      ref="mescroll"
      class="home_box_mescroll"
      :down="mescrollDown"
      :up="mescrollUp"
      @init="mescrollInit"
    >
      <div
        class="authenticate_box_main"
        v-loading="loading"
        element-loading-text="拼命加载中"
      >
        <!-- <mescroll-vue
        ref="mescroll"
        class="home_box_mescroll"
        :down="mescrollDown"
        :up="mescrollUp"
        @init="mescrollInit"
      > -->
        <ul class="authenticate_box-main-authenticateUl" v-if="interflowShow">
          <li
            class="authenticate_box-main-authenticateList"
            v-for="(item, index) in interflowDat"
            @click="authenticateDetails(item.id)"
            :key="index"
          >
            <div class="authenticate_box-main-authenticateList-box1">
              <img
                preview="1"
                v-lazy="'http://192.168.1.8:8002/' + item.img[0]"
                alt
                class="authenticate_box-main-authenticateList-box1-img"
              />
              <div class="authenticate_box-main-authenticateList-box1-txt">
                {{ item.problem }}
              </div>
            </div>

            <div class="authenticate_box-main-authenticateList-box2">
              <div class="authenticate_box-main-authenticateList-box3">
                <img
                  preview="1"
                  v-lazy="'http://192.168.1.8:8002/' + item.photo"
                  alt
                  class="authenticate_box-main-authenticateList-box3-img"
                />
                <div class="authenticate_box-main-authenticateList-box3-name">
                  {{
                    item.user_remark == "" || item.user_remark == null
                      ? item.username
                      : item.user_remark
                  }}
                </div>
              </div>
              <img
                src="../../assets/image/new/10.png"
                alt
                class="authenticate_box-main-authenticateList-box4-img"
              />
            </div>
          </li>
        </ul>

        <!-- 暂空判断 -->
        <div class="collect_judge" id="empty" v-else>
          <img src="../../assets/image/wu.png" alt class="collect_judge_img" />
          <div class="collect_judge_text">抱歉，暂无鉴定</div>
        </div>
        <!-- </mescroll-vue> -->
      </div>
    </mescroll-vue>
  </div>
</template>

<script>
// 引入mescroll的vue组件
import MescrollVue from "mescroll.js/mescroll.vue";
export default {
  name: "authenticate",
  components: {
    MescrollVue,
  },
  data() {
    //这里存放数据
    return {
      fullHeight: document.documentElement.clientHeight, //自适应高度
      activeName: "second", //tab切换交流、鉴定、方案
      // 交流
      interflowShow: true, //暂无数据
      interflowDat: [], //交流列表数据
      isClick: true, //点赞开关
      amplificationShow: false, //查看大图
      imgList: "",
      // 上拉加载下拉刷新
      mescroll: null, // mescroll实例对象
      mescrollDown: {}, //下拉刷新的配置. (如果下拉刷新和上拉加载处理的逻辑是一样的,则mescrollDown可不用写了)
      mescrollUp: {
        // 上拉加载的配置.
        callback: this.upCallback, // 上拉回调,此处简写; 相当于 callback: function(page, mescroll) { }
        //以下是一些常用的配置,当然不写也可以的.
        page: {
          num: 0, //当前页 默认0,回调之前会加1; 即callback(page)会从1开始
          size: 6, //每页数据条数,默认10
        },
        isBounce: true, //根据记录的滚动条高度回弹
        htmlNodata: '<p class="upwarp-nodata">-- 已经到底了! --</p>',
        noMoreSize: 6, //如果列表已无数据,可设置列表的总数量要大于5才显示无更多数据;
        // 避免列表数据过少(比如只有一条数据),显示无更多数据会不好看
        // 这就是为什么无更多数据有时候不显示的原因
        toTop: {
          //回到顶部按钮
          src:
            "http://pic.51yuansu.com/pic3/cover/00/65/23/5896fa4bc81fc_610.jpg", //图片路径,默认null,支持网络图
          offset: 500, //列表滚动1000px才显示回到顶部按钮
        },
        onScroll: function (mescroll, y, isUp) {
          //吸顶
          // if (y > 500) {
          //   self.navBarFixed = true;
          // } else {
          //   self.navBarFixed = false;
          // }
        },
        lazyLoad: {
          use: true, // 是否开启懒加载,默认false
        },
      },
      aggregate: "", //后端传来数据的总条数
      loading: true,
      // 上拉加载下拉刷新
    };
  },
  beforeRouteEnter(to, from, next) {
    if (from.name === "addData_details") {
      to.meta.isBack = true;
    }
    // 如果没有配置顶部按钮或isBounce,则beforeRouteEnter不用写
    next((vm) => {
      if (from.name === "addData_details") {
        // 滚动到原来的列表位置,恢复顶部按钮和isBounce的配置
        vm.$refs.mescroll && vm.$refs.mescroll.beforeRouteEnter();
      }
    });
  },
  beforeRouteLeave(to, from, next) {
    if (to.name !== "addData_details") {
      to.meta.isBack = false;
    } else {
      to.meta.isBack = true;
      // 如果没有配置顶部按钮或isBounce,则beforeRouteLeave不用写
      // 记录列表滚动的位置,隐藏顶部按钮和isBounce的配置
      this.$refs.mescroll && this.$refs.mescroll.beforeRouteLeave();
    }
    next();
  },
  activated() {
    if (!this.$route.meta.isBack) {
      // 如果isBack是false，表明需要获取新数据，否则就不再请求，直接使用缓存的数据
      this.mescroll.resetUpScroll(); // 刷新列表数据
    }
    // 恢复成默认的false，避免isBack一直是true，导致下次无法获取数据
    this.$route.meta.isBack = 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;
        })();
      };
    },

    // mescroll组件初始化的回调,可获取到mescroll对象
    mescrollInit(mescroll) {
      this.mescroll = mescroll; // 如果this.mescroll对象没有使用到,则mescrollInit可以不用配置
    },

    upCallback(page, mescroll) {
      var that = this;
      that
        .$axios({
          method: "get",
          url: "http://192.168.1.8:8002/user_answer",
          params: {
            page: that.mescrollUp.page.num,
            ret: "all", //区别是全部还是个人
            diverse: "0", //鉴定
          },
          headers: {
            "Content-Type": "multipart/form-data",
          },
        })
        .then((res) => {
          var nums = res.data.num;
          that.aggregate = nums;
          if (this.aggregate === "") {
            //存变量
            this.aggregate = nums;
            var b = "6";
            this.aggregate = this.aggregate / b;
            this.aggregate = Math.ceil(this.aggregate); //将小数点转换为整数
          }
          if (res.data.num !== 0) {
            // var data = res.data.dat;
            var arrA = [];
            for (var i = 0; i < res.data.dat.length; i++) {
              var obj = {};
              obj["exist"] = res.data.dat[i].exist;
              obj["id"] = res.data.dat[i].id;
              obj["img"] = res.data.dat[i].img;
              obj["like_num"] = res.data.dat[i].like_num;
              obj["photo"] = res.data.dat[i].photo;
              obj["problem"] = res.data.dat[i].problem;
              obj["reply_num"] = res.data.dat[i].reply_num;
              obj["time"] = res.data.dat[i].time;
              obj["user_remark"] = res.data.dat[i].user_remark;
              obj["visit_num"] = res.data.dat[i].visit_num;
              if (res.data.dat[i].username !== "admin") {
                // 1字符串转化成数组
                let phoneArr = [...res.data.dat[i].username];
                var n = "";
                // 2.将数组中的4-7位变成*
                phoneArr.map((res, index) => {
                  if (index > 2 && index < 7) {
                    n += "*";
                    // return '*';
                  } else {
                    n += res;
                  }
                });
                // console.log(n)
                obj["username"] = n;
              } else {
                obj["username"] = res.data.dat[i].username;
              }
              arrA.push(obj);
            }
            var data = arrA;
            console.log(data);

            // that.interflowDat = [];
            // 如果是第一页需手动置空列表
            if (page.num === 1) this.interflowDat = [];
            // 把请求到的数据添加到列表
            this.interflowDat = this.interflowDat.concat(data);

            // 数据渲染成功后,隐藏下拉刷新的状态
            this.$nextTick(() => {
              mescroll.endSuccess(data.length);
            });
            that.interflowShow = true;
            that.loading = false;
          } else if (res.data.num === 0) {
            this.gerenShow = false;
            that.interflowShow = false;
          }
        })
        .catch((err) => {
          mescroll.endErr();
          console.log(err);
        });
    },

    // 返回
    goBack() {
      var that = this;
      that.$router.replace("/home");
    },

    // 鉴定列表接口
    // interflowData() {
    //   var that = this;
    //   that
    //     .$axios({
    //       method: "get",
    //       url: "http://192.168.1.8:8002/user_answer",
    //       params: {
    //         page: 1,
    //         ret: "all", //区别是全部还是个人
    //         diverse: "0", //鉴定
    //       },
    //       headers: {
    //         "Content-Type": "multipart/form-data",
    //       },
    //     })
    //     .then((res) => {
    //       if (res.data.num !== 0) {
    //         var data = res.data.dat;
    //         that.interflowDat = [];
    //         that.interflowDat = data;
    //         that.interflowShow = true;
    //       } else if (res.data.num === 0) {
    //         this.gerenShow = false;
    //         that.interflowShow = false;
    //       }
    //     })
    //     .catch((err) => {
    //       console.log(err);
    //     });
    // },

    //  点击进入鉴定详情
    authenticateDetails(id) {
      var that = this;
      that.$router.push({
        name: "addData_details",
        query: {
          id: id, //id
          ret: "authenticate",
          // visit_num: visit_num, //查看
          // replys: replys, //评论
          // like: like, //点赞状态
          // like_num: like_num, //点赞次数
        },
      });
      // that.$router.push({
    },
    //点击进入新建鉴定页面
    newAuthenticate() {
      this.drawer = false;
      // this.$router.push("/fieldsShow");
      this.$router.push({
        name: 'fieldsShow',
        query: {
          ret: '2'
        }
      });
    },

    //点击轮播图片进行放大
    imgShow(img) {
      this.amplificationShow = true;
      this.imgList = img;
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
    this.get_boderHeight(); //动态获取浏览器高度
    // this.interflowData(); //鉴定列表接口
  },
};
</script>
<style lang='scss'>
.el-popup-parent--hidden {
  overflow: auto;
}

@import "../../assets/scss/bus.scss";

// 盒子
.authenticate_box {
  // border: 1px solid #000;
  background: #f7f8fc;
}

// 头部
.authenticate_headrBox {
  background: -webkit-linear-gradient(right, #0dc6b6, #0cd3aa, #1dd69c);
  position: fixed;
  width: 100%;
  z-index: 100;
}

.authenticate_divBox {
  display: flex;
  justify-content: space-between;
  width: 90%;
  margin: 0 0 0 0.5rem;
}

.authenticate_headrBox-tlt {
  text-align: center;
  font-size: 18px;
  color: #fff;
  padding: 8px 0 8px 0;
}

.authenticate_headrBox-img {
  width: 0.5rem;
  height: 0.5rem;
  vertical-align: middle;
  margin-top: 0.3rem;
}

// tab切换交流、鉴定、方案
.authenticate_box_main {
  // border: 1px solid #000;
  background: #f7f8fc;
  height: 100%;
  padding: 1rem 0 0 0;
}
.authenticate_box_main,
.swiper-container-autoheight,
.swiper-container-autoheight .swiper-slide {
  height: 100%;
}
.authenticate_box_main .navlist {
  background: #fff;
}
.authenticate_box_main .navlist ul {
  border-bottom: 1px solid #e9e9e9;
  display: flex;
  justify-content: space-between;
}

.authenticate_box_main .navlist .activeT {
  border-bottom: 1px solid #1ec8a1;
  color: #1ec8a1;
}

.navli .navliVal {
  padding: 10px 35px 10px 35px;
  font-size: 15px;
}

// 交流页面
.authenticate_box_main-ulA {
}

.authenticate_box_main-listA {
  // border: 1px solid #1ec8a1;
  background: #fff;
  padding-top: 0.25rem;
}

// 用户信息
.authenticate_box_main-listA-userBox {
  // border: 1px solid #000;
  display: flex;
  width: 95%;
  margin: 0 auto;
}

.authenticate_box_main-listA-userBox-img {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 25px;
}

.authenticate_box_main-listA-userBox-txt {
  margin: 0 0 0 12px;
}

.authenticate_box_main-listA-userBox-name {
  font-size: 15px;
  text-align: left;
  line-height: 30px;
}

.authenticate_box_main-listA-userBox-time {
  color: #acacac;
  font-size: 12px;
  text-align: left;
  line-height: 10px;
}

// 交流内容-文字
.authenticate_box_main-listA-writing {
  // border: 1px solid #000;
  width: 95%;
  margin: 10px auto;
  text-align: left;
  text-indent: 2em;
}

// 交流图片
.authenticate_box_main-listA-image {
  // border: 1px solid #000;
  width: 95%;
  margin: 0 auto;
}

.authenticate_box_main-listA-image-ul {
  // border: 1px solid #000;
  display: flex;
  flex-wrap: wrap;
}

.authenticate_box_main-listA-image-list {
  // border: 1px solid #000;
}

.authenticate_box_main-listA-imageList {
  width: 2.8rem;
  height: 3.5rem;
  margin: 0.24rem 0.14rem 0 0.15rem;
}

// 交流数据的查看评论点赞
.authenticate_box_main-listA-operation {
  border-top: 1px solid #e8e8e8;
  margin: 0.25rem auto;
  width: 90%;
  padding-bottom: 0.25rem;
}

.authenticate_box_main-listA-operation-ul {
  margin-top: 0.35rem;
  display: flex;
  justify-content: space-between;
}

.authenticate_box_main-listA-operation-list {
  display: flex;
}

.authenticate_box_main-listA-operation-listImg {
  width: 0.5rem;
  height: 0.5rem;
}

.authenticate_box_main-listA-operation-listNum {
  font-size: 15px;
  line-height: 0.55rem;
  text-align: left;
  margin: 0 0 0 0.15rem;
  color: #989898;
}

// 鉴定
.authenticate_box-main-authenticateUl {
  // border: 1px solid #000;
  width: 95%;
  margin: 0.25rem auto;
  display: flex;
  flex-wrap: wrap;
}

.authenticate_box-main-authenticateList {
  border: 1px solid #fff;
  background: #fff;
  width: 45%;
  margin: 0.2rem 0 0 0.2rem;
  border-radius: 5px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.authenticate_box-main-authenticateList-box1 {
  // border: 1px solid #000;
  width: 95%;
  margin: 0.1rem auto;
  border-radius: 5px;
}

.authenticate_box-main-authenticateList-box1-img {
  // width: 4.5rem;
  width: 100%;
  height: 3rem;
  border-radius: 5px;
}

.authenticate_box-main-authenticateList-box1-txt {
  font-size: 13px;
  color: #686565;
  text-align: left;
}

.authenticate_box-main-authenticateList-box2 {
  border-top: 1px solid #e9e9e9;
  display: flex;
  justify-content: space-between;
  width: 95%;
  margin: 0.25rem auto;
  padding: 0.25rem 0 0 0;
}

.authenticate_box-main-authenticateList-box3 {
  // border: 1px solid red;
  display: flex;
}

.authenticate_box-main-authenticateList-box3-img {
  width: 1rem;
  height: 1rem;
  vertical-align: middle;
  border-radius: 25px;
}

.authenticate_box-main-authenticateList-box3-name {
  font-size: 13px;
  line-height: 1.2rem;
  text-align: left;
  margin-left: 0.25rem;
}

.authenticate_box-main-authenticateList-box4-img {
  width: 0.8rem;
  height: 0.8rem;
  margin-top: 0.15rem;
}

// 方案
.authenticate_box-main-authenticateUlA {
  // border: 1px solid #000;
  width: 98%;
  margin: 0.25rem auto;
  display: flex;
  flex-wrap: wrap;
}

.authenticate_box-main-authenticateListA {
  border: 1px solid #fff;
  background: #fff;
  width: 47%;
  margin: 0.2rem 0 0 0.2rem;
  border-radius: 5px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.authenticate_box-main-authenticateListA-box1 {
  // border: 1px solid #000;
  width: 100%;
  // margin: .1rem auto;
  border-radius: 5px;
}

.authenticate_box-main-authenticateListA-box1-img {
  // width: 4.5rem;
  width: 100%;
  height: 3rem;
  border-radius: 5px 5px 0 0;
}

.authenticate_box-main-authenticateListA-box1-txt {
  font-size: 12px;
  color: #686565;
  text-align: left;
  // border: 1px solid #000;
  padding: 0.25rem 0.15rem 0.25rem 0.15rem;
}
.authenticate_box-main-authenticateListA-box1-num {
  text-align: right;
  color: #acacac;
}

// 新建弹出菜单
.authenticate_main-drawerUl {
  // margin: -13% 0 0 0;
  margin: 2% 0 0 0;
}
.authenticate_main-drawerList {
  text-align: center;
  border-bottom: 1px solid #ececec;
  font-size: 15px;
  color: #919191;
  padding: 0.15rem 0 0.15rem 0;
}
.el-drawer__open .el-drawer.btt {
  border-radius: 20px 20px 0 0;
  height: 15% !important;
}

// 暂空处理
.collect_judge {
  margin: 45% 0 0 0;
}

.collect_judge_img {
  margin: 0 auto;
}

.collect_judge_text {
  font-size: 25px;
  color: #bfbfbf;
  margin: 0.5rem 0 0 0;
  text-align: center;
}
</style>