<template>
	<view class="container">
		<view class="logo"><image src="https://wx.fujinyangche.com/nvrnetwork/images/accredit_logo.png"></image></view>
		<!-- 横线 -->
		<view class="line"></view>
		<view class="title">申请获取以下权限</view>
		<view class="title title1">您暂未授权附近养车网获取你的信息，将无法正常使用小程序的功能，如需要正常使用，请点击"授权按钮"，打开头像昵称等信息的授权</view>
		<button class="login"  open-type="getUserInfo" @getuserinfo="getUserInfo">授权登录</button>
		<view class="no_login" @tap="navBack">取消</view>
	</view>
</template>

<script>
	let app = getApp();
	export default {
		data() {
			return {
				params:'',//接收路径传递过来的参数
			}
		},
		onLoad(options) {
			console.log(options);
			this.params = options.params;
		},
		methods: {
			//授权登陆
			getUserInfo(e){
				app.globalData.userInfo = e.detail.userInfo;
				uni.setStorageSync('userInfo',e.detail.userInfo);
				let pages = getCurrentPages();    //获取当前页面信息栈
				// let beforePage = pages[pages.length - 2];
				uni.login({
					success: (res) => {
						uni.request({
							url:'http://192.168.3.136/nvrnetwork/user',
							data:{
								code:res.code,
								nickName:e.detail.userInfo.nickName,
								img:e.detail.userInfo.avatarUrl
							},
							success: (res) => {
								console.log(res);
								let token = res.data.data.data;
								app.globalData.token = token;
								uni.setStorageSync('token',token);
								if(pages[0].route == 'pages/packageOne/service/serviceView/serviceView'){ //说明是从首页跳转过来
									uni.reLaunch({
										url:"/pages/packageOne/service/serviceView/serviceView?index=" + this.params
									})
								}else{
									uni.navigateBack({
										delta:1
									})
								}
								
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.container {
	  height: 100%;
	  display: flex;
	  flex-direction: column;
	  align-items: center;
	  justify-content: space-between;
	  padding: 200rpx 0;
	  box-sizing: border-box;
	  overflow: hidden;
	} 
	.logo{
	  width:138rpx;
	  height:138rpx;
	}
	.logo image{
	  display: block;
	  width:100%;
	  height:100%;
	}
	.line{
	  width:80%;
	  height:2rpx;
	  background-color: #000000;
	  margin-top:100rpx;
	}
	.title{
	  width:80%;
	  color:#333333;
	  font-size: 24rpx;
	  text-align: left;
	  margin-top:60rpx;
	}
	.title1{
	  margin-top:10rpx;
	}
	.login{
	  width: 574rpx;
	  height: 74rpx;
	  background:linear-gradient(270deg,rgba(254,107,21,1) 0%,rgba(254,163,48,1) 100%);
	  text-align: center;
	  line-height: 74rpx;
	  color:#ffffff;
	  font-size: 26rpx;
	  border-radius: 56rpx; 
	  margin-top:100rpx;
	}
	.no_login{
	  width: 574rpx;
	  height: 74rpx;
	  background-color: #ffffff;
	  color:#E77817;
	  text-align: center;
	  line-height: 74rpx;
	  font-size: 26rpx;
	  border-radius: 56rpx;
	  margin-top:40rpx;
	  border:1px solid rgba(231,120,23,1);
	}
</style>
