bind.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 + '/bind').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. let openId = this.$queue.getData('openid') ? this.$queue.getData('openid') : '';
  88. const {
  89. mobile,
  90. code
  91. } = this;
  92. let userId = this.$queue.getData("userId");
  93. if (!mobile) {
  94. this.$queue.showToast("请输入手机号");
  95. } else if (mobile.length !== 11) {
  96. this.$queue.showToast("请输入正确的手机号");
  97. } else if (!code) {
  98. this.$queue.showToast("请输入验证码");
  99. } else {
  100. this.$queue.showLoading("正在绑定中...");
  101. let data={
  102. msg:code,
  103. phone:mobile,
  104. userId:userId,
  105. openId: openId,
  106. }
  107. this.$Request.postT('/app/Login/registerCode',data).then(res => {
  108. if (res.code === 0) {
  109. this.$queue.setData("mobile", mobile);
  110. // this.$queue.showToast('修改成功');
  111. uni.setStorageSync('token', res.token)
  112. uni.setStorageSync('userInfo', res.user)
  113. uni.setStorageSync('userId', res.user.userId)
  114. uni.setStorageSync('invitationCode', res.user.invitationCode)
  115. uni.setStorageSync('userId', res.user.userId)
  116. uni.setStorageSync('openId', res.user.openId)
  117. uni.switchTab({
  118. url: '/pages/my/index'
  119. });
  120. } else {
  121. uni.showModal({
  122. showCancel: false,
  123. title: '绑定失败',
  124. content: res.msg,
  125. });
  126. }
  127. uni.hideLoading();
  128. })
  129. // this.$Request.postT("/app/updatePhone?msg=" + code + "&phone=" + mobile + "&userId=" + userId).then(
  130. // res => {
  131. // if (res.code === 0) {
  132. // this.$queue.setData("mobile", mobile);
  133. // this.$queue.showToast('修改成功');
  134. // uni.switchTab({
  135. // url: '/pages/my/index'
  136. // });
  137. // } else {
  138. // uni.showModal({
  139. // showCancel: false,
  140. // title: '绑定失败',
  141. // content: res.msg,
  142. // });
  143. // }
  144. // uni.hideLoading();
  145. // });
  146. }
  147. },
  148. },
  149. }
  150. </script>
  151. <style lang='scss'>
  152. page {
  153. background: #FFFFFF;
  154. }
  155. .send-msg {
  156. border-radius: 30px;
  157. color: white;
  158. height: 30px;
  159. font-size: 14px;
  160. line-height: 30px;
  161. background: #00B88F;
  162. }
  163. .container {
  164. top: 0;
  165. padding-top: 32upx;
  166. position: relative;
  167. width: 100%;
  168. height: 100%;
  169. overflow: hidden;
  170. background: #FFFFFF;
  171. }
  172. .confirm-btn {
  173. width: 600upx;
  174. height: 80upx;
  175. line-height: 80upx;
  176. border-radius: 60upx;
  177. margin-top: 32upx;
  178. background: #00B88F;
  179. color: #fff;
  180. font-size: 32upx;
  181. &:after {
  182. border-radius: 60px;
  183. }
  184. }
  185. </style>