pwd-retrieve.vue 3.1 KB
Newer Older
芊里 已提交
1
<template>
DCloud_JSON's avatar
DCloud_JSON 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
	<view class="content">
		<!-- 顶部文字 -->
		<text class="title">重置密码</text>
		<login-ikonw v-show="isPhone" class="login-iknow" :text="tipText"></login-ikonw>
		<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
		<uni-forms ref="form" :value="formData" :rules="rules">
			<uni-forms-item name="phone">
				<!-- focus规则如果上一页携带来“手机号码”数据就focus验证码输入框,否则focus手机号码输入框 -->
				<uni-easyinput :focus="!formData.phone.length" type="number" class="easyinput" :inputBorder="false"
					v-model="formData.phone" maxlength="11" placeholder="请输入手机号"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="code">
				<uni-easyinput :focus="formData.phone.length!=0" type="number" class="easyinput" :inputBorder="false"
					v-model="formData.code" maxlength="6" placeholder="请输入验证码">
					<template slot="right">
						<send-sms-code ref="shortCode" :phone="formData.phone"></send-sms-code>
					</template>
				</uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false"
					v-model="formData.pwd" placeholder="请输入新密码"></uni-easyinput>
			</uni-forms-item>
			<uni-forms-item name="pwd2">
				<uni-easyinput type="password" class="easyinput" :inputBorder="false"
					v-model="formData.pwd2" placeholder="请确认新密码"></uni-easyinput>
			</uni-forms-item>
			<button class="send-btn-box" :disabled="!canSubmit" :type="canSubmit?'primary':'default'"
				@click="submit">完成</button>
		</uni-forms>
芊里 已提交
32 33 34
	</view>
</template>

DCloud_JSON's avatar
DCloud_JSON 已提交
35
<script>
36
import mixin from '../common/loginPage.mixin.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
37
	export default {
芊里 已提交
38
		mixins:[mixin],
芊里 已提交
39 40 41 42 43 44
		data() {
			return {
			}
		},
		computed: {
			tipText() {
DCloud_JSON's avatar
DCloud_JSON 已提交
45
				return `验证码已通过短信发送至${this.formData.phone}。密码为6 - 20位`
芊里 已提交
46 47
			},
			canSubmit() {
48
				return this.isPhone && this.isPwd && this.isCode;
DCloud_JSON's avatar
DCloud_JSON 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
			},
			isPhone(){
				let reg_phone = /^1\d{10}$/;
				let isPhone = reg_phone.test(this.formData.phone);
				return isPhone;
			},
			isPwd(){
				let reg_pwd = /^.{6,20}$/;
				let isPwd = reg_pwd.test(this.formData.pwd);
				return isPwd;
			},
			isCode(){
				let reg_code = /^\d{6}$/;
				let isCode = reg_code.test(this.formData.code);
				return isCode;
芊里 已提交
64 65 66
			}
		},
		onLoad(event) {
芊里 已提交
67
			if (event && event.phoneNumber) {
芊里 已提交
68
				this.formData.phone = event.phoneNumber;
芊里 已提交
69 70
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
		onReady() {
			if(this.formData.phone){
				this.$refs.shortCode.start();
			}
		},
		methods: {
			/**
			 * 完成并提交
			 */
			submit(){
				this.$refs.form.submit()
				.then(res=>{
					this.request('user-center/resetPwdBySmsCode',{
						"mobile":this.formData.phone,
						"code":this.formData.code,
						"password":this.formData.pwd
DCloud_JSON's avatar
DCloud_JSON 已提交
87
					},result=>{
DCloud_JSON's avatar
DCloud_JSON 已提交
88 89 90 91 92 93 94 95 96 97
						console.log(result);
						uni.showToast({
							title: result.msg,
							icon: 'none'
						});
						if(result.code === 0){
							uni.navigateBack()
						}
					})
				})
芊里 已提交
98 99 100 101 102
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
103
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
104
	@import url("../common/login-page.css");
DCloud_JSON's avatar
DCloud_JSON 已提交
105 106
	.content-top-title{
		margin-bottom: 6px;
芊里 已提交
107
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
108
</style>