<template>
	<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
		:duration="duration">
		<swiper-item v-for="(bannerItem,index) in carouselList" :key="index">
			<!-- <uni-link :href="bannerItem.destinationAddress?bannerItem.destinationAddress:'#'"> -->
			<image :src="bannerItem.filePath" mode="widthFix" @click="jumpUrl(bannerItem.destinationAddress)"></image>
			<!-- </uni-link> -->
		</swiper-item>
	</swiper>
</template>

<script>
	import {shareURL} from "@/environments/environment";
	export default {
		props: ['carouselList'],
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
			}
		},
		name: 'carousel',
		components: {},
		mounted() {
			
		},
		methods: {
			jumpUrl(url) {
				if (!url) {
					return false
				} else {
					const match = url.match(/fileId=([^&]*)/);
					const fileId = match ? match[1] : null;
					uni.navigateTo({
							url: `/pages/courseDetail/courseDetail?fileId=${fileId}`
						})
					// 原来的跳转逻辑，不明白为啥这样跳
					// let index = url.indexOf(`${shareURL}/pages/`);
					// if (index != -1) {
					// 	uni.navigateTo({
					// 		url: url.substring(index + 16, url.length)
					// 	})
					// } else {
					// 	// #ifdef H5
					// 	window.location.href = url;
					// 	// #endif
					// 	// #ifdef APP-PLUS
					// 	uni.navigateTo({
					// 		url: '/components/webview?url=' + url
					// 		// page.json定义的路径 传url 到webview界面去接收 实现跳转
					// 	})
					// 	//#endif
					// }
					
				}
			}

		}
	}
</script>

<style lang="scss">
	.swiper {
		height: 300rpx;
	}
</style>