<template>
  <div class="mianBox">
    <van-row class="contentBox">
		<van-row>
			<van-col span="24" class="logo"><van-image width="75" height="75" :src="require('../img/logo.png')" /></van-col>
			<van-col span="24" class="authorized_app">申请获取以下权限</van-col>
			<van-col span="24" class="authorized_text">获取你的昵称、头像、地区及性别</br>
			（用于园区内一卡通余额充值）</van-col>
		</van-row>
		<div class="authorize_wrap">
			<van-button class="authorize authorize_y"  color="#F22E3C"   open-type="getUserInfo" lang="zh_CN" @getuserinfo="checkLogin" >授权登录</van-button>
		</div>
		<van-toast id="van-toast" />
	</van-row>
  </div>
</template>
<script>
	import Toast from '../../wxcomponents/vant/weapp/dist/toast/toast';
	export default {
		
		data() {
			return {
				data:{
					money:undefined,
					openid:undefined,
				},
				
			}
		},
		onLoad(options) {
			let _this = this
			// money=${this.money}&scene=3&userId=${localStorage.getItem("user_wt")}&channelId=null&openid=null
			let data = JSON.parse(options.params)
			_this.data = data
		},
		methods: {
			checkLogin(e){
				let _this = this
				if(e.detail.userInfo) {
					uni.login({
						success: function(res) {
							if(res.code){
								uni.setStorage({
								   key: 'code', 
								   data: res.code, 
								})
							}
							uni.request({
								// url:  `http://172.16.120.104:8085/wxLogin?jsCode=${res.code}`,
								url:  `https://smartpark.caih.com/dxapi/wxLogin?jsCode=${res.code}`,
								method: 'GET',
								// header: {
								//     'content-type': 'application/x-www-form-urlencoded'
								// },
								success: function (res2) {
									uni.setStorage({
									   key: 'openid', 
									   data: res2.data.data, 
									   success: function () {
											_this.data.openid= res2.data.data
											uni.navigateTo({
											    url: `../order/index?params=${JSON.stringify(_this.data)}`
											});
									   }
									})
									
								}
							})
						},
					})
				}else{
				  //console.log('拒绝授权')
				  uni.navigateTo({
				      url: '../index/index'
				  });
				}
			},
		}
	}
</script>
<style lang="scss" scoped>
.mianBox{
    height: 100%;
    width: 100%;
    color: #000;
    padding-top: 20px;
    box-sizing: border-box;
    .contentBox{
		width: 100%;
		height: auto;
		padding: 15px 20px;
		box-sizing: border-box;
		overflow: hidden;
		.logo{
			/deep/ .van-image{
				margin:0 auto;
				display: block;
			}
		}
		.authorized_app{
			text-align: center;
			color: #000;
			display: block;
			/deep/ .van-col{
				font-size: 30rpx;
				font-weight: 700;
				margin-top:30px;
			}
		}
		.authorized_text{
			width:80%;
			margin-left:10%;
			display: block;
			text-align: center;
			line-height: 30px;
			color: #777;
			/deep/ .van-col{
				font-size: 30rpx;
				margin-top: 20px;
			}
		}
		/deep/ .van-button{
			border-radius: 6px;
			width: 100% !important;
			margin-top:25px;
			letter-spacing: 2px;
			font-size: 18px;
			height: 50px;
		}
		.authorize_wrap{
			width:95%;
			margin:70px 2.5% 0;
			.authorize{
				height: 50px;
				font-size: 18px;
				border-radius: 10px;
				margin-top:40px;
			}
		}
    }
}
</style>

