<template>
	<view class="bg">
		<view class="p">
			<image src="https://chenglantimes.com/prod-api/profile/upload/2024/06/04/1717472782145.jpg" class="pic" mode="widthFix"></image>
		</view>
		<view class="xy">
			<u-checkbox-group class="checkbox" v-model="item.checked">
				<u-checkbox size="15" shape="circle" label="我已阅读并同意" labelSize="14" name="true"></u-checkbox>
			</u-checkbox-group>
			<text class="a" @click="go('/pages/other/agreement?title=用户协议')">《用户协议》</text>
			<text>和</text>
			<text class="a" @click="go('/pages/other/agreement?title=隐私政策')">《隐私政策》</text>
		</view>
		<button class="btn" @click="getUserProfile()" :disabled="disabled">微信一键登录</button>
	</view>
</template>
<script>
export default {
	data() {
		return {
			item: {},
			disabled: false //防止重复点击
		};
	},
	methods: {
		getUserProfile() {
			let rule = [{ name: 'checked', checkType: 'notnull', errorMsg: '请同意并勾选协议' }];
			if (!this.verify.check(this.item, rule)) {
				uni.showModal({ content: this.verify.error, showCancel: false });
				return false;
			}
			this.disabled = true;
			let code = '';
			uni.login({
				provider: 'weixin',
				success: (res) => {
					code = res.code;
				}
			});
			//获取用户信息
			uni.getUserProfile({
				desc: '用于完善会员资料',
				lang: 'zh_CN',
				provider: 'weixin',
				success: (info) => {
					let item = info.userInfo;
					item.code = code;
					this.http.request({
						url: '/app/user/login',
						data: item,
						method: 'POST',
						success: (res) => {
							this.disabled = false;
							uni.setStorageSync('user', res.data.data);
							uni.navigateBack();
						},
						fail: (res) => {
							this.disabled = false;
						}
					});
				},
				fail: (res) => {
					this.disabled = false;
				}
			});
		},
		go(url) {
			uni.navigateTo({ url: url });
		}
	}
};
</script>

<style lang="scss">
.bg {
	padding: 30px;
	.p {
		text-align: center;
		padding: 45px 15px 15px 15px;
		.pic {
			width: 150px;
			height: 150px;
			border-radius: 50%;
		}
	}
	.xy {
		color: $font-c;
		padding-top: 15px;
		font-size: 14px;
		.checkbox {
			float: left;
			font-size: 14px;
			margin-top: 1px;
		}
		.a {
			color: blue;
		}
	}
	.btn {
		margin-top: 20px;
		border-radius: 30px;
	}
}
</style>
