<template>
	<view>
		<lf-nav title="旧手机号验证" :showIcon="true"></lf-nav>
		<view class="content">
			<view class="list">
				<view class="lf-flex">
					<view class="lf-font-28 lf-color-black" style="width: 140rpx;">旧手机号</view>
					<input class="input" placeholder="请输入手机号" v-model="phone" maxlength="11" />
				</view>
				<view class="clear" v-if="phone.length" @click="phone = ''">
					<text class="lf-iconfont icon--"></text>
				</view>
			</view>
			<view class="list">
				<view class="lf-flex">
					<view class="lf-font-28 lf-color-black" style="width: 140rpx;">验证码</view>
					<input class="input input-code" placeholder="请输入验证码" maxlength="8" v-model="code" />
				</view>
				<view class="code" :class="{'active-bg': is_code}" @click="getCode">
					<text>{{ is_code ? num +'秒后重新获取' : '获取验证码' }}</text>
				</view>
			</view>
		</view>
		<button class="next-btn" hover-class="lf-opacity" @click="next">下一步</button>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				phone: '',
				code: '',
				is_code: false,
				timer: null,
				num: 10
			}
		},
		onLoad(){
			
		},
		onUnload(){
			if(this.timer){
				clearInterval(this.timer);
				this.timer = null;
			}
		},
		methods: {
			getCode(){
				if(this.is_code) return;
				this.is_code = true;
				if(this.timer){
					clearInterval(this.timer);
					this.timer = null;
				}
				console.log("测试重复点击", Math.random())
				// TODO 在此发送网络请求
				this.timer = setInterval(() => {
					this.num--;
					if(this.num <= 0){
						clearInterval(this.timer);
						this.timer = null;
						this.num = 10;
						this.is_code = false;
					}
				}, 1000);
			},
			next(){
				// this.$url('/pages/user/my/setPassword', {type: 'redirect'});
				this.$url('/pages/user/my/setPassword');
			}
		}
	}
</script>

<style lang="scss" scoped="scoped">
	.content{
		padding: 0 32rpx;
	}
	.next-btn{
		width: 550rpx;
		height: 100rpx;
		background: #15716E;
		border-radius: 50rpx;
		position: fixed;
		bottom: 10vh;
		left: calc(50% - 275rpx);
		line-height: 100rpx;
		color: #FFFFFF;
	}
	.list{
		height: 106rpx;
		width: 100%;
		border-bottom: 1rpx solid #e5e5e5;
		display: flex;
		justify-content: space-between;
		align-items: center;
		&:nth-child(2n){
			margin-top: 30rpx;
		}
		.input{
			width: 380rpx;
			height: 80rpx;
			font-size: 32rpx;
			margin-left: 50rpx;
		}
		.input-code{
			width: 290rpx;
		}
		.clear{
			padding: 20rpx;
		}
		.code{
			min-width: 180rpx;
			max-width: 220rpx;
			height: 64rpx;
			padding: 0 4rpx;
			font-size: 24rpx;
			color: #15716E;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 32rpx;
			border: 2rpx solid #15716E;
		}
		.active-bg{
			background: #efefef;
		}
	}
</style>
