<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<image class="topbg" src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/994d4d1a-8655-4105-8857-d3a783486d5f.png" mode="widthFix"></image>
		<div class="content adffcacjc">
			<button class="zt_btn" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">快速登录</button>
			<div class="agree adfacjc" @tap="changeAgree">
				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/6a4d6238-f4aa-4c19-82ec-70829c2898b1.png" v-if="!agree"></image>
				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/03/adcda2a2-8e59-4b01-8e6a-e1e575bbc15d.png" v-else></image>
				<div class="a_text">已阅读并同意 <span>《用户协议》</span><span>《隐私政策》</span></div>
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				agree:false
			}
		},
		methods:{
			changeAgree(){
				this.agree = !this.agree;
			},
			decryptPhoneNumber(e){
				if(!this.agree) return this.$showToast('请勾选协议和政策');
				if(e.detail.code) this.wxLogin(e.detail.code);
			},
			wxLogin(code){
				uni.showLoading({ title:'登录中' });
				let that = this;
				wx.login({
					success(res){
						that.$api.get('/sys/wx/login',{
							code:res.code,
							phoneCode:code
						},false).then(res=>{
							if(res.data.code===0){
								uni.setStorageSync('token',res.data.data.token);
								uni.setStorageSync('userInfo',JSON.stringify({
									id:res.data.data.id,
									mobile:res.data.data.mobile,
									username:res.data.data.username
								}));
								
								uni.hideLoading();
								that.$showToast('登录成功');
								setTimeout(()=>{
									uni.reLaunch({ url:'/pages/home' })
								},1500)
							}else that.$showToast(res.data.msg)
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page{
		background: #FFFFFF;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		
		.topbg{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;
		}
		
		
		.content{
			position: relative;
			display: flex;
			flex: 1;
			width: calc(100% - 140rpx);
			margin: 307rpx 70rpx 0;
			
			.agree{
				margin-top: 50rpx;
				&>image{
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
				}
				.a_text{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #A6A6A6;
					line-height: 33rpx;
					span{
						color: #72832B;
					}
				}
			}
		}
	}
</style>