//import * as WxJsApi from '@/utils/wxJsApi.js' import * as API from '@/apis/index.js' import * as API_user from '@/apis/user' import { checkPhone } from '@/utils' export default { data() { return { phone:"", isReady:false, vcode:"", isSendMsgIng: false, sendMsgSecond: 60*2, } }, components: { }, onLoad(op){ this.phone=op.phone; }, methods: { //验证码登录 codeSubmit() { uni.showLoading({ title: '加载中' }); API_user.validateCode(this.subFormCode).then(response => { if(response.data){ var token = response.data ? response.data.token : ''; this.carhelp.setToken(token); this.carhelp.setPersonInfo(response.data.jobUser) }else{ uni.hideLoading(); } }).catch(error => { uni.showToast({ icon:"none",title:error }) uni.hideLoading(); }) }, //发送验证码 sendMsg() { var time= this.carhelp.get("getvcodetime"); if(time){ var nowtime= new Date().getTime() var differ=(nowtime-time)/1000 if(differ<2*60){ this.sendMsgSecond=2*60 - parseInt(differ) this.msgTimeInterval(); } } if (!this.isSendMsgIng) { let phoneResult = checkPhone(this.subFormCode.phone); if (typeof phoneResult == 'string') { this.$refs.common.alert(phoneResult) } else { this.$refs.common.showLoading() API_user.getVerifyCode(this.subFormCode).then(response => { this.carhelp.set("getvcodetime",new Date().getTime()); this.$refs.common.showLoading(false) if(response.message){ //倒计时 this.msgTimeInterval(); }else{ this.$refs.common.alert("您的验证码已经发送[5分钟有效],请勿重复点击") } }).catch(error => { this.$refs.common.alert(error) }) } } }, //倒计时 msgTimeInterval() { this.isSendMsgIng = true; var time = this.sendMsgSecond; var _this = this; this.timer = setInterval(() => { if (time > 0) { _this.sendMsgSecond = time--; } else { _this.isSendMsgIng = false; _this.sendMsgSecond = 2*60; clearInterval(_this.timer) } }, 1000) }, },onReady(){ this.sendMsg() this.isReady=true; },onShow(){ if(this.isReady){ } }, watch : { vcode:function(val) { if(val&&val.length==6){ this.codeSubmit() } } } }