bindDialog.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="my-tel-dialog">
  3. <view class="my-tel-content">
  4. <view class="tel-close" @click="telClose"></view>
  5. <view class="yzm-row">
  6. <view class="my-tel-title">绑定新手机号</view>
  7. <view class="yzm-tip" v-if="bindObj.getYzmFlag">验证码已发送至:{{bindObj.telNumber}}</view>
  8. <view class="my-input-box">
  9. <input class="my-input" type="text" v-model="bindObj.yzmNumber" placeholder="请输入验证码" maxlength="6"
  10. @input="changeYzmInput" />
  11. <view class="close-btn" v-if="bindObj.clearYzmIcon" @click="clearYzm"></view>
  12. </view>
  13. <view @click="bindBtn" class="my-bind-btn">绑定</view>
  14. </view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import captcha from "../../components/captcha4/index.vue";
  20. import cacheManager from '@/utils/cacheManager.js';
  21. import {
  22. telBind,
  23. sendCode
  24. } from "@/api/login.js"
  25. import {
  26. toast
  27. } from "../../utils/common";
  28. export default {
  29. data() {
  30. return {
  31. bindObj: {
  32. telNumber: '',
  33. yzmNumber: '',
  34. clearYzmIcon: false,
  35. /*** 验证码 ***/
  36. yzmStatus: 'login-btn-disabled',
  37. timeLeft: 60, // 初始倒计时时间(秒)
  38. intervalId: null, // 定时器ID
  39. },
  40. }
  41. },
  42. methods: {
  43. telClose() {
  44. this.$emit('telClose')
  45. },
  46. // 清空验证码
  47. clearYzm() {
  48. this.bindObj.yzmNumber = '';
  49. this.bindObj.clearYzmIcon = false;
  50. },
  51. // 判断是否显示验证码的清除按钮
  52. changeYzmInput(event) {
  53. if (event.detail.value.length > 0) {
  54. this.bindObj.clearYzmIcon = true;
  55. } else {
  56. this.bindObj.clearYzmIcon = false;
  57. }
  58. },
  59. // 绑定按钮
  60. bindBtn() {
  61. if (this.bindObj.yzmNumber === '') {
  62. toast('验证码不能为空')
  63. return;
  64. }
  65. let req = {
  66. tel: this.bindObj.telNumber,
  67. code: this.bindObj.yzmNumber,
  68. }
  69. telBind(req).then(res => {
  70. if (res.code == 0) {
  71. toast('手机号绑定成功')
  72. this.updataTel(this.bindObj.telNumber);
  73. this.telReset();
  74. this.$emit('bindBtn')
  75. }
  76. })
  77. },
  78. // 在缓存中修改手机号
  79. updataTel(data) {
  80. cacheManager.updateObject('auth', {
  81. userName: data
  82. })
  83. }
  84. }
  85. }
  86. </script>