phone.vue 3.1 KB

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