<template>
	<view class="page">
		<u-navbar :is-back="false" :title="tittxt" :border-bottom="false" :background="bgc" title-color='#000' title-size='36' height='50' >
			
		</u-navbar>
		<view class="imgbox">
			<image src="https://api.ccttiot.com/smartmeter/img/static/uGHvzVjLjHy3SGGFbD5C" mode=""></image>
		</view>
		<button class="button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"   >
			授权登录
		</button>
		<view class="tip">
			<!-- <image src="https://api.ccttiot.com/smartmeter/img/static/u4LEl3cUFgF9uN30ESnF" mode=""></image> -->
			<u-checkbox-group style="width: 40rpx;">
				<u-checkbox v-model="checked" active-color="#25CE88"></u-checkbox>
			</u-checkbox-group>
			我已同意并阅读《服务条款》《法律条款及隐私政策》
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				bgc: {
					backgroundColor: "#25CE88",
				},
				tittxt:"登录",
				chooseType:true,
				usertype:'',
				login:false,
				checked:false
			}
		},
		methods: {
			userType(num){
				this.chooseType=false
				this.login=true
				if(num==1){
					this.usertype='01'
				}else{
					this.usertype='00'
				}
			},
			getPhoneNumber(e) {
			    let that = this;
			    if(this.checked == false){
					uni.showToast({
						title: '请勾选服务条款以及隐私政策',
						icon: 'none',
						duration:2000
					})
				}else{
					const wxLoginAsync = () => {
					    return new Promise((resolve, reject) => {
					        wx.login({
					            success(res) {
					                if (res.code) {
					                    console.log('登录！', res);
					                    let data = {
											loginCode: res.code,
					                        mobileCode: e.detail.code,
					                    };
					                    resolve(data);
					                } else {
					                    reject(res.errMsg);
					                }
					            },
					            fail(err) {
					                reject(err);
					            }
					        });
					    });
					};
					wxLoginAsync()    
					    .then(async (data) => {
					        this.$u.post("/app/auth/wxLogin",data).then((res) => {
					        	if (res.code == 200) {
									uni.setStorageSync('token', res.token);
									that.ceshi()
					        	}
					        });
					       
					    })
					    .catch((err) => {
					        console.error(err);
					    });
				}

			},
			ceshi() {
				this.$u.get("/app/user/userInfo").then((res) => {
					console.log('进入跳转');
					uni.switchTab({
						url: '/pages/index/index'
					})
				});
			},
		}
	}
</script>

<style lang="scss" >
	/deep/ .u-title,
	/deep/ .uicon-nav-back {
		padding-bottom: 22rpx;
	}
	page{
		background: #E7F3E4;
	}
	.page {
		position: relative; /* 添加相对定位 */
	}

	.imgbox {
		margin:102rpx auto ;
		width: 730rpx;
		height: 600rpx;
		z-index: 0;

		image {
			width: 730rpx;
			height: 600rpx;
		}
	}
	.button{
		margin-top: 200rpx;
		width: 586rpx;
		height: 90rpx;
		background: #25CE88;
		border-radius: 54rpx 54rpx 54rpx 54rpx;
		font-weight: 500;
		font-size: 40rpx;
		color: #FFFFFF;
		line-height: 90rpx;
	}
	.tip{
		margin-top:30rpx ;
		display: flex;
		flex-wrap: nowrap;
		align-items: center;
		justify-content: center;
		font-weight: 400;
		font-size: 24rpx;
		color: #979797;
	}

	
</style>
