phone.vue 3.4 KB

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