index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="content">
  3. <view class="title">
  4. <view>绑定手机号</view>
  5. </view>
  6. <view class="form"><input v-model="mobile" type="number" maxlength="11" placeholder="请输入手机号码" placeholder-class="placeholder" class="ipt" /></view>
  7. <view class="form dflex">
  8. <input v-model="code" type="number" maxlength="6" placeholder="请输入短信验证码" placeholder-class="placeholder" class="ipt flex" />
  9. <view class="yzm" @click="getCode()" v-text="sendMsg"></view>
  10. </view>
  11. <view class="btn" @click="submitBind">绑定</view>
  12. </view>
  13. </template>
  14. <script>
  15. const app = getApp();
  16. const req = require('../../utils/request.js');
  17. const api = require('../../utils/api.js');
  18. const util = require('../../utils/util.js');
  19. export default {
  20. data() {
  21. return {
  22. mobile: '', //手机号
  23. code: '', //code
  24. sendMsg: '获取验证码',
  25. isGetCodeDisabled: false,
  26. typeRole: '',
  27. userInfo: {}
  28. };
  29. },
  30. onLoad() {},
  31. methods: {
  32. jumpUrl(url) {
  33. uni.navigateTo({
  34. url: url
  35. });
  36. },
  37. getCode() {
  38. if (this.isGetCodeDisabled == true) return false;
  39. if (!this.mobile) {
  40. req.msg('请输入手机号');
  41. return;
  42. }
  43. if (!util.isMobile(this.mobile)) {
  44. req.msg('请输入11位的有效手机号');
  45. return;
  46. }
  47. req.postRequest(
  48. api.sms_bind_mobile,
  49. {
  50. mobile: this.mobile
  51. },
  52. data => {
  53. req.msg('验证码获取成功');
  54. let time = 60;
  55. let interval = setInterval(() => {
  56. time--;
  57. if (time == 0) {
  58. this.isGetCodeDisabled = false;
  59. this.sendMsg = '获取验证码';
  60. clearInterval(interval);
  61. } else {
  62. this.isGetCodeDisabled = true;
  63. this.sendMsg = time + '秒后再获取';
  64. }
  65. }, 1000);
  66. },
  67. true
  68. );
  69. },
  70. submitBind: function() {
  71. if (!this.mobile) {
  72. req.msg('请输入手机号');
  73. return;
  74. }
  75. if (!this.code) {
  76. req.msg('请输入验证码');
  77. return;
  78. }
  79. var dataP = {
  80. mobile: this.mobile,
  81. code: this.code
  82. };
  83. req.postRequest(
  84. api.mobile_bind_mobile,
  85. dataP,
  86. data => {
  87. this.userInfo = data;
  88. req.setStorage('AUTH_TOKEN', data.token);
  89. req.setStorage('userInfo', data);
  90. uni.navigateBack();
  91. },
  92. true
  93. );
  94. }
  95. }
  96. };
  97. </script>
  98. <style>
  99. @import './index.css';
  100. </style>