change.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import * as API_user from '@/apis/user'
  2. import {
  3. checkPhone,
  4. } from '@/utils'
  5. export default {
  6. data() {
  7. return {
  8. subFormCode: {
  9. phone: '',
  10. openId: '',
  11. code: ''
  12. },
  13. isSendMsgIng: false,
  14. sendMsgSecond: 60,
  15. }
  16. },
  17. methods: {
  18. codeCheckForm() {
  19. let phoneResult = checkPhone(this.subFormCode.phone);
  20. if (typeof phoneResult == 'string') {
  21. this.$refs.common.alert(phoneResult)
  22. return false;
  23. } else if (!this.subFormCode.code) {
  24. this.$refs.common.alert('请输入验证码')
  25. return false;
  26. } else {
  27. return true;
  28. }
  29. },
  30. login() {
  31. this.codeSubmit();
  32. },
  33. //验证码登录
  34. codeSubmit() {
  35. if (this.codeCheckForm()) {
  36. this.$refs.common.showLoading()
  37. API_user.userUpdatePhone(this.subFormCode).then(response => {
  38. if(response.data){
  39. this.user=this.carhelp.getPersonInfo();
  40. this.user.phone=this.subFormCode.phone;
  41. this.carhelp.setPersonInfo(this.user)
  42. this.$refs.common.setFnc(this.loginSuccess)
  43. this.$refs.common.alert2("变更手机号成功!")
  44. }else{
  45. this.$refs.common.showLoading(false,response.message);
  46. }
  47. }).catch(error => {
  48. this.$refs.common.showLoading(false,error);
  49. })
  50. }
  51. },
  52. //发送验证码
  53. sendMsg() {
  54. if (!this.isSendMsgIng) {
  55. let phoneResult = checkPhone(this.subFormCode.phone);
  56. if (typeof phoneResult == 'string') {
  57. this.$refs.common.alert(phoneResult)
  58. } else {
  59. this.$refs.common.showLoading()
  60. API_user.getVerifyCode(this.subFormCode).then(response => {
  61. this.$refs.common.showLoading(false)
  62. if(response.message){
  63. //倒计时
  64. this.msgTimeInterval();
  65. }else{
  66. this.$refs.common.alert("您的验证码已经发送[5分钟有效],请勿重复点击")
  67. }
  68. }).catch(error => {
  69. this.$refs.common.alert(error)
  70. })
  71. }
  72. }
  73. },
  74. //倒计时
  75. msgTimeInterval() {
  76. this.isSendMsgIng = true;
  77. var time = this.sendMsgSecond;
  78. var _this = this;
  79. this.timer = setInterval(() => {
  80. if (time > 0) {
  81. _this.sendMsgSecond = time--;
  82. } else {
  83. _this.isSendMsgIng = false;
  84. _this.sendMsgSecond = 60;
  85. clearInterval(_this.timer)
  86. }
  87. }, 1000)
  88. }, //登录成功
  89. loginSuccess() {
  90. uni.switchTab({
  91. url: '/pages/my/index'
  92. });
  93. },
  94. showphone(phone){
  95. if(!phone){
  96. return "";
  97. }
  98. if(phone.length!=11){
  99. return "";
  100. }
  101. return phone.substring(0,3)+'****'+phone.substring(8);
  102. },
  103. },
  104. onLoad() {
  105. }
  106. }