phone.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <view class="container">
  3. <view class="row b-b">
  4. <text class="tit">手机号</text>
  5. <input class="input" v-model="account" type="text" placeholder="请填写手机号" placeholder-class="placeholder" />
  6. </view>
  7. <view>
  8. <view class="row b-b">
  9. <text class="tit">验证码</text>
  10. <input class="input" v-model="captcha" type="text" placeholder="请填写验证码"
  11. placeholder-class="placeholder" />
  12. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  13. </view>
  14. <button class="add-btn" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">提交</button>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. verify
  21. } from '@/api/login.js';
  22. import {
  23. mapState
  24. } from 'vuex';
  25. import {
  26. registerReset,
  27. binding
  28. } from '@/api/set.js';
  29. export default {
  30. data() {
  31. return {
  32. time: '', //保存倒计时对象
  33. countDown: 0, //倒计时
  34. account: '', //手机号
  35. captcha: '', //验证码
  36. password: '', //新密码
  37. loding: false //是否载入中
  38. };
  39. },
  40. watch: {
  41. // 监听倒计时
  42. countDown(i) {
  43. if (i == 0) {
  44. clearInterval(this.time);
  45. }
  46. }
  47. },
  48. computed: {
  49. ...mapState(['userInfo'])
  50. },
  51. onLoad() {
  52. if (this.userInfo.phone == null) {
  53. this.account = '';
  54. } else {
  55. this.account = this.userInfo.phone;
  56. this.show = false;
  57. }
  58. },
  59. methods: {
  60. //发送验证码
  61. verification() {
  62. let obj = this;
  63. if (this.account == '') {
  64. this.$api.msg('请输入电话号码');
  65. return;
  66. }
  67. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.account)) {
  68. this.$api.msg('请输入正确的手机号');
  69. return;
  70. }
  71. // 判断是否在倒计时
  72. if (obj.countDown > 0) {
  73. return false;
  74. } else {
  75. obj.countDown = 60;
  76. obj.time = setInterval(() => {
  77. obj.countDown--;
  78. }, 1000);
  79. //调用验证码接口
  80. verify({
  81. phone: obj.account,
  82. type: 'BDING_CODE'
  83. })
  84. .then(({
  85. data
  86. }) => {})
  87. .catch(err => {
  88. console.log(err);
  89. });
  90. }
  91. },
  92. confirm(e) {
  93. let obj = this;
  94. obj.loding = true;
  95. binding({
  96. phone: obj.account,
  97. captcha: obj.captcha
  98. })
  99. .then(({
  100. data
  101. }) => {
  102. obj.$api.msg('绑定成功!');
  103. setTimeout(function() {
  104. obj.loding = false;
  105. uni.switchTab({
  106. url: '/pages/user/user'
  107. });
  108. }, 1000);
  109. })
  110. .catch(err => {
  111. obj.loding = false;
  112. console.log(err);
  113. });
  114. }
  115. }
  116. };
  117. </script>
  118. <style lang="scss">
  119. page {
  120. background: $page-color-base;
  121. }
  122. .row {
  123. display: flex;
  124. align-items: center;
  125. position: relative;
  126. padding: 0 30rpx;
  127. height: 110rpx;
  128. background: #fff;
  129. .tit {
  130. flex-shrink: 0;
  131. width: 120rpx;
  132. font-size: 30rpx;
  133. color: $font-color-dark;
  134. }
  135. .input {
  136. flex: 1;
  137. font-size: 30rpx;
  138. color: $font-color-dark;
  139. }
  140. .iconlocation {
  141. font-size: 36rpx;
  142. color: $font-color-light;
  143. }
  144. }
  145. .add-btn {
  146. display: flex;
  147. align-items: center;
  148. justify-content: center;
  149. width: 690rpx;
  150. height: 80rpx;
  151. margin: 60rpx auto;
  152. font-size: $font-lg;
  153. color: #fff;
  154. background-color: $base-color;
  155. border-radius: 10rpx;
  156. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  157. }
  158. .bg-gray {
  159. background-color: $color-gray;
  160. }
  161. .code {
  162. color: #9C0B18;
  163. font-size: 23rpx;
  164. border-left: 1px solid #eeeeee;
  165. width: 150rpx;
  166. flex-shrink: 0;
  167. text-align: center;
  168. }
  169. </style>