<template>
  <div class="indexfind">
    <indexfindhead @serch="serch"></indexfindhead>
    <div class="tab">
      <indexfindtab @changeno="getno"></indexfindtab>
    </div>
    <div class="all" v-if="no==0">
      <div class="all1" v-for="(i,j) in list" :key="j" @click="todetail(i.id,i.type)">
        <indexfindall :title="i.title" :num="i.comment" :content="i.text" :right="'http://lawpro.earnest.pro/'+i.avatar"></indexfindall>
      </div>

      <div style="width:100%;height:0.5rem;text-align:center;line-height:0.3rem">{{text}}</div>
      <!-- <div class="all1">
    <indexfindall title="学法律后，对你最大的影响或改变是什么？"  num="1532"  :right="pics"></indexfindall>
      </div>-->
    </div>
    <div class="user" v-if="no==2">
      <div class="user1" v-for="(i,j) in list" :key="j">
        <indedfinduser
          :answer="i.answer"
          :article="i.article"
          :attention="i.attention"
          :username="i.topic_name"
          :pic="'http://lawpro.earnest.pro/'+i.img"
        ></indedfinduser>
      </div>

      <div style="width:100%;height:0.5rem;text-align:center;line-height:0.3rem">{{text}}</div>
      <!-- <div class="user1">
    <indedfinduser></indedfinduser>
  </div>
    <div class="user1">
    <indedfinduser></indedfinduser>
  </div>
    <div class="user1">
    <indedfinduser></indedfinduser>
      </div>-->
    </div>
    <div class="user" v-if="no==5">
      <div class="user1" v-for="(i,j) in list" :key="j">
        <!-- klmklvnklnkvl -->
        <!-- <indedfinduser :username="i.topic_name" :pic="'http://lawpro.earnest.pro/'+i.img"  :desc="i.text"  :ifnum="false" v-if="i.img"></indedfinduser> -->
        <indedfinduser
          :username="i.nickname"
          :pic="'http://lawpro.earnest.pro/'+i.avatar"
          :desc="i.text"
          :ifnum="false"
        ></indedfinduser>
      </div>

      <div style="width:100%;height:0.5rem;text-align:center;line-height:0.3rem">{{text}}</div>
      <!-- <div class="user1">
    <indedfinduser></indedfinduser>
      </div>-->
      <!-- <div class="user1">
    <indedfinduser></indedfinduser>
      </div>-->
    </div>
  </div>
</template>

<script>
import indexfindhead from "./components/indexfindhead";
import indexfindtab from "./components/indexfindtab";
import indexfindall from "./components/indexfindall";
import pics from "./assets/ad.png";
import indedfinduser from "./components/indexfinduser";
export default {
  components: {
    indexfindhead,
    indexfindtab,
    indexfindall,
    indedfinduser
  },
  mounted() {
    this.getlist1()
  },  
  watch: {
    no() {
      this.page = 0;
      this.dynamiclist = [];
      this.list = [];
      this.lock = false;
      // this.getlist1();
      this.text="加载中"
    }
  },
  beforeRouteLeave(a, b, c) {
    window.$(window).scroll(() => {});
    c();
  },
  methods: {
    getlist1(){
          let t=this;
          t.list=[]
      t.axios
        .post("http://lawpro.earnest.pro/api/login_main/indexsearch", {
          where: t.$route.query.word,
          type: t.no,
        }).then((res)=>{
          if(res.data.data){
         
            t.list=res.data.data
            window.console.log(t.list.length,"hfihaifohog")
            if(t.list.length<5){
              t.text="暂无数据"
            }
            window.$(window).scroll(() => {
            var windowH = window.$(window).height(); //设备可见区域高度
            var documentH = window.$(document).height(); //整个网页的高度（包括未显示的部分）
            var scrollH = window.$(window).scrollTop(); //滚动条滚动上去的高度
            //或者  scrollH = $(document).scrollTop();
            if (windowH + scrollH >= documentH) {
              // do something
              // alert(2);
              window.console.log(1);
              t.getlist();
            }
          });
            
          }else{
            window.console.log("errir")
            t.text="暂无数据"
          }
          
          
        })
    },
    getlist() {
      if (this.lock) {
        return "lock";
      }
      this.lock = true;
      var t = this;
      t.page += 1;
      t.axios
        .post("http://lawpro.earnest.pro/api/login_main/indexsearch", {
          where: t.$route.query.word,
          type: t.no,
          page: t.page
        })
        .then(res => {
          window.console.log(res);
          if (res.data.code == 200) {
            if(res.data.data){
            t.list = t.list.concat(res.data.data);

            }
            t.lock = false;
               window.$(window).scroll(() => {
            var windowH = window.$(window).height(); //设备可见区域高度
            var documentH = window.$(document).height(); //整个网页的高度（包括未显示的部分）
            var scrollH = window.$(window).scrollTop(); //滚动条滚动上去的高度
            //或者  scrollH = $(document).scrollTop();
            if (windowH + scrollH >= documentH) {
              // do something
              // alert(2);
              window.console.log(1);
              t.getlist();
            }
          });
          } else {
            t.text = "暂无更多";
          }
          // t.list=res.data.data
        });

    },
    getno(e) {
      window.console.log(e);
      this.no = e;
      this.list = [];
      this.getlist1()
      window.console.log(this.list.length,"list")
    },
    todetail(e, type) {
      window.console.log(e);
      if (type == 2) {
        this.$router.push({
          path: `/IndexArticleDetaill?id=` + e
        });
      } else {
        this.$router.push({
          path: `/articledetail?id=` + e
        });
      }
    },
    serch(e) {
      this.$router.push({
        path: `/indexfind?word=` + e
      });
      // let t=this;
      // window.console.log(e)
      //   t.axios.post("http://lawpro.earnest.pro/api/login_main/indexsearch", {where:e,type:this.no}).then((res)=>{
      //       //   window.console.log(res)
      //       //           for(let i in res.data.data){
      //       //   res.data.data[i].avatar=  res.data.data[i].avatar.substr(1)
      //       //    res.data.data[i].avatar= "http://lawpro.earnest.pro/"+res.data.data[i].avatar
      //       // }
      //       //   t.list=res.data.data
          //    if (res.data.code == 200) {
          //   t.list = res.data.data;
          //   window.$(window).scroll(() => {
          //     var windowH = window.$(window).height(); //设备可见区域高度
          //     var documentH = window.$(document).height(); //整个网页的高度（包括未显示的部分）
          //     var scrollH = window.$(window).scrollTop(); //滚动条滚动上去的高度
          //     //或者  scrollH = $(document).scrollTop();
          //     if (windowH + scrollH >= documentH) {
          //       // do something
          //       // alert(2);
          //       window.console.log(1);
          //       t.getlist();
          //     }
          //   });
          // } else {
      //       t.text = "暂无数据";
      //     }
      //       })
      //  t.axios.post("http://lawpro.earnest.pro/api/login_main/indexsearch", {where:e,type:0}).then((res)=>{
      //         window.console.log(res)
      //                 for(let i in res.data.data){
      //         res.data.data[i].avatar=  res.data.data[i].avatar.substr(1)
      //          res.data.data[i].avatar= "http://lawpro.earnest.pro/"+res.data.data[i].avatar
      //       }
      //         t.list=res.data.data
      //       })

      //   t.axios.post("http://lawpro.earnest.pro/api/login_main/indexsearch", {where:e,type:2}).then((res)=>{
      //         window.console.log(res)
      //                 for(let i in res.data.data){
      //         res.data.data[i].img=  res.data.data[i].img.substr(1)
      //          res.data.data[i].img= "http://lawpro.earnest.pro/"+res.data.data[i].img
      //       }
      //         t.list3=res.data.data
      //       })
      //           t.axios.post("http://lawpro.earnest.pro/api/login_main/indexsearch", {where:e,type:5}).then((res)=>{
      //         window.console.log(res)
      //                 for(let i in res.data.data){
      //         res.data.data[i].avatar=  res.data.data[i].avatar.substr(1)
      //          res.data.data[i].avatar= "http://lawpro.earnest.pro/"+res.data.data[i].avatar
      //       }
      //         t.list2=res.data.data
      //       })
    }
  },
  data() {
    return {
      pics,
      no: 0,
      list: [],
      list1: [],
      list2: [],
      list3: [],
      page: 0,
      lock: false,
      text: "加载中"
    };
  }
};
</script>

<style lang="scss">
body {
  background-color: #f6f6f6;
}
.tab {
  margin-top: 89px;
  // margin-bottom: 15px;
}
.all {
  .all1 {
    margin-top: -33px;
  }
}
.user1 {
  margin-top: 20px;
}
</style>