<!-- 蓝色简洁登录页面 -->
<template>
	<view class="t-login">
		<!-- 页面装饰图片 -->
		<view class="img-a"></view>
		<view class="t-login-p">
			<view class="t-b">
				<view>Hello！<br>欢迎来到库比森</view>
			</view>
			<form class="cl">
				<view class="t-a">
					<image src="@/static/sj.png"></image>
					<input type="number" name="phone" placeholder="请输入手机号" maxlength="11" v-model="phone" />
				</view>
				<view class="t-a">
					<image src="@/static/yz.png"></image>
					<input type="number" name="code" maxlength="6" placeholder="请输入验证码" v-model="code" />
					<view v-if="showText" class="t-c" @tap="getCode()">获取验证码</view>
					<view v-else class="t-c" style="background-color: #A7A7A7;">重新发送({{ second }})</view>
				</view>
				<button @tap="login()" :loading="loading">登 录</button>
			</form>
		</view>

		<view class="pact">
			<view class="pact-a">
				<radio value="pactChecked" activeBackgroundColor="#3ba662" activeBorderColor="#3ba662"
					borderColor="#3ba662" color="#fff" @click="pactChange" />
				<view>我已阅读并同意<text @click="toPact">《用户协议》</text>和<text @click="toPact">《隐私协议》</text></view>
			</view>
		</view>
	</view>
</template>
<script>
	import {
		v4 as uuidv4
	} from 'uuid';
	import {
		getPhoneVerifyCode
	} from '@/api/user.js'
	export default {
		data() {
			return {
				loading: false,
				pactChecked: false,
				second: 60, //默认60秒
				showText: true, //判断短信是否发送
				phone: '15933333333', //手机号码
				code: '', //验证码
				uuid: uuidv4(),
			};
		},
		onLoad() {},
		methods: {
			pactChange() {
				this.pactChecked = true
			},
			//当前登录按钮操作
			login() {
				if (!this.phone) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					});
					return;
				}
				if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.phone)) {
					uni.showToast({
						title: '请输入正确手机号',
						icon: 'none'
					});
					return;
				}
				if (!this.code) {
					uni.showToast({
						title: '请输入验证码',
						icon: 'none'
					});
					return;
				}
				if (!this.pactChecked) {
					uni.showToast({
						title: '请选中协议',
						icon: 'none'
					});
					return;
				}
				this.loading = true
				this.$u.api.token(
						this.uuid,
						this.phone,
						this.code
					).then(data => {
						uni.setStorageSync('uuid', this.uuid)
						uni.setStorageSync('phone', this.phone);
						uni.showToast({
							icon: 'none',
							title: '登录成功',
							position: "bottom",
							mask: true
						})
						let _this = this
						setTimeout(function() {
							_this.$u.func.login(data)
						}, 1000);
					})
					.finally(() => {
						this.loading = false;
					});
			},
			//获取短信验证码
			getCode() {
				if (!this.phone) {
					uni.showToast({
						title: '请输入手机号',
						icon: 'none'
					});
					return;
				}
				if (!/^[1][3,4,5,7,8,9][0-9]{9}$/.test(this.phone)) {
					uni.showToast({
						title: '请输入正确手机号',
						icon: 'none'
					});
					return;
				}

				this.showText = false;
				var that = this;
				var interval = setInterval(() => {
					var times = that.second - 1;
					that.second = times < 10 ? '0' + times : times; //小于10秒补 0
					that.second = times;
					console.log(times);
				}, 1000);
				setTimeout(() => {
					clearInterval(interval);
					that.second = 60;
					that.showText = true;
				}, 60000);
				let obj = {
					phone: this.phone,
					uuid: this.uuid
				}
				getPhoneVerifyCode(obj).then(res => {
					this.code = res.data.data
				})
			},
			//等三方微信登录
			wxLogin() {
				uni.showToast({
					title: '微信登录',
					icon: 'none'
				});
			},
			//第三方支付宝登录
			zfbLogin() {
				uni.showToast({
					title: '支付宝登录',
					icon: 'none'
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	.img-a {
		width: 100%;
		height: 565rpx;
		background: url(../../static/images/login/heae.png) no-repeat;
		background-size: 100%;
	}

	.img-b {
		position: absolute;
		width: 50%;
		bottom: 0;
		left: -50rpx;
		margin-bottom: -200rpx;
	}

	.t-login {
		width: 100%;
		font-size: 28rpx;
		color: #000;
	}

	.t-login-p {
		position: relative;
		padding: 0 36rpx;
		top: -300rpx;
	}

	.t-login button {
		font-size: 28rpx;
		background: #03803B;
		color: #fff;
		height: 90rpx;
		line-height: 90rpx;
		border-radius: 50rpx;
		box-shadow: 0 5px 7px 0 rgba(86, 119, 252, 0.2);
	}

	.t-login input {
		padding: 0 20rpx 0 120rpx;
		height: 90rpx;
		line-height: 90rpx;
		margin-bottom: 50rpx;
		background: #f8f7fc;
		border: 1px solid #e9e9e9;
		font-size: 28rpx;
		border-radius: 50rpx;
	}

	.t-login .t-a {
		position: relative;
	}

	.t-login .t-a image {
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		left: 40rpx;
		top: 28rpx;
		border-right: 2rpx solid #dedede;
		padding-right: 20rpx;
	}

	.t-login .t-b {
		text-align: left;
		font-size: 46rpx;
		color: #000;
		padding: 200rpx 0 120rpx 0;
		font-weight: bold;
	}

	.t-login .t-c {
		position: absolute;
		right: 22rpx;
		top: 22rpx;
		background: #03803B;
		color: #fff;
		font-size: 24rpx;
		border-radius: 50rpx;
		height: 50rpx;
		line-height: 50rpx;
		padding: 0 25rpx;
	}


	.t-login .uni-input-placeholder {
		color: #000;
	}

	.pact {
		position: absolute;
		width: 100%;
		bottom: 60rpx;
		font-size: 24rpx;

		text {
			color: #3ba662;
		}

		.pact-a {
			display: flex;
			align-items: center;
			justify-content: center;

			radio {
				:deep(.uni-radio-input) {
					border: 1rpx solid #3ba662;
				}

				transform:scale(0.6)
			}
		}

	}
</style>