<template>
	<view class="container">
		<view class="top">
			<text class="iconfont icon-youjiantou zuojiantou" @click="goBack()"></text>
			<text>重置密码</text>
		</view>
		<view class="input-row">
			<input type="text" placeholder="6-20位数字字母组合"/>
			<input type="text" placeholder="再次确认"/>
		</view>
		<view class="forgetpsd">
			<button class="primary log-btn" @click="resetPassword()">修改密码</button>
			</view>
	</view>
</template>

<script>
	import api from "@/api/api";
	export default{
		data(){
			return {
				form:{
					mobile: uni.getStorageSync('user_mobile'),
					code:'',
					password:'',
				},
			}
		},
		components:{},
		onLoad(){
		
		},
		methods:{
			resetPassword(){
				const params = {
					...this.form
				}
				if(!common.passwordValid(this.form.password)){
					common.errorDialog(2,'请输入6-12位数字字母组合');
					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">
	.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;
		}
	}
</style>