<template>
	<view>
		<view class='header'>
			<image src='../../static/logo.png'></image>
		</view>

		<view class='content'>
			<view>申请获取以下权限</view>
			<text>获得你的公开信息(昵称，头像等)</text>
		</view>

		<button class='bottom' type='primary' open-type="getUserInfo" @getuserinfo="bindGetUserInfo">
			授权登录
		</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad(){
			uni.getSetting({
			   success(res) {
			     if(res && res.authSetting['scope.userInfo']){
					uni.getUserInfo({
						provider: 'weixin',
						success:function(infoRes) {
							  wx.login({
								success: res => {
									console.log("用户的code:" + res.code);
								}
							});
						}
					})
				 }else{
					uni.switchTab({url: '/pages/device/device'})
				 }
			   }
			})
		},
		methods: {
			 bindGetUserInfo(e) {
			        if (e.detail.userInfo) {
			            //用户按了允许授权按钮
			            var that = this;
			            // 获取到用户的信息了，打印到控制台上看下
			            console.log("用户的信息如下：");
			            console.log(e.detail.userInfo);
						uni.switchTab({url: '/pages/device/device'})
			        } else {
			            //用户按了拒绝按钮
			            uni.showModal({
			                title: '警告',
			                content: '您点击了拒绝授权，将无法进入小程序，请授权之后再进入!!!',
			                showCancel: false,
			                confirmText: '返回授权',
			                success: function(res) {
			                    // 用户没有授权成功，不需要改变 isHide 的值
			                    if (res.confirm) {
			                        console.log('用户点击了“返回授权”'); 
			                    }
			                }
			            });
			        }
			    }
		}
	}
</script>

<style scoped>
.header {
    margin: 90rpx 0 90rpx 50rpx;
    border-bottom: 1px solid #ccc;
    text-align: center;
    width: 650rpx;
    height: 300rpx;
    line-height: 450rpx;
}

.header image {
    width: 200rpx;
    height: 200rpx;
}

.content {
    margin-left: 50rpx;
    margin-bottom: 90rpx;
}

.content text {
    display: block;
    color: #9d9d9d;
    margin-top: 40rpx;
}

.bottom {
    border-radius: 80rpx;
    margin: 70rpx 50rpx;
    font-size: 35rpx;
}
</style>
