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:
hansu 2020-07-03 11:07:40 +08:00
commit 5308f50e4e

View File

@ -4,7 +4,7 @@
<view class="old-phone"> <view class="old-phone">
<view class="phone-number"> <view class="phone-number">
<view class="title">原手机号</view> <view class="title">原手机号</view>
<input type="text" v-model="oldNumber" placeholder="请输入手机号码" /> <input type="text" v-model="oldMobile" placeholder="请输入手机号码" />
</view> </view>
<view class="code"> <view class="code">
<view class="title">验证码</view> <view class="title">验证码</view>
@ -16,7 +16,7 @@
<view class="new-phone"> <view class="new-phone">
<view class="phone-number"> <view class="phone-number">
<view class="title">新手机号</view> <view class="title">新手机号</view>
<input type="text" v-model="newNumber" placeholder="请输入手机号码" /> <input type="text" v-model="newMobile" placeholder="请输入手机号码" />
</view> </view>
<view class="code"> <view class="code">
<view class="title">验证码</view> <view class="title">验证码</view>
@ -27,51 +27,53 @@
<u-toast ref="uToast" /> <u-toast ref="uToast" />
</view> </view>
</view> </view>
<view class="tips">注意修改手机号需要原手机号获取验证码无原手机验证码请联系后台</view> <view class="tips">注意修改手机号需要原手机号获取验证码无原手机验证码请联系客服</view>
<view class="btn">保存</view> <view class="btn" @click="changeMemberPhone">保存</view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
oldNumber: '', oldMobile: '',
oldCode: '', oldCode: '',
newNumber: '', newMobile: '',
newCode: '', newCode: '',
btnText: ['获取验证码', '获取验证码'], btnText: ['获取验证码', '获取验证码'],
seconds: 60, // seconds: 60, //
} }
}, },
methods: { methods: {
verifyValue(type) { //
const phone = type == 0 ? this.oldNumber : this.newNumber; verifySendCode(type) {
return this.$u.test.mobile(phone); const [phone, tips] = type == 0
}, ? [this.oldMobile, '请填写正确的原手机号']
// @param Number type 0: 1: : [this.newMobile, '请填写正确的新手机号'];
getSmsCode (type) { if (!this.$u.test.mobile(phone)) {
if(!this.verifyValue(type)) {
let tips = type == 0 ? '请填写正确的原手机号' : '请填写正确的新手机号';
this.$u.toast(tips); this.$u.toast(tips);
return false; return false;
} }
if(this.seconds > 0) { return true;
this.$u.toast('倒计时结束后再发送'); },
//
verifyChangeMobile() {
if(!this.$u.test.mobile(oldMobile)) {
this.$u.toast('请填写正确的原手机号');
return false;
} }
uni.showLoading({ if(this.$u.test.isEmpty(oldCode)) {
title: '正在获取验证码' this.$u.toast('验证码为空');
}) return false;
this.$u.api.sendSmsCode({ }
member_mobile: type == 0 ? this.oldNumber: this.newNumber, if(!this.$u.test.mobile(newMobile)) {
smslog_type: 4 // [1:,2:,3:,4:] this.$u.toast('请填写正确的新手机号');
}).then(res => { return false;
uni.hideLoading(); }
if(res.errCode == 0) { if(this.$u.test.isEmpty(newCode)) {
this.$u.toast('验证码为空');
} else { return false;
this.$u.toast(res.message); }
} return true;
})
}, },
oldCodeChange(text) { oldCodeChange(text) {
this.$set(this.btnText, 0, text); this.$set(this.btnText, 0, text);
@ -79,39 +81,54 @@ export default {
newCodeChange(text) { newCodeChange(text) {
this.$set(this.btnText, 1, 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) { getCode(type) {
const refs = type == 0 ? this.$refs.uOldCode : this.$refs.uNewCode; const refs = type == 0 ? this.$refs.uOldCode : this.$refs.uNewCode;
if(refs.canGetCode) { if(refs.canGetCode) {
//
uni.showLoading({ uni.showLoading({
title: '正在获取验证码' title: '正在获取验证码'
}) })
setTimeout(() => { this.getSmsCode(type).then(res => {
uni.hideLoading(); uni.hideLoading();
// this.start() if(res.errCode == 0) {
this.$u.toast('验证码已发送'); // this.start()
// this.$u.toast(res.message);
refs.start(); //
}, 2000); refs.start();
}
}).catch(() => {
uni.hideLoading();
this.$u.toast('验证码发送错误');
})
} else { } else {
this.$u.toast('倒计时结束后再发送'); this.$u.toast('倒计时结束后再发送');
} }
}, },
changeMemberPhone() { changeMemberPhone() {
if(!this.verifyChangeMobile) return false;
this.$u.api.changeMemberPhone({ this.$u.api.changeMemberPhone({
old_mobile: this.oldNumber, old_mobile: this.oldMobile,
old_code: this.oldCode, old_code: this.oldCode,
new_mobile: this.newNumber, new_mobile: this.newMobile,
new_code: this.newCode, new_code: this.newCode,
}).then(res => { }).then(res => {
if(res.errCode == 0) {
}
}) })
}, },
end() { end() {
this.$u.toast('倒计时结束'); // this.$u.toast('');
}, },
start() { start() {
this.$u.toast('倒计时开始'); // this.$u.toast('');
} }
}, },
}; };