phone.vue 3.5 KB

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