<template>
	<view>
		<image src="../../static/bg.png" mode="" class="bg"></image>
		<!-- <button   @click="getUserProfile">登录</button> -->
		<view class="" style="margin: 72rpx auto 40rpx;width: 610rpx;padding-top: 300rpx;">
			<u-button @click="getUserProfile" text="授权登录"  shape="circle" color="linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%)"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.gologin()
		},
		data() {
			return {
				
			}
		},
		methods: {
			gologin(){
							uni.login({
								provider: 'weixin',
								success: (res) => {
									
								},
								fail: () => {
									uni.showToast({
										title: "微信登录授权失败",
										icon: "none"
									});
								}
							})
			},
			getUserProfile(){
				var that=this
				uni.getUserProfile({
					desc:'获取微信用户的昵称与头像',
					success:function(resp){
						// that.authorization=false
						// that.userInfo=resp.userInfo
						uni.login({
							success(re) {
								uni.$u.http.post('/api/login/wechat_login',{code:re.code,rawData:resp.rawData}).then(res => {
									uni.setStorageSync('token',res.data.token)
									if(res.data.vip_level==1){
										uni.switchTab({
											url:'../index/index'
										})
									}else{
										uni.switchTab({
											url:'../auth/auth'
										})
									}
									
								})
								
							}
						})
					}								
				})
			}
		}
	}
</script>

<style>
page{
	
}
</style>
