<template>
	<view class="page" :style="{'min-height':h+'px'}">
		<view class="box">
		<!-- 	<image src="https://i.ringzle.com/file/20240109/d6c4691423cf40c2bdf9210d389cdd1e.png"></image>
			<view class="text">您好！欢迎使用<br>游嵊泗商家服务平台</view> -->
			<!-- <view class="" @click="aa()">核销</view> -->
			<view class="login">
				<button open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">授权手机号登录</button>
			</view>
		</view>
	</view>
</template>
 
<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad() {
			uni.clearStorageSync();
		},
		methods: {
			aa(){
				uni.reLaunch({
					url:"/pagesHouse/hexiao/index"
				})
			},
			//获取手机号进行登录
			decryptPhoneNumber(e){
				if(e.detail.code) this.wxLogin(e.detail.code);
			},
			//登录
			wxLogin(code){
				uni.showLoading({ title:'登录中' });
				let that = this;
				wx.login({
					success(res){
						that.$api.post('/auth/oauth/token',{
							code:res.code,
							phoneCode:code,
							grant_type:'merchantWeChat',
							captcha:'aaa'
						},false).then(result=>{
							if(result.data.code===0){
								uni.setStorageSync('authorization',result.data.token_type+' '+result.data.access_token);
								uni.setStorageSync('access_token',result.data.access_token);
								that.$api.get('/sys/user/info').then(resu=>{
									if(resu.data.code===0){
										that.$showToast('登录成功');
										uni.setStorageSync('userInfo',resu.data.data);
										setTimeout(()=>{
											uni.reLaunch({
												url:'/pages/login/select?userInfo='+encodeURIComponent(JSON.stringify(resu.data.data))
											})
										},1500)
									}else that.$showToast(resu.data.msg)
								})
							}else that.$showToast(result.data.msg)
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		background: url(https://i.ringzle.com/file/20240523/474a7a2656cb499d851cf7665f9d7d6a.png) no-repeat;
		background-size: 100% 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		.box{
			width: calc(100% - 180rpx);
			display: flex;
			flex-direction: column;
			align-items: center;
			image{
				width: 480rpx;
				height: 520rpx;
			}
			.text{
				text-align: center;
				font-size: 56rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 800;
				color: #FFFFFF;
				line-height: 96rpx;
			}
			.login{
				margin-top: 780rpx;
				width: 100%;
				height: 96rpx;
				button{
					width: 100%;
					height: 100%;
					background: #1372FF;
					border-radius: 48rpx 48rpx 48rpx 48rpx;
					line-height: 96rpx;
					text-align: center;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
			}
		}
	}
</style>