bind.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="container">
  3. <view class="cu-form-group" style="margin: 30upx;border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  4. <view class="title">手机号</view>
  5. <input type="number" :value="mobile" placeholder="请输入手机号" maxlength="11" data-key="mobile" @input="inputChange" />
  6. </view>
  7. <view class="cu-form-group" style="margin: 30upx;border: 2upx solid whitesmoke;margin-bottom: 20px;border-radius: 30px">
  8. <text class="title">验证码</text>
  9. <input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code" @input="inputChange"
  10. @confirm="toLogin" />
  11. <button class="send-msg" @click="sendMsg" :disabled="sending">{{ sendTime }}</button>
  12. </view>
  13. <button class="confirm-btn" @click="toLogin" :disabled="logining">立即换绑</button>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import listCell from '@/components/com-input';
  19. export default {
  20. components: {
  21. listCell
  22. },
  23. data() {
  24. return {
  25. mobile: '',
  26. code: '',
  27. logining: false,
  28. sending: false,
  29. sendTime: '获取验证码',
  30. count: 60,
  31. }
  32. },
  33. methods: {
  34. inputChange(e) {
  35. const key = e.currentTarget.dataset.key;
  36. this[key] = e.detail.value;
  37. },
  38. navBack() {
  39. uni.navigateBack();
  40. },
  41. countDown() {
  42. const {
  43. count
  44. } = this;
  45. if (count === 1) {
  46. this.count = 60;
  47. this.sending = false;
  48. this.sendTime = '获取验证码'
  49. } else {
  50. this.count = count - 1;
  51. this.sending = true;
  52. this.sendTime = count - 1 + '秒后重新获取';
  53. setTimeout(this.countDown.bind(this), 1000);
  54. }
  55. },
  56. sendMsg() {
  57. const {
  58. mobile
  59. } = this;
  60. if (!mobile) {
  61. this.$queue.showToast("请输入手机号");
  62. } else if (mobile.length !== 11) {
  63. this.$queue.showToast("请输入正确的手机号");
  64. } else {
  65. this.$queue.showLoading("正在发送验证码...");
  66. this.$Request.getT('/appLogin/sendMsg/' + mobile + '/bind').then(res => {
  67. if (res.code === 0) {
  68. this.sending = true;
  69. this.$queue.showToast('验证码发送成功请注意查收');
  70. this.countDown();
  71. uni.hideLoading();
  72. } else {
  73. uni.hideLoading();
  74. uni.showModal({
  75. showCancel: false,
  76. title: '短信发送失败',
  77. content: res.msg ? res.msg : '请一分钟后再获取验证码'
  78. });
  79. }
  80. });
  81. }
  82. },
  83. toLogin() {
  84. const {
  85. mobile,
  86. code
  87. } = this;
  88. let userId = this.$queue.getData("userId");
  89. if (!mobile) {
  90. this.$queue.showToast("请输入手机号");
  91. } else if (mobile.length !== 11) {
  92. this.$queue.showToast("请输入正确的手机号");
  93. } else if (!code) {
  94. this.$queue.showToast("请输入验证码");
  95. } else {
  96. this.$queue.showLoading("正在绑定中...");
  97. this.$Request.postT("/app/updatePhone?msg=" + code + "&phone=" + mobile + "&userId=" + userId).then(res => {
  98. if (res.code === 0) {
  99. this.$queue.setData("mobile", mobile);
  100. this.$queue.showToast('修改成功');
  101. uni.switchTab({
  102. url: '/pages/my/index'
  103. });
  104. } else {
  105. uni.showModal({
  106. showCancel: false,
  107. title: '绑定失败',
  108. content: res.msg,
  109. });
  110. }
  111. uni.hideLoading();
  112. });
  113. }
  114. },
  115. },
  116. }
  117. </script>
  118. <style lang='scss'>
  119. .send-msg {
  120. border-radius: 30px;
  121. color: white;
  122. height: 30px;
  123. font-size: 14px;
  124. line-height: 30px;
  125. background: #e10a07;
  126. }
  127. .container {
  128. top: 0;
  129. padding-top: 32upx;
  130. position: relative;
  131. width: 100%;
  132. height: 100%;
  133. overflow: hidden;
  134. background: #111224;
  135. }
  136. .confirm-btn {
  137. width: 600upx;
  138. height: 80upx;
  139. line-height: 80upx;
  140. border-radius: 60upx;
  141. margin-top: 32upx;
  142. background: #5E81F9;
  143. color: #fff;
  144. font-size: 32upx;
  145. &:after {
  146. border-radius: 60px;
  147. }
  148. }
  149. </style>