phone.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. uni.showToast({
  84. title:"请输入电话号码",
  85. icon:"none"
  86. })
  87. return;
  88. }
  89. if (this.account.length != 11) {
  90. uni.showToast({
  91. title:"请输入正确的手机号",
  92. icon:"none"
  93. })
  94. return;
  95. }
  96. // 判断是否在倒计时
  97. if (obj.countDown > 0) {
  98. return false;
  99. } else {
  100. obj.countDown = 60;
  101. obj.time = setInterval(() => {
  102. obj.countDown--;
  103. }, 1000);
  104. //调用验证码接口
  105. verify({
  106. phone: obj.account,
  107. type: 'BDING_CODE'
  108. })
  109. .then(({
  110. data
  111. }) => {})
  112. .catch(err => {
  113. console.log(err);
  114. });
  115. }
  116. },
  117. confirm(e) {
  118. let obj = this;
  119. obj.loding = true;
  120. binding({
  121. phone: obj.account,
  122. captcha: obj.captcha
  123. })
  124. .then(({
  125. data
  126. }) => {
  127. uni.showToast({
  128. title:"绑定成功",
  129. icon:"success"
  130. })
  131. setTimeout(function() {
  132. obj.loding = false;
  133. uni.switchTab({
  134. url: '/pages/user/user'
  135. });
  136. }, 1000);
  137. })
  138. .catch(err => {
  139. obj.loding = false;
  140. console.log(err);
  141. });
  142. }
  143. }
  144. };
  145. </script>
  146. <style lang="scss">
  147. page {
  148. background: $page-color-base;
  149. }
  150. .container{
  151. padding-top: 30rpx;
  152. }
  153. .listBox {
  154. margin: $page-row-spacing;
  155. border-radius: 20rpx;
  156. overflow: hidden;
  157. background-color: #FFFFFF;
  158. }
  159. .list {
  160. .input {
  161. text-align: right;
  162. font-size: $font-base;
  163. color: $color-gray;
  164. width: 100%;
  165. }
  166. .listItem {
  167. padding: 35rpx 40rpx;
  168. border-bottom: 1px solid $page-color-light;
  169. }
  170. .listIconImg {
  171. width: 36rpx;
  172. }
  173. .right {
  174. color: $font-color-light;
  175. font-size: $font-base;
  176. flex-grow: 1;
  177. .img {
  178. width: 26rpx;
  179. }
  180. }
  181. .titleBox {
  182. .title {
  183. color: $font-color-base;
  184. font-size: $font-base;
  185. }
  186. }
  187. }
  188. .bg-gray {
  189. background-color: $color-gray;
  190. }
  191. .code {
  192. color: #5dbc7c;
  193. font-size: 23rpx;
  194. border-left: 1px solid #eeeeee;
  195. padding-left: 20rpx;
  196. flex-shrink: 0;
  197. text-align: center;
  198. }
  199. </style>