password.vue 4.5 KB
<template>
	<view class="login">
		<view class="icon">
			<view class="icontitle">
				忘记密码
			</view>
			<view class="bar flexwrap">
				<view class="name">
					手机号:
				</view>
				<view class="lastname">
					<input v-model="mobile" maxlength="16" type="text" value="" placeholder="请输入手机号" />
				</view>
			</view>
			<view class="bar flexwrap">
				<view class="name">
					验证码:
				</view>
				<view class="lastname">
					<input v-model="captcha" maxlength="4" type="number" value="" placeholder="请输入验证码" />
					<view class="code"  @click="getCode">
							{{num==0?'获取验证码':num + '秒重新发送'}}
					</view>
				</view>
			</view>
			<view class="bar flexwrap">
				<view class="name">
					密码:
				</view>
				<view class="lastname">
					<input v-model="newpassword" type="text" value="" placeholder="请输入密码" />
				</view>
			</view>
			<view class="bar flexwrap">
				<view class="name">
					确认密码:
				</view>
				<view class="lastname">
					<input v-model="confirmpassword" type="text" value="" placeholder="请确认密码" />
				</view>
			</view>
			<view class="loginbtn" @click="goReset">
				确认
			</view>
		</view>
	</view>
</template>

<script>
	import {sendCode,resetPassword} from '@/api/login.js'
	import {toa} from '@/utils/toast.js'
	export default {
		data() {
			return {
				mobile:'',
				captcha:'',
				newpassword:'',
				confirmpassword:'',
				clearId:'',
				num:0,
			};
		},
		methods: {
			getCode(){
				if(this.num>0) return
				if(!this.mobile) return toa.toast('请先输入手机号')
				if (!(/^1[34578]\d{9}$/.test(this.mobile))) return toa.toast('请输入正确手机号')
				this.sendCode()
			},
			async sendCode(){
			  try {
			    const res = await sendCode(this.mobile,'resetpwd')
				toa.success('发送成功')
				this.setInter()
			    console.log('sendCode', res)
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('sendCode', err)
			  }
			},
			setInter (){
			 	 this.num=60
				 this.clearId = setInterval(() => {
				         this.num --
				 }, 1000)
			},
			goReset(){
				if(!this.mobile) return toa.toast('请输入手机号')
				if(!this.captcha) return toa.toast('请输入验证码')
				if(!this.newpassword) return toa.toast('请输入密码')
				if(!this.confirmpassword) return toa.toast('请输入确认密码')
				this.resetPassword()
			},
			async resetPassword(){
			  try {
			    const res = await resetPassword(this.mobile,this.captcha,this.newpassword,this.confirmpassword)
			    console.log('resetPassword', res)
				setTimeout(()=>{
					toa.success('重置密码成功')
				},200)
				uni.navigateBack({})
			    // 保存数据
			  } catch (err) {
			 	uni.showToast({ title:err,icon:'none' })
			    console.log('resetPassword', err)
			  }
			},
		},
	}
</script>

<style lang="scss">
	.login {
		padding: 0 48rpx;
		box-sizing: border-box;

		.icon {
			.icontitle {
				margin-top: 152rpx;
				margin-left: 16rpx;
				margin-bottom: 80rpx;
				color: rgba(50, 50, 51, 1);
				font-size: 52rpx;
				font-weight: 700;
				font-family: "PingFang SC";
			}

			.bar {
				border-bottom: 1px solid #f0f0f0;
				padding: 40rpx 0;
				color: rgba(0, 0, 0, 1);
				font-size: 32rpx;
				font-weight: 500;
				font-family: "PingFang SC";

				.name {
					width: 180rpx;
				}

				.lastname {
					flex: 1;
					position: relative;

					input {
						width: 100%;
						// width: 260rpx;
					}

					.code {
						position: absolute;
						right: 0;
						top: 50%;
						transform: translate(-10%, -50%);
						color: rgba(0, 0, 0, 0.26);
						font-size: 32rpx;
						font-weight: 400;
						font-family: "PingFang SC";
					}
				}
			}

			.loginbtn {
				margin-top: 100rpx;
				width: 654rpx;
				height: 88rpx;
				border-radius: 28rpx;
				opacity: 1;
				color: rgba(0, 0, 0, 0.9);
				font-size: 32rpx;
				font-weight: 600;
				font-family: "PingFang SC";
				text-align: center;
				line-height: 88rpx;
				background: rgba(254, 208, 0, 1);
			}

			.passway {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 16rpx;

				text {
					&:first-child {
						color: rgba(0, 0, 0, 0.26);
						font-size: 24rpx;
						font-weight: 400;
						font-family: "PingFang SC";
					}

					&:last-child {
						color: rgba(254, 208, 0, 1);
						font-size: 26rpx;
						font-weight: 400;
						font-family: "PingFang SC";
					}
				}
			}
		}
	}
</style>