change-phone.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="change-phone">
  3. <view class="content">
  4. <view class="form">
  5. <navigator url="../phone-area/phone-area" class="phone-area">
  6. <text class="text">国家/地区</text>
  7. <text class="area">{{ areaName }}({{ areaCode }})</text>
  8. <text class="icon cuIcon-right"></text>
  9. </navigator>
  10. <view class="item">
  11. <text class="icon cuIcon-mobilefill"></text>
  12. <input maxlength="11" type="number" v-model="phone" placeholder="请输入要换绑的手机号" />
  13. <text v-if="phone" class="cuIcon-roundclosefill" @tap="phone=''"></text>
  14. </view>
  15. <view class="item">
  16. <text class="icon cuIcon-markfill"></text>
  17. <input maxlength="6" type="number" v-model="verifycode" placeholder="请输入6位验证码" />
  18. <text v-if="verifycode" class="cuIcon-roundclosefill" @tap="clearVerify"></text>
  19. <view class="countdown" @tap="getCode">
  20. 发送验证码 <text v-if="countDown">{{ ' ' + countDown }}</text>
  21. </view>
  22. </view>
  23. </view>
  24. <button class="big-btn bg" @tap="submit">立即换绑</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. _API_ChangeBindCode,
  31. _API_ChangeBindPhone
  32. } from '@/apis/verify.js'
  33. export default {
  34. data() {
  35. return {
  36. areaName: '中国大陆', // 手机号地区名称
  37. areaCode: '+86', // 手机号地区代码
  38. phone: '', // 手机号
  39. verifycode: '', // 验证码
  40. countDown: 0, // 倒计时
  41. };
  42. },
  43. created() {
  44. uni.$on('CHOOSEPHONECODE', (name, code) => { // 监听 chooseArea 事件更新
  45. this.areaName = name // 修改选择的手机号地区名称
  46. this.areaCode = code // 修改选择的手机号地区代码
  47. })
  48. },
  49. methods: {
  50. getCode() { // 点击获取手机验证码
  51. if (this.phone.length) { // 手机号是否输入
  52. if (this.countDown) { // 如果正在倒计时
  53. uni.toast('验证码已发送,请稍后重试')
  54. } else {
  55. uni.showLoading({
  56. mask: true
  57. }) // 显示 loading
  58. _API_ChangeBindCode({
  59. mobile: this.phone,
  60. code: this.areaCode
  61. }).then(res => {
  62. if (res.code == 200) {
  63. uni.toast('验证码发送成功') // 提示邀请码发送成功
  64. this.countDown = 120 // 倒计时时长
  65. this.timer = setInterval(() => { // 开始倒计时
  66. this.countDown--
  67. if (this.countDown <= 0) { // 倒计时结束清除倒计时
  68. this.countDown = 0
  69. clearInterval(this.timer)
  70. }
  71. }, 1000)
  72. } else { // code 300 表示禁止获取验证码,禁止登录
  73. uni.toast(res.message)
  74. }
  75. })
  76. }
  77. } else {
  78. uni.toast('手机号格式不正确,请重新输入')
  79. }
  80. },
  81. submit() { // 立即换绑
  82. if (!(this.verifycode.length == 6)) {
  83. uni.toast('验证码格式不正确,请重新输入');
  84. return
  85. }
  86. uni.showLoading({
  87. mask: true
  88. }) // 显示 loading
  89. _API_ChangeBindPhone({
  90. mobile: this.phone,
  91. verify_code: this.verifycode,
  92. code: this.areaCode
  93. }).then(res => {
  94. if (res.code == 200) {
  95. this.$store.commit('app/LOGOUT')
  96. uni.reLaunch({
  97. url: '../login-reg/login-reg'
  98. })
  99. } else {
  100. uni.toast(res.message)
  101. }
  102. })
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss">
  108. .change-phone {
  109. @include page();
  110. .content {
  111. .form {
  112. padding: 30rpx;
  113. margin-top: 10rpx;
  114. box-sizing: border-box;
  115. background-color: #FFFFFF;
  116. .phone-area {
  117. @include flex();
  118. justify-content: space-between;
  119. .text {
  120. font-size: 32rpx;
  121. }
  122. .area {
  123. color: #42b983;
  124. }
  125. }
  126. .item {
  127. @include flex();
  128. height: 110rpx;
  129. padding-top: 20rpx;
  130. box-sizing: border-box;
  131. color: $app-sec-text-color;
  132. border-bottom: 1rpx solid #B2B2B2;
  133. .icon,
  134. .cuIcon-roundclosefill {
  135. margin: 0 20rpx;
  136. font-size: 36rpx;
  137. }
  138. input {
  139. flex: 1;
  140. height: 84rpx;
  141. margin-left: 15rpx;
  142. }
  143. .countdown {
  144. @include flex();
  145. height: 50rpx;
  146. font-size: 24rpx;
  147. padding: 0 20rpx;
  148. background: #FFEFF0;
  149. margin-right: 20rpx;
  150. border-radius: 33rpx;
  151. color: $app-base-color;
  152. text {
  153. margin-left: 8rpx;
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. </style>