Files

149 lines
4.5 KiB
Vue
Raw Normal View History

2020-03-15 13:59:43 +08:00
<template>
<view class="ChangePassword">
<view class="list">
<view class="item">
2020-03-15 13:59:43 +08:00
<input type="number" placeholder="填写手机号码" v-model="phone" />
</view>
<view class="item acea-row row-between-wrapper">
2020-03-15 13:59:43 +08:00
<input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" />
2021-02-20 16:01:51 +08:00
<button class="code font-color-red" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">{{ text }}</button>
</view>
</view>
<view class="confirmBnt bg-color-red" @click="confirm">确认绑定</view>
</view>
2020-03-15 13:59:43 +08:00
</template>
<script>
2021-02-20 16:01:51 +08:00
import { mapGetters } from 'vuex'
import sendVerifyCode from '@/mixins/SendVerifyCode'
import { required, alpha_num, chs_phone } from '@/utils/validate'
import { validatorDefaultCatch } from '@/utils/dialog'
import { registerVerify, wxappBindingPhone } from '@/api/user'
2020-03-15 13:59:43 +08:00
export default {
2021-02-20 16:01:51 +08:00
name: 'BindingPhone',
2020-03-15 13:59:43 +08:00
components: {},
props: {},
2021-02-20 16:01:51 +08:00
data: function () {
2020-03-15 13:59:43 +08:00
return {
2021-02-20 16:01:51 +08:00
captcha: '',
phone: '', //手机号
}
2020-03-15 13:59:43 +08:00
},
mixins: [sendVerifyCode],
2021-02-20 16:01:51 +08:00
computed: mapGetters(['userInfo']),
mounted: function () {},
2020-03-15 13:59:43 +08:00
methods: {
async confirm() {
2021-02-20 16:01:51 +08:00
let that = this
const { phone, captcha } = that
2020-03-15 13:59:43 +08:00
try {
await that
.$validator({
2021-02-20 16:01:51 +08:00
phone: [chs_phone(chs_phone.message('手机号码')), alpha_num(alpha_num.message())],
captcha: [required(required.message('验证码')), alpha_num(alpha_num.message('验证码'))],
2020-03-15 13:59:43 +08:00
})
2021-02-20 16:01:51 +08:00
.validate({ phone, captcha })
2020-03-15 13:59:43 +08:00
} catch (e) {
2021-02-20 16:01:51 +08:00
return validatorDefaultCatch(e)
2020-03-15 13:59:43 +08:00
}
2021-02-20 16:01:51 +08:00
wxappBindingPhone({
2020-03-15 13:59:43 +08:00
phone: this.phone,
2021-02-20 16:01:51 +08:00
captcha: this.captcha,
2020-03-15 13:59:43 +08:00
})
.then(res => {
if (res.data !== undefined && res.data.is_bind) {
uni.showModal({
2021-02-20 16:01:51 +08:00
title: '提示',
content: '确认绑定?',
success: function (res) {
if (res.confirm) {
2021-02-20 16:01:51 +08:00
wxappBindingPhone({
phone: this.phone,
captcha: this.captcha,
2021-02-20 16:01:51 +08:00
step: 1,
})
.then(res => {
uni.showToast({
title: res.msg,
2021-02-20 16:01:51 +08:00
icon: 'none',
duration: 2000,
})
that.$yrouter.replace({
2021-02-20 16:01:51 +08:00
path: '/pages/user/PersonalData/index',
})
2020-03-15 13:59:43 +08:00
})
.catch(res => {
uni.showToast({
title: res.msg,
2021-02-20 16:01:51 +08:00
icon: 'none',
duration: 2000,
})
that.$yrouter.replace({
2021-02-20 16:01:51 +08:00
path: '/pages/user/PersonalData/index',
})
})
} else if (res.cancel) {
uni.showToast({
2021-02-20 16:01:51 +08:00
title: '已取消绑定',
icon: 'none',
duration: 2000,
})
that.$yrouter.replace({
2021-02-20 16:01:51 +08:00
path: '/pages/user/PersonalData/index',
})
2020-03-15 13:59:43 +08:00
}
2021-02-20 16:01:51 +08:00
},
})
2020-03-15 13:59:43 +08:00
} else {
2020-03-16 01:40:52 +08:00
uni.showToast({
2020-03-15 13:59:43 +08:00
title: res.msg,
2021-02-20 16:01:51 +08:00
icon: 'none',
duration: 2000,
})
that.$yrouter.replace({ path: '/pages/user/PersonalData/index' })
2020-03-15 13:59:43 +08:00
}
})
.catch(res => {
2020-03-16 01:40:52 +08:00
uni.showToast({
2020-03-15 13:59:43 +08:00
title: res.msg,
2021-02-20 16:01:51 +08:00
icon: 'none',
duration: 2000,
})
})
2020-03-15 13:59:43 +08:00
},
async code() {
2021-02-20 16:01:51 +08:00
let that = this
const { phone } = that
2020-03-15 13:59:43 +08:00
try {
await that
.$validator({
2021-02-20 16:01:51 +08:00
phone: [required(required.message('手机号码')), chs_phone(chs_phone.message())],
2020-03-15 13:59:43 +08:00
})
2021-02-20 16:01:51 +08:00
.validate({ phone })
2020-03-15 13:59:43 +08:00
} catch (e) {
2021-02-20 16:01:51 +08:00
return validatorDefaultCatch(e)
2020-03-15 13:59:43 +08:00
}
registerVerify({ phone: phone })
.then(res => {
2020-03-16 01:40:52 +08:00
uni.showToast({
2020-03-15 13:59:43 +08:00
title: res.msg,
2021-02-20 16:01:51 +08:00
icon: 'none',
duration: 2000,
})
that.sendCode()
2020-03-15 13:59:43 +08:00
})
.catch(res => {
2020-03-16 01:40:52 +08:00
uni.showToast({
2020-03-15 13:59:43 +08:00
title: res.msg,
2021-02-20 16:01:51 +08:00
icon: 'none',
duration: 2000,
})
})
},
},
}
2020-03-15 13:59:43 +08:00
</script>
2021-02-20 16:01:51 +08:00
<style lang=""></style>