<template>
	<view>
		<view>
			<swiper class="swiper-box" :autoplay="autoplay" :interval="interval" :duration="duration" :indicator-dots="indicatorDots">
				<swiper-item v-for="(item, index) in banner" :key="index">
					<cover-image class="img" @click="linkTo(item)" :src="item.bannerImg"></cover-image>
				</swiper-item>
			</swiper>
		</view>
		
		<view>
			<uni-list v-for="(item, index) in user" :key="index">
					<uni-list-item v-bind:title="item" clickable  @click="getUser(item)"></uni-list-item>
			</uni-list>
		</view>
	</view>
</template>

<script>
	import {getBannerList} from '@/api/creator.js' 
	export default {
		data() {
			return {
				banner: [],
				autoplay: true,
				interval: 2000,
				duration: 500,
				indicatorDots: true,
				user:['Kim','Jim','Bob']
			}
		},
		onLoad() {
			this.getBanner();
		},
		methods: {
			linkTo(item){
				console.log(item.bannerImg)
				uni.showModal({
					content: '跳转啦', 
					showCancel: false
				});
			},
			getUser(item){
				console.log(item);
			},
			async getBanner(){
				const res = await getBannerList()
				if(res.data.code === 200){
					console.log('相應結果2',res);
					this.banner = res.data.data
				}else{
					uni.showModal({
						content: 'banner加载失败！', 
						showCancel: false
					});
				}
			}
		}
	}
</script>

<style scoped>
	.swiper-box {
		height: 100px;
		border: 2rpx solid #18BC37;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 200px;
		color: #fff;
	}

	.img {
		position: absolute;
		width: 100%;
		height: 100%;
	}
</style>
