<template>
	<view>
		
		
		<view class="info-line">
			<view class="il-top">
				<text>手机账号</text>
			</view>
			<view class="il-code" style="color: #ccc;">
				{{ getHideMobile(user.mobile) }}
			</view>
		</view>
		

		<view class="info-line">
			<view class="il-top">
				<text>验证码</text>
			</view>
			<view class="il-code">
				<input placeholder="验证码" type="number" v-model="verify_code" />
				<view class="ilc-btn" v-if="verifyCount == 0" @click="getverifyPhone">获取验证码</view>
				<view class="ilc-no-show" v-else>{{verifyCount}} s</view>
			</view>
		</view>
		<view class="info-line" >
			<view class="il-top">
				<text>输入密码</text>
			</view>
			<view class="il-bot">
				<input placeholder="输入密码" v-model="new_password" password />
			</view>
		</view>
		<view class="info-line">
			<view class="il-top">
				<text>再次输入密码</text>
			</view>
			<view class="il-bot">
				<input placeholder="再次输入密码" v-model="two_password" password />
			</view>
		</view>

		<view class="update-btn" @click="tapSubmit">
			<text>修改</text>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		computed: mapState(['user']),
		data() {
			return {
				verify_code: "",
				verifyCount: 0,
				new_password: "",
				two_password : ""
			}
		},
		onLoad(options) {

		},
		methods: {
			
			getverifyPhone: function() {
				if (this.verifyCount > 0) return;
				uni.showLoading({
					title: "获取中..."
				});
				this
					.request
					.post("userYzm", {
						type: "mobile"
					})
					.then(res => {
						console.log(res);
						uni.hideLoading();
						if (res.code == 200) {
							if (res.data.status == 2) {
								this.utils.CountDowm(res.data.time, (e, s) => {
									this.verifyCount = e;
								});
							}

							if (res.data.status == 1) {
								this.utils.CountDowm(120, (e, s) => {
									this.verifyCount = e;
								});
							}

						} else {
							uni.showToast({
								title: res.msg,
								mask: true,
								icon: 'none'
							});
						}
					})
					.catch(err => {
						uni.showToast({
							title: '获取失败',
							mask: true,
							icon: 'none'
						});
						uni.hideLoading();
					});
			},
			/**
			 * 提交数据
			 */
			tapSubmit:function(){
				
				if(this.verify_code == ''){
					this.utils.Tip("请输入验证码");
					return;
				}
				
				if(this.new_password == ''){
					this.utils.Tip("请输入新密码");
					return;
				}
				
				
				if(this.new_password.length < 5){
					this.utils.Tip("新密码不能少于5位");
					return;
				}
				
				if(this.new_password != this.two_password){
					this.utils.Tip("两次密码不相等");
					return;
				}
				this.utils.loadIng("提交中..");
				this
					.request
					.post("updatePassword",{new_password:this.new_password,verify_code:this.verify_code})
					.then(res=>{
						uni.hideLoading();
						if(res.code == 200) {
							this.utils.Tip(res.msg,()=>{
								uni.navigateBack();
							});
						}else{  
							this.utils.Tip(res.msg);
						}
					}).catch(function(){
						uni.hideLoading();
						this.utils.Tip("网络错误，请稍后尝试");
					});
			
			},

		
			getHideMobile:function(text){
				if(!this.utils.isDefine(text)) {
					return "";
				}
				return text.substr(0,3) + "******" + text.substr(text.length - 3,3);
			},
		
		},

	}
</script>


<style>
	page {
		background: #F5F5F5;
	}

	#box {
		padding-top: 90px;
		z-index: -1;
	}

	.info-line {
		height: 80px;
		padding: 0 15px;
		background-color: #fff;
		border-top: 1px #f5f5f5 solid;
	}

	.il-top {
		color: #333;
		font-size: 14px;
		margin-top: 10px;
	}

	.il-bot {
		margin-top: 10px;
	}

	.il-bot input {
		width: 100%;
		height: 100%;
		font-size: 13px;
	}

	.update-btn {
		width: 90%;
		height: 40px;
		text-align: center;
		line-height: 40px;
		margin: 30px auto;
		background: #db292b;
		color: #fff;
		border-radius: 100px;
		font-size: 16px;
	}

	.il-code {
		display: flex;
		align-items: center;
		margin-top: 10px;
	}

	.il-code input {
		width: 50%;
		height: 100%;
		font-size: 13px;
	}

	.ilc-btn {
		width: 90px;
		height: 30px;
		text-align: center;
		line-height: 30px;
		margin-left: auto;
		font-size: 12px;
		background: #db292b;
		color: #fff;
		border-radius: 100px;
	}

	.ilc-no-show {
		width: 90px;
		height: 30px;
		text-align: center;
		line-height: 30px;
		margin-left: auto;
		font-size: 12px;
		background: #eee;
		color: #999;
		border-radius: 100px;
	}
</style>
