职站学生端小程序版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.1 KiB

3 months ago
<template>
<view class="page">
3 months ago
<view class="line">
<view class="label">手机号</view>
<input type="number" v-model.trim="form.phone" placeholder="请填写你的手机号" maxlength="11" />
3 months ago
</view>
3 months ago
<view class="line code-wrap not-bd">
<view class="label">验证码</view>
<input class="code" type="number" v-model.trim="form.code" placeholder="请填写验证码" maxlength="6" />
3 months ago
<view class="send-code" @click="sendCode" :disabled="codeDisabled">{{ btnText }}</view>
</view>
3 months ago
<view class="btn" @click="submit">确认</view>
3 months ago
</view>
</template>
<script>
3 months ago
import { sendPhoneOrEmailCode, bindPhoneOrEmail } from '@/apis/modules/user.js'
3 months ago
export default {
data() {
return {
3 months ago
userId: uni.getStorageSync('userId'),
3 months ago
form: {
phone: '',
code: ''
},
codeDisabled: false,
phoneTimer: null,
phoneOpener: '',
3 months ago
btnText: '获取验证码',
3 months ago
}
},
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('请输入正确的手机号')
// 手机号判重
3 months ago
sendPhoneOrEmailCode({
userId: this.userId,
phone,
types: 2
}).then(({ message }) => {
if (message.opener) {
this.phoneCountdown()
this.phoneOpener = message.opener
} else {
this.$util.errMsg(message)
}
3 months ago
}).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('请输入验证码')
3 months ago
bindPhoneOrEmail({
userId: this.userId,
phone,
types: 2,
code,
opener: this.phoneOpener
}).then(res => {
3 months ago
this.$util.sucMsg('修改成功!')
setTimeout(() => {
uni.navigateBack()
}, 1500)
}).catch(res => {})
}
}
}
</script>
<style scoped lang="scss">
.page {
3 months ago
min-height: 100%;
3 months ago
padding: 20px;
background-color: #fff;
3 months ago
box-sizing: border-box;
.line {
display: flex;
align-items: center;
padding: 20rpx 0;
margin-bottom: 10rpx;
&:not(.not-bd) {
border-bottom: 1px solid #f3f3f3;
}
}
.label {
width: 200rpx;
font-size: 28rpx;
color: #565656;
}
input {
font-size: 28rpx;
color: #333;
}
.code {
flex: 1;
}
.send-code {
margin-left: 20rpx;
color: #4386ff;
font-size: 24rpx;
line-height: 36px;
}
.btn {
width: 300rpx;
height: 60rpx;
margin: 50rpx auto 0;
font-size: 30rpx;
text-align: center;
color: #fff;
line-height: 60rpx;
background-color: #007EFF;
border-radius: 40rpx;
3 months ago
}
}
</style>