phone.vue 3.9 KB

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