123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- // 根据type_id判断哪些是必填项
- var source=parseQueryString(location.href).source?parseQueryString(location.href).source:1001;
- var typeId=''
- // 根据入口设置typeId
- // shebaoLogin为社保贷,typeId---1
- if(window.location.href.indexOf("shebaoLogin")!=-1){
- typeId=1
- // gjjLogin为公积金贷,typeId---2
- }else if(window.location.href.indexOf("gjjLogin")!=-1) {
- typeId=2
- // billLogin为流水贷---3
- }else if(window.location.href.indexOf("billLogin")!=-1) {
- typeId=3
- // carLogin为车贷,typeId---4
- }else if(window.location.href.indexOf("carLogin")!=-1) {
- typeId=4
- // houseLogin为房贷,typeId---5
- }else if(window.location.href.indexOf("houseLogin")!=-1) {
- typeId=5
- // insureLogin为保险贷,typeId---6
- }else if(window.location.href.indexOf("insureLogin")!=-1) {
- typeId=6
- // weiliLogin为微粒贷---7
- }else if(window.location.href.indexOf("weiliLogin")!=-1) {
- typeId=7
- // 优质贷的,不传typeId
- }else if(window.location.href.indexOf("newLogin")!=-1) {
- typeId="0"
- }
- // document.body.addEventListener('focusout', function () {
- // window.scrollTo(0,0); });
- // var typeId=parseQueryString(location.href).typeId?parseQueryString(location.href).typeId:1;//先默认是1
- var hasLogin=false;//标记点击登录次数
- if(!source||source=="undefined") {
- source=1001
- }
- var code_type=1;//短信验证码为1,语音验证码是2
- var countDown = '',count_down = '';
- var myreg = /^[0-9]{11}$/;
- var ttl="",uid="",token=""
- $().ready(function(){
- clickRecord("openLink","链接打开")//链接打开
- var arr=["code_type="+code_type,"phone="+$("#text").val(),"send_type=1","ttl="+ttl].sort()
- var sign=arr.join("&")
- })
- // 发送验证码
- $(".check").on("click",function(){
- if (!myreg.test($("#text").val())) {
- //手机号码未填写及填写不正确
- showMsg('请正确填写手机号')
- return;
- }else {
- $(".notice").show();
- // 默认发送短信验证码
- sendCode(1)
- }
- })
- function sendCode(type) {
- var ttl=new Date().getTime();
- var arr=["phone="+$("#text").val(),"code_type="+type,"send_type=1","ttl="+ttl].sort()
- var sign=arr.join("&")
- $.ajax({
- type:"post",
- url:"/user/sendCode",
- dataType:'json',
- headers:{
- source:source
- },
- data:{
- // channel_id:source,
- phone:$("#text").val(),
- code_type:type,//1是短信验证码,2是语音验证码
- application_type:1,//2为信贷端
- send_type:1,//动态登录
- ttl:ttl,
- sign:hex_md5(sign+"cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL")
- },
- success: function (res){
- if(res && res.errno == 0){
- countDown = res.rst.wait_time;
- count_down = countDown;
- $(".check").html(count_down+"s");
- count_down = count_down-1;
- $(".check").attr("disabled","true")
- var time = setInterval(function () {
- $(".check").html(count_down+"s");
- count_down--;
- if(count_down < 0){
- if(window.location.href.indexOf("weiliLogin")!=-1||window.location.href.indexOf("insureLogin")!=-1||window.location.href.indexOf("newLogin")!=-1) {
- $(".check").removeAttr("disabled")
- .html('获取验证码')
- }else {
- $(".check").removeAttr("disabled")
- .html('验证码')
- }
- clearInterval(time);
- count_down = countDown;
- }
- },1000)
- }else{
- showMsg(res.err)
- $(".notice").show();
- }
- }
- });
- }
- $(".button").on("click",function(){
- if (!myreg.test($("#text").val())) {
- //手机号码未填写及填写不正确
- showMsg('请正确填写手机号')
- return;
- }else if(!$("#text").val()||!$("#code").val()){
- if (!myreg.test($("#text").val())) {
- //手机号码未填写及填写不正确
- showMsg('请正确填写手机号')
- return;
- }else {
- showMsg("验证码不能为空")
- return;
- }
- }else {
- if(!hasLogin) {
- $.ajax({
- url:"/user/login",
- type:"post",
- dataType:"json",
- data:{
- phone:$("#text").val(),
- code:$("#code").val(),
- channel_id:source
- },
- success:function(res) {
- if(res&&res.errno==0) {
- clickRecord("applyClick","立即申请点击") // 立即申请
- // 判断进行到哪步
- var step=res.rst.data.user_info_step;
- token=res.rst.data.token;
- uid=res.rst.data.uid;
- hasLogin=true
- if(typeId) {
- // 未填写信息
- if(step<=3) {
- window.location.href="index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&code="+$("#code").val()+"&typeId="+typeId
- // 正在审核
- }else if(step==4) {
- window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=1"+"&typeId="+typeId
- // 审核成功
- }else if(step==5) {
- window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=2"+"&typeId="+typeId
- // 审核失败
- }else if(step==6) {
- window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=3"+"&typeId="+typeId
- }
- }else {
- // 未填写信息
- if(step<=3) {
- window.location.href="index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&code="+$("#code").val()
- // 正在审核
- }else if(step==4) {
- window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=1"
- // 审核成功
- }else if(step==5) {
- window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=2"
- // 审核失败
- }else if(step==6) {
- window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=3"
- }
- }
- }else {
- showMsg(res.rst.msg)
- }
- },
- error:function(err) {
- showMsg("网络错误,请稍后再试")
- }
- })
- }
- }
- })
- $(".button1").on("click",function(){
- // 审核失败,hasError=1
- if(typeId) {
- window.location.href=getLocation()+"index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&hasError="+1+"&typeId="+typeId
- }else {
- window.location.href=getLocation()+"index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&hasError="+1
- }
- })
- // 展示错误提示信息
- function showMsg(msg) {
- $(".alert-info").show();
- $(".alert-info p").text(msg);
- setTimeout(function() {
- $(".alert-info").hide();
- }, 1000);
- }
- //获取地址栏参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, function($0, $1, $2) {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
- // 埋点
- function clickRecord(eventId,eventName){
- $.ajax({
- url:"/user/clickRecord",
- type:"post",
- dataType:"json",
- data:{
- event_id:eventId,
- event_name:eventName,
- channel_id:source?source:1001
- },
- success:function(res) {
- }
- })
- }
- // 获取上级地址
- function getLocation() {
- var upper=window.location.href.split("/")[window.location.href.split("/").length-1]
- return window.location.href.replace(upper,"");
- }
|