<template>
	<view class="common_download_page">
		<view class="page_content">
			<view class="bg_img">
				<image :src="config.download_bg_img" mode="aspectFill" class="width-100p height-100p"></image>
			</view>
			<view style="margin-top: 160rpx;">
				<image class="jc-image-160 block-center" :src="config.app_img" mode="aspectFill"></image>
				<view class="margin-top-40 text-center text-40 text-bold text-ff">{{config.app_name}}</view>
				<!-- <view >下载APP</view> -->
				<view
					class="margin-top-40 line-height-80 radius-40 block-center bg-main-gradient text-center text-28 text-ff"
					style="width: 50%;" @click="openApp">打开APP</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: "", //外链链接
				config: {},
				hasTurnPage: {}
			}
		},

		onReady() {
			this.rq.getData('project/api/Config/getAppDownloadConfig').then(res => {
				if (res.code === 0) {
					this.config = res.data.app_download
				}
			})

			let _this = this
			document.addEventListener('visibilitychange', () => {
				console.log('document hidden', document.hidden)
				//监听当前页面有没有被移到后台 true--被移到后台有跳转其他页面 fasle--没有被移到后台跳转其他页面
				_this.hasTurnPage = document.hidden

			})

		},

		methods: {
			openApp() {
				// 先打开scheme协议来唤起app，如果超时了（比如超时2s）那么就跳转到app下载页

				// let scheme = 'juchengtp://h5toapp?id=8' // scheme链接找客户端
				let scheme = 'https://tp-universal.jucheng01.net?id=8'
				try {
					console.log('openLocation跳转：', scheme)
					window.location.href = scheme
				} catch (e) {
					console.log('openLocation错误', e)
				}


				setTimeout(() => {
					// console.log('!state.hidden', !state.hidden)
					// 当前页面依然在说明没有下载App,所以跳转至商店下载
					if (!this.hasTurnPage) {
						if (this.cn.platform() == 'android') {
							console.log('安卓下载')
							//链接找安卓开发要
							window.location.href =
								'https://jucheng-app.oss-cn-qingdao.aliyuncs.com/ynxianhuaapp/__UNI__412EE24_0708180330.apk'
						} else if (this.cn.platform() == 'ios') {
							console.log('ios下载')
							// 链接找ios开发要
							window.location.href =
								'https://apps.apple.com/us/app/%E6%81%8B%E7%88%B1%E8%AF%9D%E6%9C%AF/id1608827634?l=zh'
						}
					}
				}, 2000)
			},
		}
	}
</script>

<style scoped>
	.bg_img {
		position: fixed;
		left: 0;
		top: 0;
		z-index: -1;
		width: 100%;
		height: 100%;
	}
</style>
