phone.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. jpcode: 'toLogin',
  39. }
  40. },
  41. methods: {
  42. codeChange(text) {
  43. this.codeTips = text;
  44. },
  45. start() {
  46. if (!this.isSendMsgIng) {
  47. uni.showLoading({
  48. title: "加载中",
  49. mask: true,
  50. })
  51. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  52. uni.hideLoading();
  53. this.carhelp.set("getvcodetime", new Date().getTime());
  54. if (!"") {
  55. //倒计时
  56. uni.showToast({
  57. title: "发送成功"
  58. })
  59. } else {
  60. uni.showToast({
  61. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  62. })
  63. }
  64. }).catch(error => {
  65. uni.showToast({
  66. title: error,
  67. icon: "none"
  68. })
  69. })
  70. }
  71. },
  72. //倒计时
  73. end() {
  74. this.sendMsgSecond = 60;
  75. this.isSendMsgIng = false;
  76. },
  77. // 获取验证码
  78. getCode() {
  79. if (this.$refs.uCode.canGetCode) {} else {
  80. uni.showToast({
  81. title: '倒计时结束后再发送',
  82. icon: "none"
  83. })
  84. return
  85. }
  86. var checkPhoneResult = checkPhone(this.form.telephone);
  87. if (checkPhoneResult !== true) {
  88. uni.showToast({
  89. title: checkPhoneResult,
  90. })
  91. return;
  92. }
  93. this.$refs.uCode.start();
  94. },
  95. sure() {
  96. var checkPhoneResult = checkPhone(this.form.telephone);
  97. if(!this.form.telephone || checkPhoneResult != true) {
  98. uni.showToast({
  99. title: checkPhoneResult,
  100. icon: "none"
  101. })
  102. return;
  103. }
  104. if(!this.form.verifyCode) {
  105. uni.showToast({
  106. title: "请输入验证码",
  107. icon: "none"
  108. })
  109. return
  110. }
  111. uni.showLoading({
  112. title: "加载中",
  113. mask: true,
  114. })
  115. userApi.changePhone(this.form).then((response) => {
  116. uni.hideLoading();
  117. uni.reLaunch({
  118. url: '/pages/index/index?jpcode=' + this.jpcode
  119. })
  120. }).catch(error => {
  121. uni.showToast({
  122. title: error,
  123. icon: "none"
  124. })
  125. })
  126. }
  127. }
  128. }
  129. </script>
  130. <style>
  131. page{
  132. background-color: #fff;
  133. }
  134. </style>
  135. <style lang="scss" scoped>
  136. .login-form{
  137. background-color: #fff;
  138. padding: 12px 28px;
  139. }
  140. .login-form-item{
  141. .title{
  142. margin-bottom: 8px;
  143. }
  144. .input {
  145. padding: 4px 0;
  146. border-bottom: 1px solid #f7f7f7;
  147. position: relative;
  148. }
  149. .code{
  150. position: absolute;
  151. right: 0;
  152. top:12px;
  153. color:#1677FF;
  154. }
  155. .tips {
  156. color: $u-type-info;
  157. margin-top: 12px;
  158. font-size: 12px;
  159. span{
  160. color:#3fbd70;
  161. }
  162. }
  163. }
  164. .login-btn {
  165. margin: 28px ;
  166. background-color:#00B962!important;
  167. border-color: #00B962!important;
  168. color:#fff!important;
  169. }
  170. </style>