<template>
	<view class="content">
		<!-- <view class="bg"></view> -->
		<view class="login">
			<view class="editem">
				<view class="item">
					<view class="text">手机号/邮箱</view>
					<view class="input">
						<input v-model="phone" placeholder="" />
					</view>
				</view>
				<view class="item ">
					<view class="text">验证码</view>
					<view class="input yanzhengma">
						<input class="uni-input" v-model="code" />
						<button class="code" type="none" @click="handleCode" v-model="code"
							:disabled="disabled">{{second<60 ? second+'S后重发':$t("login.sendcode")}}
						</button>
					</view>
				</view>
				<view class="item">
					<view class="text">密码</view>
					<view class="input">
						<input class="uni-input" v-model="password" />
					</view>
				</view>
				<view class="item">
					<view class="text">确认密码</view>
					<view class="input">
						<input class="uni-input" v-model="password2" />
					</view>
				</view>
			</view>
			<!-- <view class="xieyi">
				<checkbox-group @change="checkboxChange" class="group">
					<label>
						<checkbox :value="1" style="transform:scale(0.7)" />{{$t("login.agreement")}}
						<text @click="handlexieyi" @click.stop>{{$t("login.agreementContnt")}}</text>
					</label>
				</checkbox-group>
			</view> -->
			<view class="btnlogin" @click="handleTelLogin">确认</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: "",
				code: "",
				password: "",
				password2: "",
				disabled: false,
				second: 60,
				value: 1,
				type: ""
			}
		},
		onLoad(options) {
			this.type = options.type //1
		},
		methods: {
			checkboxChange(e) {
				this.value = e.detail.value.length ? e.detail.value[0] : "0"
			},
			// 登录、
			handleTelLogin() {
				let that = this
				let phoneType = that.phone.indexOf("@") !== -1
				if (that.value == 0) {
					that.$tools.msg("请先确认勾选协议")
					return
				}
				if (!phoneType && !(/^1[3456789]\d{9}$/.test(that.phone))) {
					that.$tools.msg("请输入正确的手机号")
					return
				}
				if (phoneType && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that.phone))) {
					that.$tools.msg("请输入正确的邮箱")
					return
				}
				if (!that.code) {
					that.$tools.msg("请填写验证码")
					return
				}
				if (!that.password) {
					that.$tools.msg("请填写密码")
					return
				}
				if (!that.password2) {
					that.$tools.msg("请确认密码")
					return
				}
				if (that.password2 != that.password) {
					that.$tools.msg("请确认两次密码填写一致")
					return
				}
				let account = {
					data: that.phone,
					password: that.password,
					c_password: that.password2,
					code: that.code
				}
				let https = that.type == 'register' ? that.$model.getregister(account) : that.$model.getResetPassword(
					account)
				return https.then(res => {
					console.log("注册", res)
					if (res.code != 0) {
						that.$tools.msg(res.msg)
						return
					}
					uni.setStorageSync('token', res.data.token)
					uni.setStorageSync('aan_id', res.data.aan_id)
					that.$tools.msg("设置成功,进入程序中")
					setTimeout(function() {
						uni.reLaunch({
							url: "/pages/home/home?type=1"
						})
					}, 1000)
				}).catch(err => {})
			},
			// 获取验证码
			handleCode() {
				let that = this
				let phoneType = that.phone.indexOf("@") !== -1
				if (!phoneType && !(/^1[3456789]\d{9}$/.test(that.phone))) {
					that.$tools.msg("请输入正确的手机号")
					return
				}
				if (phoneType && !(/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(that.phone))) {
					that.$tools.msg("请输入正确的邮箱")
					return
				}
				// 
				that.$model.getSendCode({
					data: that.phone,
					type: that.type
				}).then(res => {
					console.log(res)
					if (res.code != 0) {
						that.$tools.msg(res.msg)
						return
					}
					that.disabled = true
					let interval = setInterval(() => {
						--that.second
					}, 1000)
					setTimeout(() => {
						clearInterval(interval)
						that.disabled = false
						that.second = 60
					}, 60000)
				}).catch(err => {})
			},
			handlexieyi() {}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		width: 100%;
		height: 100vh;
		// display: flex;
		// flex-direction: column;
		// align-items: center;
		// justify-content: center;
	}

	.bg {
		position: absolute;
		top: 0;
		width: 100%;
		height: 50vh;
		z-index: 9;
		// background: $maincolor;
	}

	.login {
		width: calc(100% - 30px);
		height: auto;
		background: #fff;
		border-radius: 10px;
		padding: 15px;
		background-color: #fff;
		z-index: 99;
		// position: relative;
		// margin-left: calc(10% - 40px);
		// box-shadow: 0px 1px 5px 2px #dfe2e1fc;

		.title {
			text-align: left;
			color: #333;
			font-size:  40rpx;
			font-weight: bold;
			margin-bottom: 15px;
		}


		.editem {
			position: relative;
			display: flex;
			align-items: center;
			font-size: 32rpx;
			justify-content: space-between;
			flex-wrap: wrap;


			.item {
				width: 100%;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-bottom: 15px;

				.text {
					width: 240rpx;
					height: 40px;
					line-height: 40px;
					font-size: 32rpx;
				}

				.input {
					width: calc(100% - 240rpx);
					height: 35px;
					line-height: 35px;
					display: flex;
					position: relative;
					border: #dfdfdf 1px solid;
					border-radius: 5px;
					padding: 0 10px;
					background-color: #f7f7f7;
				}

				input {
					height: 40px;
					line-height: 40px;
					position: absolute;
					left: 10px;
					right: 0px;
					z-index: 88;
					font-size:28rpx;
				}

				.yanzhengma {
					input {
						right: 220rpx;
						font-size:28rpx;
					}
				}
			}

			.code {
				width: 220rpx;
				background: #dfdfdf;
				font-size: 28rpx;
				margin: 0;
				line-height: 40px;
				border-radius: 5px;
				text-align: center;
				position: absolute;
				right: 0px;
				top: 0px;
				bottom: 0;
				z-index: 99;
			}

			.forget {
				width: 80px;
				background: #fff;
				color: $textcolor;
			}
		}

		.btngroup {
			width: 100%;
			height: 35px;
			line-height: 35px;
			display: flex;
			justify-content: center;

			text {
				display: block;
				color: $textcolor;
			}
		}

		.btnlogin {
			width: 100%;
			margin: 15px 0;
			height: 42px;
			line-height: 42px;
			background: $btncolor;
			font-weight: 700;
			border-radius: 15px;
			text-align: center;
			color: #fff !important;
		}
	}

	.xieyi {
		font-size: 32rpx;
		color: $textcolor;

		text {
			border-bottom: 1px solid $textcolor;
		}
	}
</style>