<template>
	<view class="app">
		<image src="@/static/logo.png" mode=""></image>
		<!-- <view class="title">
			新医路健康服务平台
		</view> -->
	</view>
</template>

<script>
	import {
		createMobileToken
	} from '@/api/pages/login/index.js'
	export default {
		data() {
			return {};
		},
		//1.分享给朋友
		onShareAppMessage(res) {
			let pages = getCurrentPages();
			let url = pages[pages.length - 1].$page.fullPath
			return {
				title: '新医路健康服务平台',
				path: url,
			}
		},
		//2.分享到朋友圈
		onShareTimeline(res) {
			let pages = getCurrentPages();
			let url = pages[pages.length - 1].$page.fullPath
			return {
				title: '新医路健康服务平台',
				path: url,
			}
		},
		onLoad(query) {
			// // scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
			// const scene = decodeURIComponent(query.scene)
			// if (scene >= 0) {
			// 	uni.setStorageSync("invitationPatientId", scene)
			// }
		},
		onShow() {
			var that = this
			if (!uni.getStorageSync('location') && !uni.getStorageSync('region')) {
				this.getAddress()
			}
			// this.getAddress();
			createMobileToken().then(res => {
				uni.setStorageSync("token", res.data.token)
			})
			setTimeout(() => {
				uni.reLaunch({
					url: '/pages/homepage/homepage'
				});
			}, 2000);
		},
		methods: {
			//获取当前位置
			getAddress() {
				let that = this;
				uni.getLocation({
					type: 'wgs84',
					success: (res) => {
						let location = res.latitude + ',' + res.longitude
						//调用逆解析接口
						uni.request({
							url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=location', //腾讯官方逆解析接口，可直接复制
							data: {
								location: location,
								'key': "Q4DBZ-UIMC2-B63UX-CUZ6A-S3UT7-TBF3V", //自己申请的Key
							},
							method: "GET",
							success(res) {
								uni.setStorageSync('location', res.data.result.address_component.city)
							},
							fail: res => {
								console.log(res.errMsg, '解析失败返回的错误信息');
							}
						})
					},
					//失败
					fail: (res) => {
						uni.showToast({
							icon: 'none',
							title: '获取地址失败,请打开定位',
						})
					}
				})
			},
		},
	}
</script>

<style lang="scss">
	.app {
		height: 100vh;
		background-color: #fff;
	}

	image {
		width: 50%;
		height: 400rpx;
		position: absolute;
		left: 25%;
		top: 28%;
	}

	.title {
		width: 80%;
		height: 48rpx;
		font-size: 49rpx;
		text-align: center;
		font-family: DengXian;
		font-weight: bold;
		color: #000000;
		position: absolute;
		top: 50%;
		left: 10%;
	}
</style>