<template>
	<view class="container">
		<view class="top">
			<text class="iconfont icon-youjiantou zuojiantou" @click="goBack()"></text>
			<text>重置密码</text>
		</view>
		<view class="input-row">
			<input class="uni-input" password type="text" placeholder="密码(6-20位字母数字组合)" v-model="form.password"/>
			<input class="uni-input" password type="text" placeholder="再次确认" v-model="confirmPassword" />
		</view>
		<view class="forgetpsd" @click="resetPassword()">
			保存
		</view>
	</view>
</template>

<script>
	import common from '../../../common/common';
	import api from "@/api/api";
	export default{
		data(){
			return {
				form:{
					mobile: uni.getStorageSync('user_mobile'),
					code:'',
					password:'',
				},
				confirmPassword:''
			}
		},
		components:{},
		onLoad(options){
			this.form.code = options.code;
		},
		methods:{
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			resetPassword(){
				const params = {
					...this.form
				}
				if(!common.passwordValid(this.form.password)){
					common.errorDialog(2,'请输入6-12位数字字母组合');
					return false;
				}
				if(this.form.password != this.confirmPassword){
					common.errorDialog(2,'两次密码输入不一致');
					return false;
				}
				api.resetPassword(params).then((res)=>{
					if(res['success']){
						uni.showToast({
							title: '密码重置成功，请重新登录',
							duration: 5000,
							icon: 'none'					
						})
					uni.removeStorageSync('isLogin')
					uni.redirectTo({
						url:'/components/login/login'
					})
						//重置密码后需要密码登录
						this.form = {
							mobile:null,
							code:null,
							password:null,
						}
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'					
						})
					}
				})
			},
			
		},
		mounted() {
			
		}
	}
</script>

<style lang="scss" scoped>
	.top{
		display: flex;
		height: 80rpx;
		justify-content: space-between;
		align-items: center;
		position: relative;
		width: 100%;
		margin: 0 auto 60rpx auto;
		.zuojiantou{
			display: inline-block;
			transform: rotate(180deg);
			font-size: 30rpx;
			z-index: 1;
			position: absolute;
		}
		text:nth-child(2){
			width: 100%;
			text-align: center;
			position: absolute;
		}
	}
	.input-row{
		.uni-input{
			background: #F4F4F4;
			margin: 20rpx auto;
			height: 90rpx;
			line-height: 90rpx;
			width: 90%;
			padding-left: 10rpx;
		}
	}
	
	.forgetpsd {
		width: 60%;
		margin: 0 auto;
		height: 80rpx;
		line-height: 80rpx;
		border-radius: 100rpx;
		font-size: 34rpx;
		color: #FFFFFF;
		background: #20269B;
		text-align: center;
		position: absolute;
		bottom: 30rpx;
		left: 0;
		right: 0;
	}

</style>