<template>
	<view>
		<image mode="widthFix" class="width100" :src="imagewxUrl+imgadres"></image>
		<view class="width100 height45l font14 fcor666 paddleft10 backcorfff">
			授权 <text class="font16 fcor333 fontwig6 sqjl">重庆嗨加油</text> 获取以下信息为您提供相关服务
		</view>
		<button class="width35 flleft mart40 height50 font16"
			style="margin-left: 10%;color: #5bbdd6;border: 1px solid #4992ee;" @click="backlatpage">暂不授权</button>
		<UPButton class="mart40 width35 height50 fcorfff backcor008 fotct btns font16 fontlet bornone flright"
			style="margin-right: 10%;" @click="btnClick" :scope="scope">
			确认授权
		</UPButton>


	</view>
</template>

<script>
	const app = getApp();
	import {
		GetPhoneNumber,
		unionPhoneLogin
	} from "../../Utils/Api.js"
	export default {
		name: 'App',
		data() {
			return {
				user: '',
				scope: "scope.mobile,scope.auth",
				imagewxUrl: app.globalData.imageWxImg,
				imgadres: 'loginunion.png',
				scope: "scope.mobile",
				code: ''
			}
		},
		onLoad() {
			this.user = app.globalData.userInfo;
		},
		methods: {
			btnClick(result) {
				this.code = result.code;
				if (result.code) {
					this.unionPhoneLogin(result.code)
				}
			},
			// 微信获取手机号
			unionPhoneLogin(item) {
				let params = {
					code: item
				}
				unionPhoneLogin(params).then(res => {
					if (res.return_code == '000000') {
						uni.showToast({
							title: '授权成功',
							icon: 'none',
							duration: 2000
						})
						this.user = res.return_data.object.highUser;
						app.globalData.token = res.return_data.uniqueCode;
						app.globalData.userInfo = res.return_data
							.object
							.highUser;
						uni.setStorage({
							key: "user",
							data: res.return_data
								.object
								.highUser
						})
						uni.setStorage({
							key: "token",
							data: res.return_data.uniqueCode
						})
						uni.navigateBack({})
					}
				});
			},
			//暂不授权
			backlatpage() {
				uni.navigateBack({})
			},
			getH5userinfo() {
				uni.navigateTo({
					url: '/pages/login/register?id=1'
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #efeff4;
	}

	.bacolorl {
		background: linear-gradient(to right, #408aea, #4890ee);
	}

	.unionimg {
		width: 200rpx;
		height: 200rpx;
	}

	.sqjl {
		padding-left: 5px;
		padding-right: 5px;
	}

	.btns {
		border-radius: 6px;
	}
</style>
