phone.vue 3.7 KB

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