index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //import * as WxJsApi from '@/utils/wxJsApi.js'
  2. import * as API from '@/apis/index.js'
  3. import * as API_user from '@/apis/user'
  4. import {
  5. checkPhone
  6. } from '@/utils'
  7. export default {
  8. data() {
  9. return {
  10. phone:"",
  11. isReady:false,
  12. vcode:"",
  13. isSendMsgIng: false,
  14. sendMsgSecond: 60*2,
  15. }
  16. },
  17. components: {
  18. },
  19. onLoad(op){
  20. this.phone=op.phone;
  21. },
  22. methods: {
  23. //验证码登录
  24. codeSubmit() {
  25. uni.showLoading({
  26. title: '加载中'
  27. });
  28. API_user.validateCode(this.subFormCode).then(response => {
  29. if(response.data){
  30. var token = response.data ? response.data.token : '';
  31. this.carhelp.setToken(token);
  32. this.carhelp.setPersonInfo(response.data.jobUser)
  33. }else{
  34. uni.hideLoading();
  35. }
  36. }).catch(error => {
  37. uni.showToast({
  38. icon:"none",title:error
  39. })
  40. uni.hideLoading();
  41. })
  42. },
  43. //发送验证码
  44. sendMsg() {
  45. var time= this.carhelp.get("getvcodetime");
  46. if(time){
  47. var nowtime= new Date().getTime()
  48. var differ=(nowtime-time)/1000
  49. if(differ<2*60){
  50. this.sendMsgSecond=2*60 - parseInt(differ)
  51. this.msgTimeInterval();
  52. }
  53. }
  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.carhelp.set("getvcodetime",new Date().getTime());
  62. this.$refs.common.showLoading(false)
  63. if(response.message){
  64. //倒计时
  65. this.msgTimeInterval();
  66. }else{
  67. this.$refs.common.alert("您的验证码已经发送[5分钟有效],请勿重复点击")
  68. }
  69. }).catch(error => {
  70. this.$refs.common.alert(error)
  71. })
  72. }
  73. }
  74. },
  75. //倒计时
  76. msgTimeInterval() {
  77. this.isSendMsgIng = true;
  78. var time = this.sendMsgSecond;
  79. var _this = this;
  80. this.timer = setInterval(() => {
  81. if (time > 0) {
  82. _this.sendMsgSecond = time--;
  83. } else {
  84. _this.isSendMsgIng = false;
  85. _this.sendMsgSecond = 2*60;
  86. clearInterval(_this.timer)
  87. }
  88. }, 1000)
  89. },
  90. },onReady(){
  91. this.sendMsg()
  92. this.isReady=true;
  93. },onShow(){
  94. if(this.isReady){
  95. }
  96. }, watch : {
  97. vcode:function(val) {
  98. if(val&&val.length==6){
  99. this.codeSubmit()
  100. }
  101. }
  102. }
  103. }