<template>
	<view class="containers">
		<div class="bg" style="background: url('/static/download/appeq_bg.png') no-repeat center bottom / cover;"></div>

		<view class="content">
			<image class="logo" src="/static/download/appLogo.png"></image>
			<view style="font-size: 40rpx;margin-top: 22rpx;color: #FFFFFF;font-weight: bold;">斯耀短剧APP</view>
			<view style="font-size: 28rpx;margin-top: 16rpx;color: #FFFFFF;font-weight: bold;">海量电子榨菜  免费又过瘾</view>
			<button class="confirm-btn" @click="download">{{data.confirmBtn}}</button>
			
		</view>
		
		<!-- #ifdef H5 -->
		<div v-if="data.isWeixin" style="width: 100%;height: 100%;position: absolute;top: 0;background: url('/static/download/open_guide.png') no-repeat center bottom / cover;"></div>
		<!-- #endif -->
	</view>
</template>

<script setup>
	import { reactive } from 'vue';
	import { onLoad} from '@dcloudio/uni-app'
	import { commonType } from '@/api/init.js';
	
	let data = reactive({
		openShare: false,
		openShares: false,
		confirmBtn: '斯耀短剧APP',
		isWeixin: false,
	})
	
	onLoad(() => {
		let u = navigator.userAgent;
		if ( u.indexOf('iPhone') > -1) {
			// #ifdef H5
			data.confirmBtn = "跳转网页版首页"
			// #endif
		}
		
		if ( u.toLowerCase().indexOf('micromessenger') !== -1) {
			data.isWeixin = true
		}
	})
	
	
	function download() {
		var u = navigator.userAgent;
		if (u.indexOf('Android') > -1 || u.indexOf('Adr') > -1) {
			commonType(49).then(res => {
				if (res.code === 0) {
					if (res.data && res.data.value) {
						// #ifndef H5
						plus.runtime.openURL(res.data.value, function(res) {
							
						});
						// #endif
						// #ifdef H5
						uni.setClipboardData({
							data: res.data.value,
							success: r => {
								// this.$queue.showToast('邀请码复制成功');
								uni.showToast({
									title: '邀请码复制成功',
									icon: 'none',
								});
							}
						});
						window.location.href = res.data.value;
						// #endif
					}
				}
			});
		} else {
			commonType(50).then(res => {
				if (res.code === 0) {
					if (res.data && res.data.value) {
						// #ifndef H5
						plus.runtime.openURL(res.data.value, function(res) {
							
						});
						// #endif
						// #ifdef H5
						uni.setClipboardData({
							data: res.data.value,
							success: r => {
								uni.showToast({
									title: '邀请码复制成功',
									icon: 'none',
								});
							}
						});
						
						uni.switchTab({
							url: '/pages/index/index'
						})
						// window.location.href = res.data.value;
						// #endif
					}
				}
			});
		}
	}
</script>

<style lang="scss" scoped>
	uni-page-body{
		width: 100%;
		height: 100%;
	}
	.containers {
		width: 100%;
		height: 100%;
		.bg{
			width: 100%;
			height: 85%;
			position: absolute;
		}
		.content{
			position: relative;
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			.logo{
				width: 124rpx;
				height: 124rpx;
				margin-top: -920rpx;
				border-radius: 20rpx;
			}
		}
	}

	.confirm-btn {
		width: 416rpx;
		height: 90rpx;
		line-height: 90rpx;
		background: #FD5775;
		color: #fff;
		font-size: 32rpx;
		font-weight: bold;
		font-size: 32rpx;
		color: #FFFFFF;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 70rpx;
		margin: auto;
	}
</style>