<template>
	<view class="addialog" v-if="show">
		<swiper indicator-dots style="height:60%;margin:0 10%;width:80%">
			<swiper-item v-for="(item, index) in ads.list" :key="index">
				<image mode="aspectFit" :src="item.picUrl" width="100%" @click="clickHandler(item.link.url)" style="height:100%" />
			</swiper-item>
		</swiper>
		<view class="close">
			<u-icon name="close" color="#000" size="56" @click="closeHandler" />
		</view>
	</view>
</template>
<script>
	export default {
		props: ["ads"],
		data() {
			return {
				show: false
			};
		},
		created() {
			if (this.ads.times == 1) {
				let showedAd = uni.getStorageSync('showedAd') ? uni.getStorageSync('showedAd') : []
				let isExsit = false
				showedAd.forEach(x => {
					if (x.toString() == this.ads.list.toString()) {
						isExsit = true
						return false
					}
				})
				if (isExsit) {
					this.closeHandler()
				} else {
					showedAd.push(this.ads.list)
					uni.setStorageSync("showedAd", showedAd);
					this.show = true
				}
			} else {
				this.show = true
			}
		},
		methods: {
			clickHandler(e) {
				if (e.currentTarget.dataset.url && e.currentTarget.dataset.url != "") {
					uni.navigateTo({
						url: e.currentTarget.dataset.url
					});
				}
			},
			closeHandler() {
				this.show = false
			}
		}
	};
</script>

<style>
	.addialog {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		top: 0;
		background: rgba(0, 0, 0, 0.5);
		display: flex;
		align-items: center;
		z-index: 999999999;
	}

	.addialog .close {
		position: absolute;
		bottom: 14%;
		left: 50%;
		margin-left: -14px;
	}
</style>