|
|
|
<template>
|
|
|
|
<view class="page">
|
|
|
|
<view class="input">
|
|
|
|
<uni-easyinput type="number" v-model="form.phone" placeholder="请填写你的手机号" maxlength="11" :clearable="false" />
|
|
|
|
</view>
|
|
|
|
<view class="input code-wrap">
|
|
|
|
<uni-easyinput class="code" type="number" v-model="form.code" placeholder="验证码" maxlength="6" :clearable="false" />
|
|
|
|
<view class="send-code" @click="sendCode" :disabled="codeDisabled">{{ btnText }}</view>
|
|
|
|
</view>
|
|
|
|
<button type="primary" @click="submit">确认</button>
|
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { sendPhoneOrEmailCode, changePhoneNumber, checkIfThePhoneNumberExists } from '@/apis/modules/user.js'
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
userId: '',
|
|
|
|
form: {
|
|
|
|
phone: '',
|
|
|
|
code: ''
|
|
|
|
},
|
|
|
|
codeDisabled: false,
|
|
|
|
phoneTimer: null,
|
|
|
|
phoneOpener: '',
|
|
|
|
btnText: '发送验证码',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
// 发送验证码
|
|
|
|
sendCode() {
|
|
|
|
const { phone } = this.form
|
|
|
|
if (!phone) return this.$util.errMsg('请输入手机号')
|
|
|
|
if (!/^1[3456789]\d{9}$/.test(phone) && !/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(phone)) return this.$util.errMsg('请输入正确的手机号')
|
|
|
|
// 手机号判重
|
|
|
|
checkIfThePhoneNumberExists(phone).then(() => {
|
|
|
|
sendPhoneOrEmailCode({
|
|
|
|
userId: this.userId,
|
|
|
|
phone,
|
|
|
|
types: 2
|
|
|
|
}).then(({ message }) => {
|
|
|
|
if (message.opener) {
|
|
|
|
this.phoneCountdown()
|
|
|
|
this.phoneOpener = message.opener
|
|
|
|
} else {
|
|
|
|
this.$util.errMsg(message)
|
|
|
|
}
|
|
|
|
}).catch(res => {})
|
|
|
|
}).catch(res => {})
|
|
|
|
},
|
|
|
|
// 验证码倒计时
|
|
|
|
phoneCountdown() {
|
|
|
|
let count = 60
|
|
|
|
if (!this.phoneTimer) {
|
|
|
|
this.codeDisabled = true
|
|
|
|
this.phoneTimer = setInterval(() => {
|
|
|
|
if (count > 0) {
|
|
|
|
count--
|
|
|
|
this.btnText = `${count}秒后重试`
|
|
|
|
} else {
|
|
|
|
this.codeDisabled = false
|
|
|
|
clearInterval(this.phoneTimer)
|
|
|
|
this.phoneTimer = null
|
|
|
|
this.btnText = `发送验证码`
|
|
|
|
}
|
|
|
|
}, 1000)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 提交
|
|
|
|
submit() {
|
|
|
|
const { phone, code } = this.form
|
|
|
|
if (!phone) return this.$util.errMsg('请输入手机号')
|
|
|
|
if (!code) return this.$util.errMsg('请输入验证码')
|
|
|
|
changePhoneNumber(phone, code).then(res => {
|
|
|
|
this.$util.sucMsg('修改成功!')
|
|
|
|
setTimeout(() => {
|
|
|
|
uni.navigateBack()
|
|
|
|
}, 1500)
|
|
|
|
}).catch(res => {})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.page {
|
|
|
|
padding: 20px;
|
|
|
|
background-color: #fff;
|
|
|
|
}
|
|
|
|
/deep/.input {
|
|
|
|
margin-bottom: 15px;
|
|
|
|
.is-input-border {
|
|
|
|
border-color: #dedede !important;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.input {
|
|
|
|
margin-bottom: 20px;
|
|
|
|
}
|
|
|
|
.code-wrap {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
.code {
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
.send-code {
|
|
|
|
font-size: 24rpx;
|
|
|
|
}
|
|
|
|
</style>
|