phone.vue 3.5 KB

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