<template>
	<view class="container">
		<image src="../../static/img/bd-top.png" mode="widthFix" style="width: 750rpx;"></image>
		<view class="login_text">
			<view class="login_input flex">
				<view class="login_img"><image src="/static/icon/phone.png"></image></view>
				<view class="login_name"><input class="uni-input" v-model="account" placeholder="请输入手机号" /></view>
			</view>
			<!-- <view class="login_input flex">
				<view class="login_img"><image src="/static/icon/img04.png"></image></view>
				<view class="login_name"><input class="uni-input" type="password" v-model="password" focus placeholder="请输入密码" /></view>
			</view> -->
			<!-- <view class="login_input flex">
				<view class="login_img"><image src="/static/icon/img04.png"></image></view>
				<view class="login_name"><input class="uni-input" type="password" v-model="repassword" focus placeholder="请重复输入密码" /></view>
			</view>
			<view class="login_input flex">
				<view class="login_img"><image src="/static/icon/img07.png"></image></view>
				<view class="login_name"><input class="uni-input" type="text" v-model="invitation" focus placeholder="请输入邀请码" /></view>
			</view> -->
			<view class="login_input flex">
				<view class="login_img"><image src="/static/icon//yzm.png"></image></view>
				<view class="login_name flex">
					<input class="uni-input width" v-model="captcha" placeholder="请输入验证码" />
					<view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
				</view>
			</view>
		</view>
		<view class="sb-btn" @click="loding ? '' : confirm()">
			确认绑定
		</view>
		<!-- <view class="row b-b">
			<text class="tit">手机号</text>
			<input class="input" v-model="account" type="text" placeholder="请填写手机号" placeholder-class="placeholder" />
		</view>
		<view>
			<view class="row b-b">
				<text class="tit">验证码</text>
				<input class="input" v-model="captcha" type="text" placeholder="请填写验证码" placeholder-class="placeholder" />
				<view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
			</view>
			<button class="add-btn" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">提交</button>
		</view> -->
	</view>
</template>

<script>
import { verify } from '@/api/login.js';
import { mapState } from 'vuex';
import { registerReset, binding } from '@/api/set.js';
export default {
	data() {
		return {
			time: '', //保存倒计时对象
			countDown: 0, //倒计时
			account: '', //手机号
			captcha: '', //验证码
			password: '', //新密码
			loding: false //是否载入中
		};
	},
	watch: {
		// 监听倒计时
		countDown(i) {
			if (i == 0) {
				clearInterval(this.time);
			}
		}
	},
	computed: {
		...mapState(['userInfo'])
	},
	onLoad() {
		if (this.userInfo.phone == null) {
			this.account = '';
		} else {
			this.account = this.userInfo.phone;
			this.show = false;
		}
	},
	onBackPress() {
		// uni.switchTab({
		// 	url: '/pages/user/user'
		// })
		return true
	},
	methods: {
		//发送验证码
		verification() {
			let obj = this;
			if (this.account == '') {
				this.$api.msg('请输入电话号码');
				return;
			}
			if (!/(^1[2|3|4|5|6|7|8|9][0-9]{9}$)/.test(this.account)) {
				this.$api.msg('请输入正确的手机号');
				return;
			}
			// 判断是否在倒计时
			if (obj.countDown > 0) {
				return false;
			} else {
				obj.countDown = 60;
				obj.time = setInterval(() => {
					obj.countDown--;
				}, 1000);
				//调用验证码接口
				verify({
					phone: obj.account,
					type: 'BDING_CODE'
				})
					.then(({ data }) => {})
					.catch(err => {
						console.log(err);
					});
			}
		},
		confirm(e) {
			let obj = this;
			obj.loding = true;
			binding({
				phone: obj.account,
				captcha: obj.captcha
			})
				.then(({ data }) => {
					obj.$api.msg('绑定成功！');
					setTimeout(function() {
						obj.loding = false;
						uni.switchTab({
							url: '/pages/user/user'
						});
					}, 1000);
				})
				.catch(err => {
					obj.loding = false;
					console.log(err);
				});
		}
	}
};
</script>

<style lang="scss">
page {
	background: #e9f8f2;
	min-height: 100%;
	height: auto;
}
.row {
	display: flex;
	align-items: center;
	position: relative;
	padding: 0 30rpx;
	height: 110rpx;
	background: #fff;

	.tit {
		flex-shrink: 0;
		width: 120rpx;
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.input {
		flex: 1;
		font-size: 30rpx;
		color: $font-color-dark;
	}
	.iconlocation {
		font-size: 36rpx;
		color: $font-color-light;
	}
}
.add-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 690rpx;
	height: 80rpx;
	margin: 60rpx auto;
	font-size: $font-lg;
	color: #fff;
	background-color: $base-color;
	border-radius: 10rpx;
	// box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
}

.bg-gray {
	background-color: $color-gray;
}
.code {
	color: #5dbc7c;
	font-size: 23rpx;
	border-left: 1px solid #eeeeee;
	width: 150rpx;
	flex-shrink: 0;
	text-align: center;
}
.login_text {
	margin: auto 30rpx;
	position: relative;
	padding: 100rpx 102rpx;
background: #e9f8f2;
	// margin-top: -180rpx;
	border-radius: 20rpx;
	.login_input {
		border-bottom: 1px solid #eee;
		margin-bottom: 65rpx;
		justify-content: flex-start;
		.login_img image {
			height: 35rpx;
			width: 29rpx;
			margin-right: 20rpx;
		}
		.uni-input {
			text-align: left;
			// width: 470rpx;
			max-width: 470rpx;
			flex-grow: 1;
			font-size: 28rpx !important;
		}
		.login_name {
			color: #333333;
		}
	}

	.other {
		margin-top: 60rpx;
		.fenge {
			width: 30%;
			height: 2rpx;
			background-color: #eeeeee;
		}
		.qita {
			font-size: 28rpx;
			color: #999999;
		}
	}
	.weixin {
		width: 75rpx;
		height: 75rpx;
		margin: 25rpx auto;
	}
	.weixin image {
		width: 100%;
		height: 100%;
	}
	.weixin_text {
		text-align: center;
		font-size: 28rpx;
		color: #999999;
	}
	.forget {
		font-size: 28rpx;
		width: 100%;
		text-align: right;
		color: #999999;
	}

	.uni-button-green {
		color: #ffffff;
		background-color: #5dbc7c;
		margin: 40rpx 10rpx;
		border-radius: 50rpx;
	}
	.uni-button-green-plain {
		border: 1px solid #5dbc7c;
		margin: 40rpx 10rpx;
		border-radius: 50rpx;
		color: #5dbc7c;
		background-color: #ffffff;
	}
	.uni-button {
		height: 85rpx;
		line-height: 85rpx;
	}
}
.code {
	color: #5dbc7c;
	font-size: 23rpx;
	border-left: 1px solid #eeeeee;
	width: 150rpx;
	flex-shrink: 0;
	text-align: center;
}
.sb-btn {
	width: 550rpx;
	height: 90rpx;
	line-height: 90rpx;
	background: #52C696;
	border-radius: 10rpx;
	font-size: 34rpx;
	font-weight: 400;
	color: #FFFFFF;
	margin: auto;
	text-align: center;
}
</style>
