123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <template>
- <zj-page-layout bgColor="#ffffff">
- <view class="all-container">
- <view class="input">
- <u-input clearable border="bottom" placeholder="" :value="mobile" :disabled="true">
- <view class="" style="" slot="prefix">
- <text class="kakkslakldsj">当前手机号码</text>
- </view>
- </u-input>
- </view>
- <view class="input">
- <u-input clearable border="bottom" placeholder="请输入手机号" v-model="phone">
- <view class="" style="" slot="prefix">
- <text class="kakkslakldsj">*新手机号码</text>
- </view>
- </u-input>
- </view>
- <view class="input">
- <u-input clearable border="bottom" placeholder="请输入验证码" v-model="code">
- <view class="" style="" slot="prefix">
- <text class="kakkslakldsj">*验证码</text>
- </view>
- <view class="" slot="suffix" @click="getCode">
- <text class="text">{{ countDown ? countDown + 'S' : '获取验证码' }}</text>
- </view>
- </u-input>
- </view>
- <u-button type="primary" text="确定" :disabled="!phone || !code" @click="submitForm"></u-button>
- <zjDialogVerification
- ref="verification"
- :isShow="isShowCodeDialog"
- :top="codeObj.yHeight"
- :bgImg="codeObj.bigImage"
- :maskImg="codeObj.smallImage"
- :isSuccess="codeObj.isSuccess"
- :isFail="codeObj.isFail"
- @close="isShowCodeDialog = false"
- @refresh="refresh"
- @finish="finish"
- >
- </zjDialogVerification>
- </view>
- </zj-page-layout>
- </template>
- <script>
- import zjDialogVerification from '@/components/zj-dialog/zj-dialog-verification.vue'
- import { getStorage } from '@/common/utils/storage.js'
- export default {
- components: {
- zjDialogVerification
- },
- data() {
- return {
- phone: '',
- code: '',
- getCodeText: '获取验证码',
- countDown: 0,
- timer: null,
- isShowCodeDialog: false,
- codeObj: {
- bigImage: '',
- smallImage: '',
- key: '',
- yHeight: '',
- isSuccess: false,
- isFail: false
- }
- }
- },
- computed: {
- userInfo() {
- return getStorage('user')
- },
- mobile() {
- return this?.userInfo?.mobile
- }
- },
- methods: {
- // 获取验证码
- getCode() {
- if (!this.phone) {
- this.$toast('请先填写手机号码')
- return false
- }
- if (this.countDown != 0) {
- this.$toast('请勿频繁获取验证码')
- return false
- }
- if (!/^1[3456789]\d{9}$/.test(this.phone)) {
- this.$toast('请填写正确的手机号码')
- return false
- }
- // this.init();
- this.isShowCodeDialog = true
- this.$refs.verification.refresh()
- },
- // 提交表单
- submitForm() {
- if (!this.phone) {
- this.$toast('请先填写手机号码')
- return false
- }
- if (!/^1[3456789]\d{9}$/.test(this.phone)) {
- this.$toast('请填写正确的手机号码')
- return false
- }
- if (this.phone == this.mobile) {
- this.$toast('不能和原号码一样')
- return false
- }
- if (!this.code) {
- this.$toast('请先填写验证码')
- return false
- }
- this.$api
- .post('/user/phone/upBind', {
- phone: this.phone,
- code: this.code
- })
- .then(res => {
- this.$successToast('申请成功')
- setTimeout(() => {
- this.$navToPage(
- {
- delta: 1
- },
- 'navigateBack'
- )
- }, 1000)
- })
- },
- // 获取图片验证码
- init() {
- this.$api.get('/common/getVerifi').then(res => {
- this.codeObj = res.data
- })
- },
- // 刷新验证码
- refresh() {
- this.init()
- },
- // 验证结束
- finish(value) {
- this.$api
- .post('/user/sms/send', {
- phone: this.phone,
- key: this.codeObj.key,
- vrifyCode: Math.round(value)
- })
- .then(res => {
- this.countDown = 60
- this.codeObj.isSuccess = true
- this.codeObj.isFail = false
- setTimeout(() => {
- this.isShowCodeDialog = false
- this.$toast('短信发送成功')
- }, 1500)
- this.countDown--
- this.timer = setInterval(() => {
- this.countDown--
- if (this.countDown == 0) {
- this.getCodeText = '重新获取'
- clearInterval(this.timer)
- }
- }, 1000)
- })
- .catch(res => {
- this.isShowCodeDialog = false
- this.codeObj.isSuccess = false
- this.codeObj.isFail = false
- // setTimeout(() => {
- // this.$refs.verification.refresh()
- // }, 1500)
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .kakkslakldsj {
- display: inline-block;
- width: 220rpx;
- }
- .all-container {
- padding: 0 30rpx;
- .input {
- margin-top: 30rpx;
- ::v-deep .u-input {
- .iconfont {
- font-size: 36rpx;
- color: $theme-color;
- font-weight: 600;
- margin-right: 12rpx;
- }
- .text {
- color: $theme-color;
- }
- }
- }
- ::v-deep .u-button {
- margin-top: 60rpx;
- }
- }
- </style>
|