change-phone.vue 4.1 KB

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