userphone.vue 3.9 KB

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