金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
4.0 KiB

  1. <template>
  2. <view>
  3. <lf-nav title="旧手机号验证" :showIcon="true"></lf-nav>
  4. <view class="content">
  5. <view class="list">
  6. <view class="lf-flex">
  7. <view class="lf-font-28 lf-color-black" style="width: 140rpx;">旧手机号</view>
  8. <input class="input" placeholder="请输入旧手机号" v-model="phone" maxlength="11" />
  9. </view>
  10. <view class="clear" v-if="phone.length" @click="phone = ''">
  11. <text class="lf-iconfont icon-status-error"></text>
  12. </view>
  13. </view>
  14. <view class="list">
  15. <view class="lf-flex">
  16. <view class="lf-font-28 lf-color-black" style="width: 140rpx;">验证码</view>
  17. <input class="input input-code" placeholder="请输入验证码" maxlength="8" v-model="code" />
  18. </view>
  19. <view class="code" :class="{'active-bg': is_code}" @click="getCode">
  20. <text>{{ is_code ? num +'秒后重新获取' : '获取验证码' }}</text>
  21. </view>
  22. </view>
  23. </view>
  24. <button class="next-btn" hover-class="lf-opacity" @click="next">下一步</button>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data(){
  30. return {
  31. phone: '',
  32. code: '',
  33. is_code: false,
  34. timer: null,
  35. num: 60,
  36. token: ''
  37. }
  38. },
  39. onLoad(){
  40. var token = this.$cookieStorage.get('user_token');
  41. this.token = token;
  42. },
  43. onUnload(){
  44. if(this.timer){
  45. clearInterval(this.timer);
  46. this.timer = null;
  47. }
  48. },
  49. methods: {
  50. getCode(){
  51. let phone = this.phone;
  52. if(!phone) return this.$msg('请输入手机号');
  53. if(!this.$check(phone, 'mobile')) return this.$msg('请输入正确的手机号');
  54. if(this.is_code) return;
  55. this.is_code = true;
  56. if(this.timer){
  57. clearInterval(this.timer);
  58. this.timer = null;
  59. }
  60. this.getVerifyCode();
  61. this.timer = setInterval(() => {
  62. this.num--;
  63. if(this.num <= 0){
  64. clearInterval(this.timer);
  65. this.timer = null;
  66. this.num = 60;
  67. this.is_code = false;
  68. }
  69. }, 1000);
  70. },
  71. getVerifyCode(){
  72. this.$http.post({
  73. api: 'api/sms/verify-code',
  74. data: {
  75. mobile: this.phone
  76. },
  77. header: {
  78. 'Content-Type': 'application/x-www-form-urlencoded',
  79. Authorization: this.token
  80. }
  81. }).then(res => {
  82. if(res.data.success){
  83. this.$msg(res.data.message, {icon: 'success'});
  84. }else{
  85. this.$msg(res.data.message);
  86. if(this.timer){
  87. clearInterval(this.timer);
  88. this.timer = null;
  89. this.num = 60;
  90. this.is_code = false;
  91. }
  92. }
  93. })
  94. },
  95. next(){
  96. let phone = this.phone;
  97. if(!phone) return this.$msg('请输入手机号');
  98. if(!this.$check(phone, 'mobile')) return this.$msg('请输入正确的手机号');
  99. if(!this.code) return this.$msg('请输入验证码');
  100. this.$http.post({
  101. api: 'api/user/check_old_mobile',
  102. data: {
  103. code: this.code,
  104. mobile: this.phone
  105. },
  106. header: {
  107. Authorization: this.token
  108. }
  109. }).then(res => {
  110. console.log("11111res", res)
  111. if(res.data.code == 200){
  112. this.$url('/pages/user/my/newPhone');
  113. }else{
  114. this.$msg(res.data.message);
  115. }
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped="scoped">
  122. .content{
  123. padding: 0 32rpx;
  124. }
  125. .next-btn{
  126. width: 550rpx;
  127. height: 100rpx;
  128. background: #15716E;
  129. border-radius: 50rpx;
  130. position: fixed;
  131. bottom: 10vh;
  132. left: calc(50% - 275rpx);
  133. line-height: 100rpx;
  134. color: #FFFFFF;
  135. }
  136. .list{
  137. height: 106rpx;
  138. width: 100%;
  139. border-bottom: 1rpx solid #e5e5e5;
  140. display: flex;
  141. justify-content: space-between;
  142. align-items: center;
  143. &:nth-child(2n){
  144. margin-top: 30rpx;
  145. }
  146. .input{
  147. width: 380rpx;
  148. height: 80rpx;
  149. font-size: 32rpx;
  150. margin-left: 50rpx;
  151. }
  152. .input-code{
  153. width: 290rpx;
  154. }
  155. .clear{
  156. padding: 20rpx;
  157. }
  158. .code{
  159. min-width: 180rpx;
  160. max-width: 220rpx;
  161. height: 64rpx;
  162. padding: 0 4rpx;
  163. font-size: 24rpx;
  164. color: #15716E;
  165. display: flex;
  166. justify-content: center;
  167. align-items: center;
  168. border-radius: 32rpx;
  169. border: 2rpx solid #15716E;
  170. }
  171. .active-bg{
  172. background: #efefef;
  173. }
  174. }
  175. </style>