<template>
	<view class="container">
		<view class="back-btn" @click="backToBefore()">
			<u-icon name="arrow-left" color="#fff" size="20" customStyle="margin:0 auto"></u-icon>

			<text class="back-text">验证邮箱</text>
		</view>

		<view class="change-content">
			<view class="pass-item">
				<view class="pass-item-name">电子邮箱</view>

				<input type="text" class="pass-item-content" v-model="emailAddress" />
			</view>
		</view>

		<view class="confirm-btn" @click="confirmEmail()">发送验证码</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";

	import {
		getCheckcode
	} from '@/api/login';

	function backToBefore() {
		uni.navigateBack({})
	};

	let emailAddress = ref(null)

	function confirmEmail() {
		let reg = /^([a-zA-Z\d][\w-]{2,})@(\w{2,})\.([a-z]{2,})(\.[a-z]{2,})?$/;
		let isValid = reg.test(emailAddress.value)
		if (!isValid) {
			return uni.showToast({
				title: "邮箱格式不正确",
				icon: "error",
				duration: 2000
			})
		}
		getCheckcode({
			email: emailAddress.value
		}).then(res => {
			if (res.code === 200) {
				uni.navigateTo({
					url: `/pages/login/changePass/index?login=done&email=${emailAddress.value}`
				})
			}
		})
	}
</script>

<style lang="scss" scoped>
	page {
		height: 100%;
		background-color: #EAF0FA;
	}

	.container {
		position: relative;
		width: 100%;
		height: 100%;
		background: linear-gradient(180deg, #1869F6 0%, #EAF0FA 64%, #EAF0FA 100%);

		.back-btn {
			position: absolute;
			top: 8%;
			left: 4%;
			display: flex;
			font-size: 40rpx;
			font-weight: 500;
			color: #FFF;

			.back-text {
				margin-left: 28rpx;
			}
		}

		.change-content {
			position: absolute;
			top: 226rpx;
			left: 4%;
			width: 92%;
			height: 118rpx;
			padding: 19rpx 28rpx;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 40rpx;

			.pass-item {
				display: flex;
				align-items: center;
				justify-content: space-between;
				width: 100%;
				height: 80rpx;
				font-size: 32rpx;
				font-weight: 400;
				color: #9E9E9E;

				.pass-item-name {
					flex: 2;
				}

				.pass-item-content {
					flex: 6;
					text-align: right;
					font-size: 32rpx;
					color: #343437;
				}

				.pass-item-icon {
					flex: 1;
					height: 100%;
					line-height: 80rpx;
					text-align: right;

					image {
						width: 36rpx;
						height: 28rpx;
					}
				}

				.pass-item-hide {
					image {
						width: 36rpx;
						height: 18rpx;
					}
				}
			}
		}

		.confirm-btn {
			position: absolute;
			top: 396rpx;
			left: 4%;
			width: 92%;
			height: 84rpx;
			line-height: 84rpx;
			font-size: 36rpx;
			color: #fff;
			text-align: center;
			background: #1869F6;
			border-radius: 16rpx;
		}
	}
</style>