<template>
	<view class="container">
		<view class="row b-b" v-if="userInfo.transaction">
			<text class="tit">原密码</text>
			<input class="input" v-model="oldPassword" type="text" placeholder="请填写原密码" placeholder-class="placeholder" />
		</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> -->
		<view class="row b-b">
			<text class="tit">新密码</text>
			<input class="input" v-model="password" type="password" placeholder="请填写6位新密码" placeholder-class="placeholder" />
		</view>
		<view class="row b-b">
			<text class="tit">再次输入</text>
			<input class="input" v-model="yzpassword" type="password" placeholder="请重新填写6位新密码" placeholder-class="placeholder" />
		</view>
		<button class="add-btn" :class="{'bg-gray':loding}" @click="loding?'':confirm()">提交</button>
	</view>
</template>

<script>
import { verify } from '@/api/login.js';
import { mapState } from 'vuex';
import { transaction } from '@/api/set.js';
export default {
	data() {
		return {
			time: '', //保存倒计时对象
			countDown: 0, //倒计时
			// account: '', //手机号
			// captcha: '', //验证码
			oldPassword:'',//老密码
			password: '' ,//新密码
			yzpassword:'',//重复输入
			loding:false,//是否载入中
		};
	},
	computed: {
		...mapState('user',['userInfo'])
	},
	onLoad() {
		if(this.userInfo.phone == null){
			this.account = '';
		}else{
			this.account = this.userInfo.phone;
			this.show = false;
		}
	},
	watch: {
		// 监听倒计时
		countDown(i) {
			if (i == 0) {
				clearInterval(this.time);
			}
		}
	},
	methods: {
		confirm(e) {
			const reg = /^[0-9]{6}$/;
			console.log(this.yzpassword)
			if(!reg.test(this.yzpassword)){
				uni.showModal({
					title: '错误',
					content: '请输入6位数字支付密码',
					showCancel: false,
				});
				return false
			}
			if(this.yzpassword!=this.password){
				uni.showModal({
					title: '错误',
					content: '密码不一致请重新输入',
					showCancel: false,
				});
				return  false
			}
			this.loding = true;
			transaction({
				pass: this.password,
				oldpass: this.oldPassword,
			})
				.then(({ data }) => {
					this.loding = false;
					uni.showModal({
						title: '提示',
						content: '修改成功',
						showCancel: false,
						confirmText: '返回个人中心',
						success: res => {
							uni.switchTab({
								url:'/pages/user/user'
							})
						}
					});
					
				})
				.catch(err => {
					this.loding = false;
					console.log(err);
				});
		}
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
}
.container {
	padding-top: 30rpx;
}
.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: #ecd0a9;
	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;
}
</style>
