<template>
  <div id="carousel-example-generic" class="carousel slide banner" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#carousel-example-generic" v-for="(item, index) in bannerList" :data-slide-to="index" :class="index==0 ? 'active' : ''"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item" v-for="(item, index) in bannerList" :key="item.ptsid" :class="index==0 ? 'active' : ''">
        <router-link :to="formatUrl(item)" :target="item.lurl ? '_blank' : ''" v-if="item.url || item.lurl">
          <img :src="item.pic" :alt="item.title">
        </router-link>
        <img :src="item.pic" :alt="item.title" v-else>
        <div class="carousel-caption">
        </div>
      </div>
    </div>
    <!---->
    <!-- Controls -->
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <!-- <span class="sr-only">Previous</span> -->
    </a>
    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right"></span>
      <!-- <span class="sr-only">Next</span> -->
    </a>
  </div>
</template>
<script>
// import autofit from 'autofit.js'
// import Swiper from 'swiper'
// import 'swiper/css/swiper.css'
import { mapGetters, mapActions } from 'vuex'

export default {
  data() {
    return {
      swiper: ''
    }
  },
  
  computed: {
    ...mapGetters([
      'bannerList'
    ])
  },

  created() {
    /* 获取轮播图，最多显示5张 */
    this.getBanners({
      limit: 5,
      orderField: 'sort'
    })
  },
  mounted() {
    // this.$nextTick(() => {
    //   this.initSwiper()
    // })
  },
  methods: {
    ...mapActions({
      getBanners: 'app/getBannerList'
    }),

    formatUrl(el) {
      return el.lurl ? el.lurl : el.url ? `${el.url}/${el.ptsid}` : ''
    }
  }
}
</script>
<style scoped>
.swiper {
  /* height: 100%; */
  margin-bottom: 30px;
  overflow: hidden;
}
</style>
