pwd-retrieve.vue 4.4 KB
Newer Older
芊里 已提交
1
<template>
DCloud_JSON's avatar
DCloud_JSON 已提交
2 3
	<view class="content">
		<!-- 顶部文字 -->
4
		<text v-show="isPhone" class="login-iknow" >{{tipText}}</text>
DCloud_JSON's avatar
DCloud_JSON 已提交
5 6 7 8 9 10 11 12 13 14 15
		<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
		<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">
16
						<uni-send-sms-code ref="shortCode" :phone="formData.phone"></uni-send-sms-code>
DCloud_JSON's avatar
DCloud_JSON 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30
					</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>
芊里 已提交
31 32 33
	</view>
</template>

DCloud_JSON's avatar
DCloud_JSON 已提交
34
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
35
	import mixin from '../common/login-page.mixin.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
36
	export default {
DCloud_JSON's avatar
DCloud_JSON 已提交
37
		mixins: [mixin],
芊里 已提交
38 39
		data() {
			return {
DCloud_JSON's avatar
DCloud_JSON 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
				formData: {
					"phone": "",
					'pwd': '',
					'pwd2': ''
				},
				rules: {
					phone: {
						rules: [{
								required: true,
								errorMessage: '请输入手机号',
							},
							{
								pattern: /^1\d{10}$/,
								errorMessage: '手机号格式不正确',
							}
						]
					},
					code: {
						rules: [{
								required: true,
								errorMessage: '请输入验证码',
							},
							{
								pattern: /^.{6}$/,
								errorMessage: '请输入6位验证码',
							}
						]
					},
					pwd: {
						rules: [{
								required: true,
								errorMessage: '请输入密码',
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: '密码应为6到20位',
							}
						]
					},
					pwd2: {
						rules: [{
								required: true,
								errorMessage: '请确认密码',
							},
							{
								pattern: /^.{6,20}$/,
								errorMessage: '密码应为6到20位',
							},
							{
								validateFunction: function(rule, value, data, callback) {
									console.log(value);
									if (value != data.pwd) {
										callback('两次输入密码不一致')
									};
									return true
								}
							}
						]
					}
				}
芊里 已提交
100 101 102 103
			}
		},
		computed: {
			tipText() {
DCloud_JSON's avatar
DCloud_JSON 已提交
104
				return `验证码已通过短信发送至${this.formData.phone}。密码为6 - 20位`
芊里 已提交
105 106
			},
			canSubmit() {
107
				return this.isPhone && this.isPwd && this.isCode;
DCloud_JSON's avatar
DCloud_JSON 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
			},
			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;
芊里 已提交
123 124 125
			}
		},
		onLoad(event) {
芊里 已提交
126
			if (event && event.phoneNumber) {
芊里 已提交
127
				this.formData.phone = event.phoneNumber;
芊里 已提交
128 129
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
130
		onReady() {
DCloud_JSON's avatar
DCloud_JSON 已提交
131
			if (this.formData.phone) {
DCloud_JSON's avatar
DCloud_JSON 已提交
132 133 134 135 136 137 138
				this.$refs.shortCode.start();
			}
		},
		methods: {
			/**
			 * 完成并提交
			 */
DCloud_JSON's avatar
DCloud_JSON 已提交
139
			submit() {
DCloud_JSON's avatar
DCloud_JSON 已提交
140
				this.$refs.form.submit()
DCloud_JSON's avatar
DCloud_JSON 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
					.then(res => {
						this.request('user-center/resetPwdBySmsCode', {
							"mobile": this.formData.phone,
							"code": this.formData.code,
							"password": this.formData.pwd
						}, result => {
							console.log(result);
							uni.showToast({
								title: result.msg,
								icon: 'none'
							});
							if (result.code === 0) {
								uni.navigateBack()
							}
						})
DCloud_JSON's avatar
DCloud_JSON 已提交
156
					})
芊里 已提交
157 158 159 160 161
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
162
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
163 164
	@import url("../common/login-page.css");

165 166
	.content{
		padding-top: 36rpx;
芊里 已提交
167
	}
168
</style>