<template>
	<view>
		<view class="uni-margin-wrap" v-if="list.length>0">
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval">
					<swiper-item v-for="(item,index) in list" :key="index">
						<view class="content " @click="clickImg(item)">
							<image class="image " :src="item.imageUrl"></image>
							<view  class="number-box">
								<text class="number">{{ index + 1 }}/{{ list.length }}</text>
							</view>
						</view>
					</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>

	import {getAdsList} from '@/api/home.js';
	export default {
		name: "my-swiper",
		props: {
			autoplay: {
				type: Boolean,
				default () {
					return true
				},
			},
			interval: {
				type: Number,
				default () {
					return 3000
				},
			},
			indicatorDots: { //是否显示面板指示点
				type: Boolean,
				default () {
					return false
				},
			},

			type: {
				type: Number,
				default () {
					return -1
				},
			},
		},
		data() {
			return {
				list:[],
			};
		},
		created(){
			this.getAdsList(this.type);
		},

		methods:{
			clickImg(item){
				console.log("点击了广告图片",item)
				//跳转到某个页面，路劲由后端配置
				if (item.skipType === 2){//跳转到文章链接
					uni.navigateTo({
						url: '/pages/groupbuying/article/article?id='+item.dataId
					});
				}
				if (item.skipType === 3){ //跳转到团购详情链接
					uni.navigateTo({
						url: item.targetUrl
					});
				}

			},
			getAdsList(type){
				getAdsList({
					type : type
				}).then(res => {
					this.list=res.data;
				})
			}
		}
	}
</script>

<style>
	.uni-margin-wrap {
		width: 750rpx;
		height: 420rpx;
	}

	.swiper {
		height: 420rpx;
	}

	.image{
		width: 100%;
		height: 100%;
	}
	.content{
		width: 750rpx;
		height: 420rpx;
		position: relative;
	}
	.number-box{
		background-color: rgba(0, 0, 0, 0.3);
		border-radius: 6px;
		padding: 2rpx 12rpx 2rpx 12rpx;
		position: absolute;
		left: 10rpx;
		top: 10rpx;
	}

	.number{
		overflow-wrap: break-word;
		color: rgba(255, 255, 255, 1);
		font-size: 20rpx;
		font-weight: NaN;
		text-align: center;
		white-space: nowrap;
		line-height: 28rpx;
	}
	.bord{
		border: 1px solid red;
	}
</style>
