<template>
  <div class="banner" :class="'terminal' + terminal">
    <swiper class="swiper" :circular="true" :indicator-dots="false" :autoplay="true" :style="{'height':bannerHeight + 'rpx'}" @change="swiperChange">
      <swiper-item class="banner-item" v-for="(item,index) in bannerList" :key="index" :style="{backgroundImage: 'url('+ item.imageUrl +')'}"  @click="jumpLink(item.jumpUrl)">
        <div class="a-link" @click="jumpLink(item.jumpUrl)"><img class="img" :src="item.imageUrl" v-show="item.imageUrl" mode="widthFix"></div>
      </swiper-item>
    </swiper>
    <view class="swiper-dots" v-if="bannerList && bannerList.length > 1">
      <text class="dot" :class="index === swiperCurrent  && 'dot-active'" v-for="(dot, index) in bannerList.length"
            :key="index"></text>
    </view>
  </div>
</template>

<script>
  import {funMixin} from '../config/mixin';
  const API = require('../../../config/api')
  const NET = require('../../../utils/request')
  export default {
    name: 'cereBanner',
    mixins: [funMixin],
    data () {
      return {
        bannerHeight: 0,
        swiperCurrent: 0,
		bannerList:[]
			  }
    },
    props: {
      terminal: {
        type: Number,
        default: 4
      },
      componentContent: {
        type: Object
      }
    },
    mounted() {
		let pagesize = {
			pageNumber: 1,
			pageSize: 10,
			}
		NET.request2(API.cereCarouselImage, pagesize, 'POST').then(res => {
			console.log('11111111111111',res)
			this.bannerList  = res.data.content
			
		})
		// uni.request({
		//     url: 'http://8.130.38.56:8027/admin-server/cereCarouselImage/queryByPage', //仅为示例，并非真实接口地址。
		//     data: {
		//        pageNumber: 1, 
		//        pageSize: 10
		//     },
		//     header: {
		//         'content-type': 'application/json;charset=UTF-8' //自定义请求头信息
		//     },
		//     success: (res) => {
		//         console.log(res.data);
		      
		//     }
		// });

      this.bannerHeight = this.componentContent.height
      this.$forceUpdate() // 刷新轮播图
    },
    // computed: {
    //   bannerList: function () {
    //     console.log(this.componentContent)
    //     return this.componentContent.bannerData.filter(function (item) {
    //       return item.bannerUrl
    //     })
    //   }
    // },
    methods:{
		jumpLink(urls){
			if(urls){
					window.open(urls, '_blank');
			}else{
				uni.navigateTo({
					url: '/pages_category_page1/goodsModule/goodsList'
				});
			}
			
		
			// uni.navigateBack({
			//   url: urls
			// });
		},
      swiperChange(e) {
        this.swiperCurrent = e.detail.current;
      }
    }
  }
</script>

<style lang="scss" scoped>
.banner{
  position: relative;
  margin-top: 20rpx;
  margin-bottom: 20rpx;
  .banner-item{
    width: 100%;
    background-repeat: no-repeat;
    background-position: center;
    background-size: auto 100%;
    img{
      display: none;
    }
  }
  &.terminal4{
    ::v-deep .el-carousel{
      height: 100%;
      .el-carousel__container{
        height: 100%;
      }
    }
    .banner-item{
      background-repeat: no-repeat;
      background-position: center;
      background-size: auto 100%;
      img{
        display: none;
      }
    }
  }

  .swiper-dots {
    display: flex;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 20upx;
    z-index: 200;
    .dot {
      width: 12upx;
      height: 12upx;
      background: #FFFFFF;
      border-radius: 6upx;
      opacity: 0.2;
      margin: 0 10upx;
    }

    .dot-active {
      opacity: 1;
      width: 24upx;
    }
  }

}
</style>
