<template>
	<!-- <view v-if="config"><view @click="goDownload()">去下载</view></view> -->
	<view v-if="config" style="overflow: hidden;margin-bottom: 20rpx;min-height: 100vh;">
		<view v-if="isWeixn">
			<image class="guide-image" src="../../static/openGuide.png"></image>
			<view class="ceng"></view>
		</view>

		<view>
			<view class="logo-box">
				<view class="logo-image"><image :src="config.CONFIG_PROJECT_LOGO"></image></view>
				<view class="logo-text">{{ config.CONFIG_PROJECT_TITLE }}</view>
			</view>
			<view class="download-btn" @click="goDownload()">下载</view>
		</view>

		<view class="gary-text footer-bar">
			<view>
				<text style="margin-right: 10rpx;" @click="jump('/pages/userAgreement/index?appId=' + appId)">服务协议</text>
				和
				<text style="margin-left: 10rpx;" @click="jump('/pages/privacyAgreement/index?appId=' + appId)">隐私政策</text>
			</view>
			<view>{{ config.CONFIG_RECORD_NUMBER }}</view>
		</view>
	</view>
</template>

<script>
const req = require('../../utils/request.js');
const util = require('../../utils/util.js');
export default {
	data() {
		return {
			isWeixn: false, //判断是否在微信环境 true不在，false在
			appId: '', //
			config: ''
		};
	},

	onLoad(opt) {
		this.appId = opt.appId;
		this.isWeixn = this.is_weixn();
		this.getConfig();
	},

	methods: {
		jump(url) {
			uni.navigateTo({
				url: url
			});
		},
		getConfig() {
			req.getRequest(
				'/api/config',
				this.appId,
				{},
				data => {
					this.config = data;
				},
				true
			);
		},

		// 去下载
		goDownload() {
			if (this.isWeixn) {
				//在微信环境
				this.showModal('请点击右上角“...”按钮, 选择在浏览器打开');
			} else {
				var u = navigator.userAgent;
				var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
				var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
				// 这里是iOS浏览器
				if (isIOS) {
					if (this.config.download_app_ios_url) {
						window.location.href = this.config.download_app_ios_url; // 跳AppStore下载地址
					} else {
						this.showModal('后台暂未开放IOS App版本下载');
					}
				} else {
					if (this.config.download_app_android_url) {
						window.location.href = this.config.download_app_android_url; // 跳AppStore下载地址
					} else {
						this.showModal('后台暂未开放Android App版本下载');
					}
				}
			}
		},

		// 是微信浏览器
		is_weixn() {
			var ua = navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				return true;
			} else {
				return false;
			}
		},

		/**
		 * 是否为Pc版本
		 */
		isPC() {
			var userAgentInfo = navigator.userAgent;
			var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
			var flag = true;
			for (var v = 0; v < Agents.length; v++) {
				if (userAgentInfo.indexOf(Agents[v]) > 0) {
					flag = false;
					break;
				}
			}
			return flag;
		},

		showModal(msg) {
			uni.showModal({
				title: '提示',
				content: msg,
				confirmText: '关闭',
				showCancel: false,
				success(res) {}
			});
		}
	}
};
</script>

<style>
@import './index.css';
</style>
