<template>
	<view class="content">
		<view class="box">
			<view class="box-top">
				<view class="shu" style="">

				</view>
				<view class="pass-title">
					支付密码
				</view>
			</view>
			<view class="box-bottom">
				<view class="ipt">
					<view class="text">
						新密码
					</view> <input type="password" class="input" value="" placeholder="请输入新的支付密码" />
				</view>
				<view class="ipt">
					 <view class="text">
					 	重复密码
					 </view><input type="password" class="input" value="" placeholder="请重复输入支付密码" />
				</view>
				<view class="ipt">
					<view class="text">
						验证码 
					</view> <input type="number" class="input" value="" placeholder="请输入验证码"/>
					<view class="yzm" @click="getDjs()" v-if="!isDjs">
						验证码
					</view>
					<view class="yzm" v-else>
						{{countDown}}
					</view>
				</view>
			</view>
		</view>
		<button class="button" @click="navTo('/pages/money/success')">确认</button>

		<!-- 		<image style="z-index: 99;" src="../../static/game/game13.png" mode=""></image>
		<image style="z-index: 99;" src="../../static/game/reb01.png" mode=""></image> -->
	</view>
</template>

<script>
	import {
		verify
	} from '@/api/login.js';
	import {
		mapState
	} from 'vuex';
	import {
		registerReset
	} from '@/api/set.js';
	export default {
		data() {
			return {
				time: '', //保存倒计时对象
				countDown: 0, //倒计时
				account: '', //手机号
				captcha: '', //验证码
				password: '', //新密码
				loding: false, //是否载入中
				isDjs:false,//是否在倒计时
			};
		},
		computed: {
			...mapState(['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: {
			getDjs(){
				this.isDjs = true
				this.countDown= 10
				let time = setInterval(e=>{
					this.countDown--
					console.log(this.countDown);
					if(this.countDown==0){
						clearInterval(time)
						console.log('倒计时结束');
						console.log(this.countDown,'打印');
					}
				},1000)
			},

			//发送验证码
			verification() {
				let obj = this;
				if (this.account == '') {
					this.$api.msg('请输入电话号码');
					return;
				}
				if (!/(^1[3|4|5|7|8][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: ''
						})
						.then(({
							data
						}) => {})
						.catch(err => {
							console.log(err);
						});
				}
			},
			confirm(e) {
				this.loding = true;
				registerReset({
						account: this.account,
						captcha: this.captcha,
						password: this.password,
					})
					.then(({
						data
					}) => {
						this.loding = false;
						this.$api.msg('修改成功');
					})
					.catch(err => {
						this.loding = false;
						console.log(err);
					});
			},
			navTo(url){
				uni.navigateTo({
					url
				})
			}
		}
	};
</script>

<style lang="scss">
	page,
	.content {
		width: 750rpx;
		height: 100%;
		background: #111111;

		.box {
			background: #222222;
			.box-top {
				height: 100rpx;
				display: flex;
				align-items: center;

				.shu {
					width: 2rpx;
					height: 30rpx;
					background: #A581FF;
					display: inline-block;
					margin: 0 20rpx 0 30rpx;
					line-height: 100rpx;
				}

				.pass-title {
					line-height: 100rpx;
					display: inline-block;
					font-size: 30rpx;
					font-weight: 500;
					color: #FFFFFF;
				}
			}

			.box-bottom {
				
				
				.ipt{
					border-top:2rpx solid #F3F3F3;
					padding: 0 30rpx;
					display: flex;
					align-items: center;
					// justify-content: space-between;
					
					.text{
						width: 150rpx;
						font-size: 26rpx;
						font-weight: 500;
						color: #FFFFFF;
						line-height: 80rpx;
					}
					.input{
						
					}
					.yzm{
						margin-left: 140rpx;
						font-size: 26rpx;
						font-weight: 500;
						color: #A581FF;
						line-height: 100rpx;
					}
				}
			}

		}

		.button {
			margin-top: 60rpx;
			width: 690rpx;
			height: 80rpx;
			background: $bgBaseBg;
			border-radius: 40rpx;

			font-size: 30rpx;
			font-weight: bold;
			color: #FFFFFF;
			line-height: 80rpx;
		}

	}
</style>
