changePhoneNumber.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <view >
  3. <u-navbar title="修改手机号" >
  4. </u-navbar>
  5. <view class="login-form">
  6. <view class="login-form-item">
  7. <view class="input">
  8. <u-input type="number" v-model="form.telephone" placeholder="填写新手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  9. </view>
  10. </view>
  11. <view class="login-form-item">
  12. <view class="input">
  13. <u-input type="number" v-model="form.verifyCode" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  14. <view class="code" :style="isCodeTipsColor ? 'color: #999999;' : ''" @click="getCode">{{codeTips}}</view>
  15. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  16. </u-verification-code>
  17. </view>
  18. </view>
  19. </view>
  20. <u-button class="login-btn" type="success" shape="circle" @click="confirmChange">确定修改</u-button>
  21. </view>
  22. </template>
  23. <script>
  24. import * as loginApi from '@/apis/login.js'
  25. import * as mineApi from '@/apis/youth/mine.js'
  26. import {
  27. checkPhone
  28. } from '@/apis/utils'
  29. export default {
  30. data() {
  31. return {
  32. form: {
  33. telephone: '',
  34. verifyCode: '',
  35. },
  36. isSendMsgIng: false,
  37. isCodeTipsColor: false,
  38. sendMsgSecond: 60,
  39. codeTips: '',
  40. }
  41. },
  42. methods: {
  43. confirmChange() {
  44. uni.showLoading({
  45. title: "加载中",
  46. mask: true,
  47. })
  48. mineApi.changePhone(this.form).then((response) => {
  49. uni.hideLoading();
  50. uni.navigateTo({
  51. url: '/pages/youth/mine/changePhoneNumber/changeResult'
  52. })
  53. }).catch(error => {
  54. uni.showToast({
  55. title: error,
  56. icon: "none"
  57. })
  58. })
  59. },
  60. codeChange(text) {
  61. this.codeTips = text;
  62. },
  63. start() {
  64. if (!this.isSendMsgIng) {
  65. uni.showLoading({
  66. title: "加载中",
  67. mask: true,
  68. })
  69. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  70. uni.hideLoading();
  71. this.carhelp.set("getvcodetime", new Date().getTime());
  72. if (!"") {
  73. //倒计时
  74. uni.showToast({
  75. title: "发送成功"
  76. })
  77. } else {
  78. uni.showToast({
  79. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  80. })
  81. }
  82. }).catch(error => {
  83. uni.showToast({
  84. title: error,
  85. icon: "none"
  86. })
  87. })
  88. }
  89. },
  90. //倒计时
  91. end() {
  92. this.sendMsgSecond = 60;
  93. this.isSendMsgIng = false;
  94. this.isCodeTipsColor = false;
  95. },
  96. // 获取验证码
  97. getCode() {
  98. if (this.$refs.uCode.canGetCode) {} else {
  99. uni.showToast({
  100. title: '倒计时结束后再发送',
  101. icon: "none"
  102. })
  103. return
  104. }
  105. var checkPhoneResult = checkPhone(this.form.telephone);
  106. if (checkPhoneResult !== true) {
  107. uni.showToast({
  108. title: checkPhoneResult,
  109. })
  110. return;
  111. }
  112. this.$refs.uCode.start();
  113. this.isCodeTipsColor = true;
  114. },
  115. },
  116. }
  117. </script>
  118. <style lang="scss" scoped>
  119. page{
  120. background-color: #fff;
  121. }
  122. .login-form{
  123. background-color: #fff;
  124. padding: 24rpx 56rpx;
  125. }
  126. .login-form-item{
  127. margin-bottom: 40rpx;
  128. .title{
  129. margin-bottom: 8px;
  130. }
  131. .input {
  132. padding: 4px 0;
  133. border-bottom: 1px solid #cccccc;
  134. position: relative;
  135. }
  136. .code{
  137. position: absolute;
  138. right: 0;
  139. top:12px;
  140. color: rgba(13, 186, 199, 1);
  141. }
  142. .tips {
  143. color: $u-type-info;
  144. margin-top: 12px;
  145. span{
  146. color:#3fbd70;
  147. }
  148. }
  149. }
  150. .login-btn {
  151. margin: 28px ;
  152. color: rgba(255, 255, 255, 1);
  153. background-color: rgba(13, 186, 199, 1);
  154. }
  155. </style>