<template>
  <div class="activity-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"
      type="1"
      style="padding-top: 0;"
      class="main-padding">
      <li
        v-for="item in dataDetail"
        :key="item.id">
        <router-link
          :to="{ path: 'activityDetail', query:{id: item.id }}"
          class="activity-item">
          <img
            :src="item.banner"
            :alt = "item.title"
            style="border-radius: 3px 3px 0 0;">
          <div class="activity-item-d">
            <div class="ellipsis2 activity-item-title">{{ item.title }}</div>
            <div class="activity-time">{{ item.startTime | formatDate('yyyy-MM-dd hh:mm') }}</div>
            <div class="activity-addr flex-aic">
              <img
                :src="item.banner"
                :alt = "item.title"
                style="width: 10px;height: 13px;margin-right: 5px;">
              {{ item.province }}{{ item.city }}{{ item.town }}{{ item.address }} </div>
          </div>
        </router-link>
      </li>

    </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 SecondBanner from '~/components/secondBanner'
  import {
    mapGetters
  } from "vuex";
  import GoTop from "~/components/goTop";
  export default {
    components: {
      Footer,
      Head,
      SecondBanner,
      GoTop
    },
    data(){
      return{
        showBanner: !0,
        looptime: 4000, // 循环时间
        touchend: false,////没有更多数据
        nodata: `${config.IMG_URL}nodata.png`,
        dataType: [],
        totalCount: "",
        dataDetail: [],
        width: 400,
        height:200,
        background: 'red',
        color: '#fff',
        fontSize: '70px',
        listQuery: {
          page: 1,
          limit: 10
        },
        store: "",
        dataNull:false,
        tourList: [],
        currentPage: 1,//当前加载页
        preventRepeatReuqest: false, //到达底部加载数据，防止重复加载
      };
    },
    computed: {
      ...mapGetters(["userInfo"])
    },
    created() {
      // handleScroll为页面滚动的监听回调
      window.addEventListener('scroll', this.handleScroll);
      this.preventRepeatReuqest = true;
      this.getAll();
    },
    async asyncData() {
      //车型banner 0：首页，1：旅游 2：营地 3：房车 4：活动 5：新闻 6：关于欣新
      let tempBannerData = await axios.get( '/api/app/banner/app/unauth/findBannerlist?type=4&platform=1');
      let banner = tempBannerData.data.data;
      return { bannerList: banner}
    },
    methods: {
      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;
            this.listQuery.page = this.currentPage+1;
            this.getAll();
          }
        }
      },
      getAll() {
        let t = this;
        axios.get('/api/uccn/summitActivity/app/unauth/list?page='+this.listQuery.page+'&limit='+this.listQuery.limit)
          .then(function(response) {
            t.totalCount = response.data.data.totalCount;
            let list = response.data.data.data;
            t.dataDetail = [...t.dataDetail, ...list];
            t.currentPage = response.data.data.pageNum;
            if (response.data.data.totalCount < t.listQuery.page*t.listQuery.limit) {
              t.touchend = true;
            }
            t.preventRepeatReuqest = false;
          });
      },
      // 点击下一页回调
      prev () {},
      // 点击下一页回调
      next () {},
      // 鼠标移入状态点回调
      changeBanner () {},
      bannerClick () {},
    },
    head () {
      return {
        title: "欣新活动|欣新沙龙|欣新高峰论坛|欣新论坛|欣新俱乐部|欣新展会|欣新活动直播链接|欣新活动APP"
      }
    },
  };

</script>

<style lang="scss">
  @import "../assets/styles/mixin";
  .activity-container{
    .activity-item{
      margin: 10px 0;
    }
    #scroll-area li{
      box-shadow: 2px 3px 13px rgba(153,153,153,0.2);
      margin: 17px 0;
      border-radius: 3px;
    }
    .activity-item-d{
      padding: 14px 10px;
    }
    .activity-item-title{
      font-size: 14px;
      font-weight: bold;
    }
    .activity-time{
      margin: 10px 0;
      font-size: 12px;
      color: #666;
    }
    .activity-addr{
      font-size: 12px;
      color: #999;
    }
  }
</style>
