<template>
	<view>
		<yomol-upgrade :type="upgradeType" :url="upgradeUrl" title="发现新版本" :content="upgradeContent" ref="yomolUpgrade"></yomol-upgrade>
		<button class="tui-button-primary tui-btn-submit" hover-class="tui-button-hover" @tap="checkVersionClick">登录</button>
	</view>
</template>

<script>
	import yomolUpgrade from '@/components/yomol-upgrade/yomol-upgrade.vue'
	export default {
		components:{
			yomolUpgrade
		},
		data() {
			return {
				upgradeType: 'pkg', //pkg 整包 wgt 升级包
				upgradeContent: '11111', //更新内容
				upgradeUrl: '', //更新地址
			}
		},
		methods: {
			/*
			* 检测版本升级
			*/
			async checkVersionClick() {
					var platform = uni.getSystemInfoSync().platform
					//根据当前平台去后台检测版本号
					//这是我的逻辑，可自定义
					var res = await  getApp().globalData.request.post("user/version",{
						platform: platform,
						uid: this.$store.state.openid
					});
					console.log(res);
					if (res.code && res.code == 200 && res.data.update) {

							//我的后台会返回一个安装包地址（pkgUrl），升级包地址（wgtUrl）
							//判空来判断是非是整包升级还是资源包升级
							//content是版本更新内容 \n换行
							//ios用户pkgUrl是苹果市场App地址，android自定义下载地址
							if (res.data.pkgUrl != '' && res.data.wgtUrl == '') {
								this.upgradeType = 'pkg'
								this.upgradeContent = res.data.content
								this.upgradeUrl = res.data.pkgUrl
								console.log(this.upgradeUrl);
								this.$refs.yomolUpgrade.show()
							} else {
								this.upgradeType = 'wgt'
								this.upgradeContent = res.data.content
								this.upgradeUrl = res.data.wgtUrl
								this.$refs.yomolUpgrade.show()
							}
					} else {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					}
			},
		}
	}
</script>
<style lang="scss">
page {
	width: 100%;
	height: 100%;
	background-color: $uni-bg-color;
}
.container {
	width: 100%;
	height: 100%;
	background-color: $uni-bg-color;

	.tui-box {
		position: fixed;
		width: 100%;
		top: 50%;
		padding: 0 45rpx;
		margin-top: -50rpx;
		box-sizing: border-box;
		text-align: center;

		.tui-text {
			font-size: $uni-font-size-base;
			color: $uni-text-color;
			padding-top: 18rpx;
		}
	}
}
</style>
