<template>
	<view class="content">
		<view class="title-img">
			<image src="../../static/img/logo.png" mode=""></image>
		</view>
		<view class="title-LOGO">
			艺绘
		</view>
		<view class="bg">
			<image src="../../static/img/pbbg.png" mode=""></image>
		</view>

		<view class="register-content">
			<view class="res-box">
				<image src="../../static/img/pb03.png" mode=""></image>
				<view class="input-box">
					<input class="input" type="number" v-model="phone" placeholder="请输入手机号">
				</view>
			</view>
			<view class="res-box">
				<image src="../../static/img/pb02.png" mode=""></image>
				<view class="input-box">
					<input class="input" type="password" v-model="loginPass" placeholder="请输入密码">
				</view>
			</view>
			<view class="res-box">
				<image src="../../static/img/pb01.png" mode=""></image>
				<view class="input-box">
					<input class="input" type="number" v-model="code" placeholder="请输入验证码">
					<view class="time" @click="getYzm" v-show="isHq">
						获取验证码
					</view>
					<view class="djs" v-show="!isHq">
						{{countDown}}
					</view>
				</view>
			</view>
		</view>
		<view class="button" @click="registerTo()">
			注册
		</view>
		<view class="tishi">
			<view class="for-pass" @click="getNavto('/pages/set/changePass')">
				忘记密码
			</view>
			<view class="ss">

			</view>
			<view class="for-phone" @click="getNavto('/pages/public/login')" >
				账号登录
			</view>
		</view>
	</view>
</template>
<script>
	import {
		register,
		verify
	} from '@/api/login.js';
	export default {
		data() {
			return {
				isHq: true,
				phone: '', //用户
				loginPass: '', //密码
				payPass: '',
				invitation: '', //邀请码
				code: '', //验证码
				time: '', //保存倒计时对象
				countDown: 60 //倒计时
			};
		},
		onLoad() {
			// 获取扫码邀请人id
			this.invitation = uni.getStorageSync('spread') || '';
		},
		methods: {
			//注册
			registerTo(){
				let obj= this
				let jiaoyan = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
				if (!jiaoyan.test(obj.phone)) {
					this.$api.msg('请输入正确的手机号!')
					return
				}else if(obj.phone == ''){
					this.$api.msg('请输入手机号')
					return
				}else if(obj.loginPass==''){
					this.$api.msg('请输入密码')
					return
				}else if(obj.code == ''){
					this.$api.msg('请输入验证码')
					return
				}else if(obj.code.length!=6){
					this.$api.msg('请输入正确的验证码')
					return
				}
				else{
					register({
						account:obj.phone,
						captcha:obj.code,
						password:obj.loginPass,
						spread:obj.invitation
						
					}).then(res=>{
						console.log(res,'res');
						this.$api.msg('注册成功')
						setTimeout(function(){
							uni.navigateTo({
								url:'/pages/public/login'
							})
						},1000)
					})
				}
			},
			//跳转详情
			getNavto(url){
				uni.navigateTo({
					url:url
				})
			},
			//获取验证码
			getYzm() {
				let obj = this
				let jiaoyan = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
				if (!jiaoyan.test(obj.phone)) {
					this.$api.msg('请输入正确的手机号!')
					return
				}

				let setTime = setInterval(
					function() {
						obj.isHq = false
						obj.countDown--;
						
						if (obj.countDown == 0) {
							clearInterval(setTime)
							// let setOut = setTimeout(() => {
								obj.isHq = true
								obj.countDown=10;
							// }, 1000)
						}

					}, 1000)
					//调用验证码接口
					verify({
						phone: obj.phone,
						type: 'register'
					})
						.then(({ data }) => {
							console.log(data,'data');
						})
						.catch(err => {
							console.log(err);
						});
					
			}


		}
	};
</script>

<style lang="scss">
	page,
	.content {
		min-height: 100%;
		background-color: #181818;

		.bg {
			width: 750rpx;
			height: 200rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.title-img {
			margin: 70rpx auto 0;
			width: 161px;
			height: 161px;
			border-radius: 50%;
			overflow: hidden;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.title-LOGO {
			text-align: center;
			margin: 30rpx;
			font-size: 36px;
			font-family: PingFang SC;
			font-weight: 400;
			color: #FFFFFF;
		}

		.register-content {
			.res-box {
				height: 110rpx;
				width: 600rpx;
				align-items: center;
				display: flex;
				margin: 0 75rpx;
				border-bottom: #f3f3f3 solid 2rpx;

				image {
					width: 31rpx;
					height: 40rpx;
				}

				.input-box {
					margin-left: 40rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
						flex-grow: 1;
					.input {
						width: 100%;
						color:#9F570E;
						// line-height: 40rpx;

					}

					.time {
						flex-shrink: 0;
						width: 190rpx;
						height: 50rpx;
						line-height: 50rpx;
						text-align: center;
						border-radius: 10rpx;
						color: #9F570E;
						background: $bgBaseBg;
					}

					.djs {
						margin-left: 100rpx;
						width: 50rpx;
						height: 50rpx;
						line-height: 50rpx;
						text-align: center;
						border-radius: 10rpx;
						color: #FFFFFF;
						background: $bgBaseBg;
					}
				}

			}
		}

		.button {
			margin: 40rpx auto;
			text-align: center;
			width: 604rpx;
			height: 90rpx;
			background: $bgBaseBg;
			border-radius: 10rpx;
			font-size: 34rpx;
			font-weight: 500;
			color: #9F570E;
			line-height: 90rpx;
		}

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


			.for-pass {
				font-size: 28rpx;
				font-weight: 500;
				color: #FFFFFF;
			}

			.ss {
				height: 26rpx;
				width: 3rpx;
				background-color: #f3f3f3;
				margin: 0 10rpx;
			}

			.for-phone {
				font-size: 28rpx;
				font-weight: 500;
				color: #FFFFFF;
			}

		}
	}
</style>
