<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/05/29/b1d0d573-3a9d-4a08-8f0f-592bbab5a731.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/05/29/e2c98493-2b1a-4138-aa7e-2b2a0be3abf3.png" v-if="!agree"></image>
				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/05/29/720de1ea-0c99-4cf3-b728-50674303f952.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>