<template>
	<view class="startPage">
		<image v-if="adverPic" @click="toShow" :src="'http://172.16.1.159:9200/api/file/pub/' + adverPic " mode="" alt="" :style="{width: '100vw',height: '100vh'}"></image>
		<image v-if="!adverPic && lan == 'zh'"  src="@/static/img/index/guideAD.png" mode="" alt="" :style="{width: '100vw',height: '100vh'}"></image>
		<image v-if="!adverPic && lan == 'en'"  src="@/static/img/index/guideAD.png" mode="" alt="" :style="{width: '100vw',height: '100vh'}"></image>
		<!-- <image src="@/static/img/index/guideAD.png" mode="widthFix" alt="" width="100%"></image> -->
	</view>
</template>

<script>
	export default {
		name:'startPage',
		data() {
			return {
				time:5,
				adverPic:'',
				QHeight:0,
				lan:this.$i18n.locale,
				linkTo:'',
				adverId:'',
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success:(res)=>{
					let height = res.windowHeight - uni.upx2px(0);
					this.QHeight = height
				}
			})
			let timeS = this.time;
			this.QTime(timeS)
			this.getAdver()
		},
		methods: {
			QTime(timeS){
				let timeStart = setInterval(function(){
					timeS --;
					if(timeS == 0){
						clearInterval(timeStart);
						uni.switchTab({
							url:"./index"
						})
					}
					console.log(timeS);
				},1000,timeS)
			},
			async getAdver(){
				let params = {
					position:'mobile_open',
					language:this.$i18n.locale
				}
				const res = await this.$myRequest({
					url: '/op/advertisementLocations/getAppAdvert',
					data: {
						...params
					}
				});
				let addver = res.data[0].list
				for(let i = 0;i < addver.length ;i++){
				  if(this.$i18n.locale == addver[i].languageDict){
					  this.adverPic = addver[i].advPicUrl;
					  this.linkTo = addver[i].advPicLink;
					  this.adverId = addver[i].id
					  break
				  }else{
					   this.adverPic = '';
					   this.linkTo = '';
				  }
				}
			},
			toShow(){
				this.getClickNumber()
				if(this.linkTo){
					plus.runtime.openURL(this.linkTo)
				}else{
					return
				}	
			},
			//点击广告次数记录增加
			async getClickNumber(){
				let res = await getApp().$myRequest({
					url:'/op/advertisementLocations/getAppAdvert',
					data:{
						position:'mobile_send',
						advId:this.adverId 
					}
				})	
			}
		}
	}
</script>

<style scoped>
	body{
		width: 100%;
		height: 100%;
	}
	.startPage{
		width: 100%;
		height: 100%;
		position: absolute;
		z-index: 999;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		
	}

</style>
