<template>
  <div class="news-container">
    <Head/>
    <second-banner
      :list = "bannerList"
      :looptime="looptime"
      :width="width"
      :height="height"
      :background="background"
      :color="color"
      class="mb-50"
      @prev="prev"
      @next="next"
      @change="changeBanner"
      @click="bannerClick"/>
    <ul
      v-if="dataDetail.length"
      id="scroll-area"
      class="main-padding">
      <router-link
        v-for="item in dataDetail"
        :to="{ path: 'newsDetail', query:{id: item.id }}"
        :key="item.id"
        class="flex-jcb"
        style="margin-bottom: 20px;">
        <img
          :src="item.coverImage"
          class="news-img-list">
        <div class="news-list">
          <div class="ellipsis2 news-list-title">{{ item.title }}</div>
          <!--<div class="ellipsis2 epitome">导语：{{ item.epitome }}</div>-->
          <div class="epitome news-list-time flex-aic">
            <img
              :src="item.coverImage"
              style="width: 17px;height: 17px;margin-right: 7px;">
            {{ item.addTime.substring(0, 10) }}</div>
        </div>
      </router-link>
    </ul>
    <p
      v-if="preventRepeatReuqest"
      class="loading">加载中……</p>
    <p
      v-if="touchend"
      class="empty_data">——共{{ totalCount?totalCount:0 }}篇新闻资讯——</p>
    <go-top/>
    <Footer v-if="touchend"/>
  </div>
</template>

<script>
  import config from "~/config";
  import Footer from "~/components/footer";
  import Head from "~/components/head";
  import axios from '../plugins/axios'
  import {
    mapGetters
  } from "vuex";
  import GoTop from "~/components/goTop";
  import SecondBanner from '~/components/secondBanner'
  export default {
    components: {
      Footer,
      Head,
      GoTop,
      SecondBanner
    },
    data(){
      return{
        showBanner: !0,
        touchend: false,////没有更多数据
        looptime: 4000, // 循环时间
        nodata: `${config.IMG_URL}nodata.png`,
        dataType: [],
        totalCount: "",
        dataDetail: [],
        width: 400,
        height:200,
        background: 'red',
        color: '#fff',
        fontSize: '70px',
        listQuery: {
          tagId: "",
          page: 1,
          limit: 10
        },
        store: "",
        dataNull:false,
        tourList: []
      };
    },
    computed: {
      ...mapGetters(["userInfo"])
    },
    created() {
      this.preventRepeatReuqest = true;
      window.addEventListener('scroll', this.handleScroll);
      this.getAll();
    },
    async asyncData() {
      const { data } = await axios.get('/api/app/banner/app/unauth/findBannerlist?type=5&platform=1');
      let cc = data.data;
      return { bannerList: cc}
    },
    methods: {
      chooseSelect(e) {
        console.log(e.target.value);
        this.listQuery.tagId = e.target.value;
        this.preventRepeatReuqest = true;
        this.getAll();
      },
      handleScroll: function () {
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        // 设备/屏幕高度
        let scrollObj = document.getElementById("scroll-area"); // 滚动区域
        if(scrollObj){
          let scrollHeight = scrollObj.scrollHeight; // 滚动条的总高度
          //滚动条到底部的条件
          if(document.documentElement.scrollTop + document.documentElement.clientHeight >= document.body.scrollHeight) {
            if (this.touchend) {
              return;
            }
            //防止重复请求
            if (this.preventRepeatReuqest) {
              return;
            }
            this.preventRepeatReuqest = true;
            //数据的定位加20位
            this.listQuery.page = this.currentPage + 1;
            this.getAll();
          }
        }
      },
      getAll() {
        let t = this;
        axios.get('/api/uccn/article/app/unauth/list?type=1&page='+this.listQuery.page+'&limit='+this.listQuery.limit)
          .then(function(response) {
            t.totalCount = response.data.data.total;
            let list = response.data.data.list;
            t.dataDetail = [...t.dataDetail, ...list];
            t.currentPage = response.data.data.pageNum;
            if (response.data.data.total < t.listQuery.limit*t.listQuery.page) {
              t.touchend = true;
            }
            t.preventRepeatReuqest = false;
          });
      },
      // 点击下一页回调
      prev () {},
      // 点击下一页回调
      next () {},
      // 鼠标移入状态点回调
      changeBanner () {},
      bannerClick () {},
    },
    head () {
      return {
        title: "欣新新闻|房车新闻|房车资讯|房车动态|房车市场信息|房车旅游动态|房车路线分享|房车新闻APP"
      }
    },
  };

</script>

<style lang="scss">
  @import "../assets/styles/mixin";
  .news-container{
    .news-img-list{
      width: 92px;
      height: 75px;
      border-radius: 3px;
    }
    .news-list {
      border-bottom: 1px solid #dfdfdf;
      width: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      margin-left: 13px;
      padding-bottom: 13px;
    }
    .news-list-title{
      margin-bottom: 15px;
      font-size: 15px;
    }
    .news-list-time{
      font-size: 13px;
      color: #999;
    }
  }
  .news-item{
    margin: 10px 0;
  }
  .tour-home-r, .news-home-r{
    width: 58%;
  }
  .tour-img-home, .news-home-img{
    width: px2rem(300px);
    height: px2rem(150px);
  }
</style>
