Merge pull request 'change mobile' (#46) from zhy into master
Reviewed-on: http://git.luyuan.tk/luyuan/deming/pulls/46
This commit is contained in:
		
						commit
						5308f50e4e
					
				@ -4,7 +4,7 @@
 | 
			
		||||
			<view class="old-phone">
 | 
			
		||||
				<view class="phone-number">
 | 
			
		||||
					<view class="title">原手机号</view>
 | 
			
		||||
					<input type="text" v-model="oldNumber" placeholder="请输入手机号码" />
 | 
			
		||||
					<input type="text" v-model="oldMobile" placeholder="请输入手机号码" />
 | 
			
		||||
				</view>
 | 
			
		||||
				<view class="code">
 | 
			
		||||
					<view class="title">验证码</view>
 | 
			
		||||
@ -16,7 +16,7 @@
 | 
			
		||||
			<view class="new-phone">
 | 
			
		||||
				<view class="phone-number">
 | 
			
		||||
					<view class="title">新手机号</view>
 | 
			
		||||
					<input type="text" v-model="newNumber" placeholder="请输入手机号码" />
 | 
			
		||||
					<input type="text" v-model="newMobile" placeholder="请输入手机号码" />
 | 
			
		||||
				</view>
 | 
			
		||||
				<view class="code">
 | 
			
		||||
					<view class="title">验证码</view>
 | 
			
		||||
@ -27,51 +27,53 @@
 | 
			
		||||
				<u-toast ref="uToast" />
 | 
			
		||||
			</view>
 | 
			
		||||
		</view>
 | 
			
		||||
		<view class="tips">注意:修改手机号需要原手机号获取验证码,无原手机验证码,请联系后台</view>
 | 
			
		||||
		<view class="btn">保存</view>
 | 
			
		||||
		<view class="tips">注意:修改手机号需要原手机号获取验证码,无原手机验证码,请联系客服</view>
 | 
			
		||||
		<view class="btn" @click="changeMemberPhone">保存</view>
 | 
			
		||||
	</view>
 | 
			
		||||
</template>
 | 
			
		||||
<script>
 | 
			
		||||
export default {
 | 
			
		||||
	data() {
 | 
			
		||||
		return {
 | 
			
		||||
			oldNumber: '',
 | 
			
		||||
			oldMobile: '',
 | 
			
		||||
			oldCode: '',
 | 
			
		||||
			newNumber: '',
 | 
			
		||||
			newMobile: '',
 | 
			
		||||
			newCode: '',
 | 
			
		||||
			btnText: ['获取验证码', '获取验证码'],
 | 
			
		||||
			seconds: 60, // 获取验证码间隔时间
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
	methods: {
 | 
			
		||||
		verifyValue(type) {
 | 
			
		||||
			const phone = type == 0 ? this.oldNumber : this.newNumber;
 | 
			
		||||
			return this.$u.test.mobile(phone);
 | 
			
		||||
		},
 | 
			
		||||
		// @param Number type 0: 原手机号 1: 新手机号
 | 
			
		||||
		getSmsCode (type) {
 | 
			
		||||
			if(!this.verifyValue(type)) {
 | 
			
		||||
				let tips = type == 0 ? '请填写正确的原手机号' : '请填写正确的新手机号';
 | 
			
		||||
		// 验证发送验证码
 | 
			
		||||
		verifySendCode(type) {
 | 
			
		||||
			const [phone, tips] = type == 0 
 | 
			
		||||
					? [this.oldMobile, '请填写正确的原手机号'] 
 | 
			
		||||
					: [this.newMobile, '请填写正确的新手机号'];
 | 
			
		||||
			if (!this.$u.test.mobile(phone)) {
 | 
			
		||||
				this.$u.toast(tips);
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			if(this.seconds > 0) {
 | 
			
		||||
				this.$u.toast('倒计时结束后再发送');
 | 
			
		||||
			return true;
 | 
			
		||||
		},
 | 
			
		||||
		// 验证修改绑定手机号
 | 
			
		||||
		verifyChangeMobile() {
 | 
			
		||||
			if(!this.$u.test.mobile(oldMobile)) {
 | 
			
		||||
				this.$u.toast('请填写正确的原手机号');
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			uni.showLoading({
 | 
			
		||||
				title: '正在获取验证码'
 | 
			
		||||
			})
 | 
			
		||||
			this.$u.api.sendSmsCode({
 | 
			
		||||
				member_mobile: type == 0 ? this.oldNumber: this.newNumber,
 | 
			
		||||
				smslog_type: 4 // 类型[1:注册,2:登录,3:找回密码,4:绑定手机]
 | 
			
		||||
			}).then(res => {
 | 
			
		||||
				uni.hideLoading();
 | 
			
		||||
				if(res.errCode == 0) {
 | 
			
		||||
 | 
			
		||||
				} else {
 | 
			
		||||
					this.$u.toast(res.message);
 | 
			
		||||
				}
 | 
			
		||||
			})
 | 
			
		||||
			if(this.$u.test.isEmpty(oldCode)) {
 | 
			
		||||
				this.$u.toast('验证码为空');
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			if(!this.$u.test.mobile(newMobile)) {
 | 
			
		||||
				this.$u.toast('请填写正确的新手机号');
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			if(this.$u.test.isEmpty(newCode)) {
 | 
			
		||||
				this.$u.toast('验证码为空');
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
			return true;
 | 
			
		||||
		},
 | 
			
		||||
		oldCodeChange(text) {
 | 
			
		||||
			this.$set(this.btnText, 0, text);
 | 
			
		||||
@ -79,39 +81,54 @@ export default {
 | 
			
		||||
		newCodeChange(text) {
 | 
			
		||||
			this.$set(this.btnText, 1, text);
 | 
			
		||||
		},
 | 
			
		||||
		// @param Number type 0: 原手机号 1: 新手机号
 | 
			
		||||
		async getSmsCode (type) {
 | 
			
		||||
			if(!this.verifySendCode(type)) return false;
 | 
			
		||||
			return await this.$u.api.sendSmsCode({
 | 
			
		||||
				member_mobile: type == 0 ? this.oldMobile: this.newMobile,
 | 
			
		||||
				smslog_type: 4 // 类型[1:注册,2:登录,3:找回密码,4:绑定手机]
 | 
			
		||||
			})
 | 
			
		||||
		},
 | 
			
		||||
		getCode(type) {
 | 
			
		||||
			const refs = type == 0 ? this.$refs.uOldCode : this.$refs.uNewCode;
 | 
			
		||||
			if(refs.canGetCode) {
 | 
			
		||||
				// 模拟向后端请求验证码
 | 
			
		||||
				uni.showLoading({
 | 
			
		||||
					title: '正在获取验证码'
 | 
			
		||||
				})
 | 
			
		||||
				setTimeout(() => {
 | 
			
		||||
				this.getSmsCode(type).then(res => {
 | 
			
		||||
					uni.hideLoading();
 | 
			
		||||
					// 这里此提示会被this.start()方法中的提示覆盖
 | 
			
		||||
					this.$u.toast('验证码已发送');
 | 
			
		||||
					// 通知验证码组件内部开始倒计时
 | 
			
		||||
					refs.start();
 | 
			
		||||
				}, 2000);
 | 
			
		||||
					if(res.errCode == 0) {
 | 
			
		||||
						// 这里此提示会被this.start()方法中的提示覆盖
 | 
			
		||||
						this.$u.toast(res.message);
 | 
			
		||||
						// 通知验证码组件内部开始倒计时
 | 
			
		||||
						refs.start();
 | 
			
		||||
					}
 | 
			
		||||
				}).catch(() => {
 | 
			
		||||
					uni.hideLoading();
 | 
			
		||||
					this.$u.toast('验证码发送错误');
 | 
			
		||||
				})
 | 
			
		||||
			} else {
 | 
			
		||||
				this.$u.toast('倒计时结束后再发送');
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		changeMemberPhone() {
 | 
			
		||||
			if(!this.verifyChangeMobile) return false;
 | 
			
		||||
			this.$u.api.changeMemberPhone({
 | 
			
		||||
				old_mobile: this.oldNumber,
 | 
			
		||||
				old_mobile: this.oldMobile,
 | 
			
		||||
				old_code: this.oldCode,
 | 
			
		||||
				new_mobile: this.newNumber,
 | 
			
		||||
				new_mobile: this.newMobile,
 | 
			
		||||
				new_code: this.newCode,
 | 
			
		||||
			}).then(res => {
 | 
			
		||||
 | 
			
		||||
				if(res.errCode == 0) {
 | 
			
		||||
					
 | 
			
		||||
				}
 | 
			
		||||
			})
 | 
			
		||||
		},
 | 
			
		||||
		end() {
 | 
			
		||||
			this.$u.toast('倒计时结束');
 | 
			
		||||
			// this.$u.toast('倒计时结束');
 | 
			
		||||
		},
 | 
			
		||||
		start() {
 | 
			
		||||
			this.$u.toast('倒计时开始');
 | 
			
		||||
			// this.$u.toast('倒计时开始');
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user