phone.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 type="number" v-model="form.phone" placeholder="请输入手机号"/>
  8. </view>
  9. </view>
  10. <view class="login-form-item">
  11. <view class="input">
  12. <u-input v-model="form.code" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  13. <view class="code" @click="getCode" >{{codeTips}}</view>
  14. </view>
  15. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start">
  16. </u-verification-code>
  17. </view>
  18. </view>
  19. <u-button class="login-btn" @click="finish" type="success" shape="circle" >确认修改</u-button>
  20. </view>
  21. </template>
  22. <script>
  23. import * as API from '@/apis/pagejs/user.js'
  24. import {
  25. checkPhone
  26. } from '@/apis/utils'
  27. export default {
  28. data() {
  29. return {
  30. form: {
  31. name: '',
  32. phone: '',
  33. code: '',
  34. },
  35. codeTips: '',
  36. isSendMsgIng: false,
  37. sendMsgSecond: 60 * 2,
  38. }
  39. },
  40. methods: {
  41. codeChange(text) {
  42. this.codeTips = text;
  43. },
  44. //倒计时
  45. end() {
  46. this.sendMsgSecond = 2 * 60;
  47. this.isSendMsgIng = false;
  48. },
  49. finish() {
  50. if (!this.carhelp.getOpenId()) {
  51. // uni.showToast({
  52. // title: "请使用“微信”访问本系统登录"
  53. // })
  54. // return
  55. }
  56. if (!this.form.phone) {
  57. uni.showToast({
  58. title: "请输入手机号"
  59. })
  60. return
  61. }
  62. if (!this.form.code) {
  63. uni.showToast({
  64. title: "请输入验证码"
  65. })
  66. return
  67. }
  68. uni.showLoading({
  69. title: "加载中",
  70. mask: true,
  71. })
  72. API.changePhone({
  73. verifyCode: this.form.code,
  74. telephone: this.form.phone,
  75. }).then((response) => {
  76. this.query()
  77. }).catch(error => {
  78. uni.showToast({
  79. title: error,
  80. icon: "none"
  81. })
  82. })
  83. },
  84. start() {
  85. if (!this.isSendMsgIng) {
  86. uni.showLoading({
  87. title: "加载中",
  88. mask: true,
  89. })
  90. API.getVerifyCode(this.form.phone).then((response) => {
  91. uni.hideLoading();
  92. this.carhelp.set("getvcodetime", new Date().getTime());
  93. if (!"") {
  94. //倒计时
  95. uni.showToast({
  96. title: "发送成功"
  97. })
  98. } else {
  99. uni.showToast({
  100. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  101. })
  102. }
  103. }).catch(error => {
  104. uni.showToast({
  105. title: error,
  106. icon: "none"
  107. })
  108. })
  109. }
  110. },
  111. // 获取验证码
  112. getCode() {
  113. if (this.$refs.uCode.canGetCode) {
  114. } else {
  115. uni.showToast({
  116. title: '倒计时结束后再发送',
  117. icon: "none"
  118. })
  119. return
  120. }
  121. var checkPhoneResult = checkPhone(this.form.phone);
  122. if (checkPhoneResult !== true) {
  123. uni.showToast({
  124. title: checkPhoneResult,
  125. })
  126. return;
  127. }
  128. this.$refs.uCode.start();
  129. },loginset(response){
  130. var token = response ? response.data.token : '';
  131. this.carhelp.setToken(token);
  132. this.carhelp.setPersonInfo(response.data.regUser);
  133. this.carhelp.setPersonInfoPlus(response.data)
  134. //this.gotoUrl("pages/user/index")
  135. uni.redirectTo({
  136. url: '/pages/mine/mine'
  137. })
  138. },
  139. query(){
  140. uni.showLoading({
  141. title: "加载中",
  142. mask: true,
  143. })
  144. API.findByOpenId({
  145. noerror:true,
  146. openId: this.carhelp.getOpenId(),
  147. }).then((response) => {
  148. this.loginset(response)
  149. }).catch(error => {
  150. uni.hideLoading();
  151. // if (!this.carhelp.getOpenId()) {
  152. // uni.showToast({
  153. // title: "请使用“微信”访问本系统登录"
  154. // })
  155. // return
  156. // }
  157. var time = this.carhelp.get("getvcodetime");
  158. if (time) {
  159. //this.$refs.uCode.start();
  160. var nowtime = new Date().getTime()
  161. var differ = (nowtime - time) / 1000
  162. if (differ < 2 * 60) {
  163. this.sendMsgSecond = 2 * 60 - parseInt(differ)
  164. this.isSendMsgIng = true;
  165. this.$refs.uCode.start();
  166. }
  167. }
  168. })
  169. }
  170. }
  171. }
  172. </script>
  173. <style>
  174. page{
  175. background-color: #fff;
  176. }
  177. </style>
  178. <style lang="scss" scoped>
  179. .login-form{
  180. background-color: #fff;
  181. padding: 12px 28px;
  182. }
  183. .login-form-item{
  184. .title{
  185. margin-bottom: 8px;
  186. }
  187. .input {
  188. padding: 4px 0;
  189. border-bottom: 1px solid #cccccc;
  190. position: relative;
  191. margin-bottom: 16rpx;
  192. }
  193. .code{
  194. position: absolute;
  195. right: 0;
  196. top:12px;
  197. color:#1F4A99;
  198. }
  199. }
  200. .login-btn {
  201. margin: 56rpx ;
  202. background-color: rgba(31, 74, 153, 1);
  203. color: rgba(255, 255, 255, 1);
  204. border-radius: 8px;
  205. }
  206. </style>