changePhone.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <view>
  3. <u-navbar title="修改手机号" title-color="#101010"></u-navbar>
  4. <view class="main">
  5. <view class="original-password">
  6. <text>新手机号</text><u-input v-model="form.telephone" style="padding: 0 0 0 20px" maxlength="11" type="number" placeholder="请填写新手机号" />
  7. </view>
  8. <view class="new-password">
  9. <text>验证码</text><u-input v-model="form.verifyCode" style="padding: 0 0 0 20px" maxlength="6" type="number" placeholder="6位验证码" />
  10. <text class="verification-code" :style="isCodeTipsColor ? 'color: #999999;' : ''" @click="getCode" >{{codeTips}}</text>
  11. </view>
  12. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start"
  13. change-text="(Xs)">
  14. </u-verification-code>
  15. </view>
  16. <!-- 确认修改 -->
  17. <button class="confirm" @click="changePhone">确认修改</button>
  18. </view>
  19. </template>
  20. <script>
  21. import * as API from '@/apis/pagejs/user.js'
  22. import {
  23. checkPhone
  24. } from '@/apis/utils'
  25. export default {
  26. data() {
  27. return {
  28. form: {
  29. telephone: '',
  30. verifyCode: '',
  31. },
  32. isSendMsgIng: false,
  33. isCodeTipsColor: false,
  34. sendMsgSecond: 60,
  35. codeTips: '',
  36. }
  37. },
  38. onReady() {
  39. var time = this.carhelp.get("getvcodetime");
  40. if (time) {
  41. //this.$refs.uCode.start();
  42. var nowtime = new Date().getTime()
  43. var differ = (nowtime - time) / 1000
  44. if (differ < 2 * 60) {
  45. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  46. this.isSendMsgIng = true;
  47. this.$refs.uCode.start();
  48. this.isCodeTipsColor = true;
  49. }
  50. }
  51. },
  52. methods: {
  53. changePhone() {
  54. var checkPhoneResult = checkPhone(this.form.telephone);
  55. if (!this.form.telephone || checkPhoneResult != true) {
  56. uni.showToast({
  57. title: checkPhoneResult,
  58. icon: "none"
  59. })
  60. return;
  61. }
  62. if (!this.form.verifyCode) {
  63. uni.showToast({
  64. title: "请输入验证码",
  65. icon: "none"
  66. })
  67. return
  68. }
  69. uni.showLoading({
  70. title: "加载中",
  71. mask: true,
  72. })
  73. API.changePhone(this.form).then((response) => {
  74. uni.hideLoading();
  75. this.carhelp.logoff()
  76. uni.redirectTo({
  77. url: '/pages/login/login'
  78. })
  79. }).catch(error => {
  80. uni.showToast({
  81. title: error,
  82. icon: "none"
  83. })
  84. })
  85. },
  86. codeChange(text) {
  87. this.codeTips = text;
  88. },
  89. //倒计时
  90. end() {
  91. this.sendMsgSecond = 60;
  92. this.isSendMsgIng = false;
  93. this.isCodeTipsColor = false;
  94. },
  95. // 获取验证码
  96. getCode() {
  97. if (this.$refs.uCode.canGetCode) {} else {
  98. uni.showToast({
  99. title: '倒计时结束后再发送',
  100. icon: "none"
  101. })
  102. return
  103. }
  104. var checkPhoneResult = checkPhone(this.form.telephone);
  105. if (checkPhoneResult !== true) {
  106. uni.showToast({
  107. icon: "none",
  108. title: checkPhoneResult,
  109. })
  110. return;
  111. }
  112. this.$refs.uCode.start();
  113. this.isCodeTipsColor = true;
  114. },
  115. start() {
  116. if (!this.isSendMsgIng) {
  117. uni.showLoading({
  118. title: "加载中",
  119. mask: true,
  120. })
  121. API.getVerifyCode(this.form).then((response) => {
  122. uni.hideLoading();
  123. this.carhelp.set("getvcodetime", new Date().getTime());
  124. if (!"") {
  125. //倒计时
  126. uni.showToast({
  127. icon: "none",
  128. title: "发送成功"
  129. })
  130. } else {
  131. uni.showToast({
  132. icon: "none",
  133. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  134. })
  135. }
  136. }).catch(error => {
  137. uni.showToast({
  138. title: error,
  139. icon: "none"
  140. })
  141. })
  142. }
  143. },
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .main{
  149. background-color: #fff;
  150. margin-top: 24rpx;
  151. .original-password,.new-password{
  152. line-height: 96rpx;
  153. padding:0 32rpx;
  154. display: flex;
  155. align-items: center;
  156. border-bottom: 1px solid rgba(221,221,221,1);
  157. ::v-deep.u-input__input{
  158. height: 96rpx;
  159. }
  160. }
  161. text{
  162. display: inline-block;
  163. width: 128rpx;
  164. color: rgba(51,51,51,1);
  165. font-size: 32rpx;
  166. }
  167. .verification-code{
  168. width: 160rpx;
  169. color: rgba(22,119,255,1);
  170. font-size: 32rpx;
  171. }
  172. }
  173. // 确认修改
  174. .confirm{
  175. border-radius: 8px;
  176. background-color: rgba(22,119,255,1);
  177. color: rgba(255,255,255,1);
  178. font-size: 32rpx;
  179. line-height: 88rpx;
  180. margin: 24rpx 32rpx;
  181. }
  182. </style>