bind.vue 4.6 KB

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