<!-- 蓝色简洁登录页面 -->
<template>
	<view class="t-login">
		<view class="img-a">
			<view class="t-login-p">
				<view style="display: flex;justify-content: center;padding: 205rpx 0 30rpx 0;">
					<image src="/static/images/login/login (2).png" style="width:518rpx;height: 144rpx;"
						mode="scaleToFill">
					</image>
				</view>
				<view style="color: #fff;font-size: 26rpx;margin-bottom: 100rpx;display: flex;justify-content: center;">
					欢迎来到库比森!</view>
				<view style="display: flex;justify-content: center;">
					<view class="login-card">
						<form>
							<view style="padding:100rpx 50rpx">
								<view style="display: flex;align-items: center;">
									<image style="width: 23rpx;height: 32rpx;" src="/static/images/login/login (3).png">
									</image>
									<uni-easyinput type="number" name="phone" placeholder="请输入手机号" maxlength="11"
										v-model="phone" :inputBorder="false"  :clearable="false"/>
								</view>
								<view style="height: 2rpx;background: #E4E4E4;">
								</view>
							</view>
							<view style="padding: 0 50rpx">
								<view style="display: flex;align-items: center;">
									<image style="width: 25rpx;height: 30rpx;" src="/static/images/login/login (4).png">
									</image>
									<uni-easyinput type="number" name="code" maxlength="6" placeholder="请输入验证码"
										v-model="code" :inputBorder="false" :clearable="false"/>
									<view v-if="showText" class="code" @tap="getCode()">获取验证码</view>
									<view v-else class="code">重新发送({{ second }})
									</view>
								</view>
								<view style="height: 2rpx;background: #E4E4E4;">
								</view>
							</view>
							<view style="margin:80rpx 0 50rpx;display: flex;justify-content: center;">
								<debounce-button style="width: 474rpx;" bgColor='#03803B' @tap="login()" :loading="loading">登 录</debounce-button>
							</view>
						</form>
					</view>
				</view>
			</view>


		</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:uni.getStorageSync('phone'), //手机号码
				code: '', //验证码
				uuid: uuidv4(),
				sendBtn:false,
			};
		},
		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;
				}
				let obj = {
					phone: this.phone,
					uuid: this.uuid
				}
				if (this.sendBtn) return
				this.sendBtn = true
				getPhoneVerifyCode(obj).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					});
					if (res.code == 200) {
						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;
						}, 1000);
						setTimeout(() => {
							clearInterval(interval);
							that.second = 60;
							that.showText = true;
						}, 60000);
					}
				}).finally(() => {
					this.sendBtn = false
				});
			},
			//等三方微信登录
			wxLogin() {
				uni.showToast({
					title: '微信登录',
					icon: 'none'
				});
			},
			//第三方支付宝登录
			zfbLogin() {
				uni.showToast({
					title: '支付宝登录',
					icon: 'none'
				});
			}
		}
	};
</script>
<style lang="scss" scoped>
	.img-a {
		width: 100%;
		height: 100vh;
		background: url(../../static/images/login/heae.png) no-repeat;
		background-size: 100%;
	}

	.t-login {
		width: 100%;
		height: 100vh;
		font-size: 28rpx;
		color: #000;
		background-color: #0C7C3E;
	}

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

	.login-card {
		width: 649rpx;
		background: rgba(7, 97, 47, 0.6);
		box-shadow: 0rpx 4rpx 54rpx 0rpx #131413;
		border-radius: 12rpx;
	}

	::v-deep .uni-easyinput__content {
		background-color: transparent !important;
	}

	::v-deep .uni-input-input {
		color: #fff;
	}

	::v-deep .uni-input-placeholder {
		color: #FFF !important;
		font-size: 28rpx;
	}

	.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;
	}
	.code{
		width: 160rpx;
		text-align: center;
		font-size: 26rpx;
		color: #FFF;
		border-radius: 8rpx;
		border: 1rpx solid #FFFFFF;
		padding:3rpx 4rpx ;
	}

	.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>