phone.vue 3.9 KB

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