Sin descripción

newlogin.js 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // 根据type_id判断哪些是必填项
  2. var source=parseQueryString(location.href).source?parseQueryString(location.href).source:1001;
  3. var typeId=''
  4. // 根据入口设置typeId
  5. // shebaoLogin为社保贷,typeId---1
  6. if(window.location.href.indexOf("shebaoLogin")!=-1){
  7. typeId=1
  8. // gjjLogin为公积金贷,typeId---2
  9. }else if(window.location.href.indexOf("gjjLogin")!=-1) {
  10. typeId=2
  11. // billLogin为流水贷---3
  12. }else if(window.location.href.indexOf("billLogin")!=-1) {
  13. typeId=3
  14. // carLogin为车贷,typeId---4
  15. }else if(window.location.href.indexOf("carLogin")!=-1) {
  16. typeId=4
  17. // houseLogin为房贷,typeId---5
  18. }else if(window.location.href.indexOf("houseLogin")!=-1) {
  19. typeId=5
  20. // insureLogin为保险贷,typeId---6
  21. }else if(window.location.href.indexOf("insureLogin")!=-1) {
  22. typeId=6
  23. // weiliLogin为微粒贷---7
  24. }else if(window.location.href.indexOf("weiliLogin")!=-1) {
  25. typeId=7
  26. // 优质贷的,不传typeId
  27. }else if(window.location.href.indexOf("newLogin")!=-1) {
  28. typeId="0"
  29. }
  30. // document.body.addEventListener('focusout', function () {
  31. // window.scrollTo(0,0); });
  32. // var typeId=parseQueryString(location.href).typeId?parseQueryString(location.href).typeId:1;//先默认是1
  33. var hasLogin=false;//标记点击登录次数
  34. if(!source||source=="undefined") {
  35. source=1001
  36. }
  37. var code_type=1;//短信验证码为1,语音验证码是2
  38. var countDown = '',count_down = '';
  39. var myreg = /^[0-9]{11}$/;
  40. var ttl="",uid="",token=""
  41. $().ready(function(){
  42. clickRecord("openLink","链接打开")//链接打开
  43. var arr=["code_type="+code_type,"phone="+$("#text").val(),"send_type=1","ttl="+ttl].sort()
  44. var sign=arr.join("&")
  45. })
  46. // 发送验证码
  47. $(".check").on("click",function(){
  48. if (!myreg.test($("#text").val())) {
  49. //手机号码未填写及填写不正确
  50. showMsg('请正确填写手机号')
  51. return;
  52. }else {
  53. $(".notice").show();
  54. // 默认发送短信验证码
  55. sendCode(1)
  56. }
  57. })
  58. function sendCode(type) {
  59. var ttl=new Date().getTime();
  60. var arr=["phone="+$("#text").val(),"code_type="+type,"send_type=1","ttl="+ttl].sort()
  61. var sign=arr.join("&")
  62. $.ajax({
  63. type:"post",
  64. url:"/user/sendCode",
  65. dataType:'json',
  66. headers:{
  67. source:source
  68. },
  69. data:{
  70. // channel_id:source,
  71. phone:$("#text").val(),
  72. code_type:type,//1是短信验证码,2是语音验证码
  73. application_type:1,//2为信贷端
  74. send_type:1,//动态登录
  75. ttl:ttl,
  76. sign:hex_md5(sign+"cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL")
  77. },
  78. success: function (res){
  79. if(res && res.errno == 0){
  80. countDown = res.rst.wait_time;
  81. count_down = countDown;
  82. $(".check").html(count_down+"s");
  83. count_down = count_down-1;
  84. $(".check").attr("disabled","true")
  85. var time = setInterval(function () {
  86. $(".check").html(count_down+"s");
  87. count_down--;
  88. if(count_down < 0){
  89. if(window.location.href.indexOf("weiliLogin")!=-1||window.location.href.indexOf("insureLogin")!=-1||window.location.href.indexOf("newLogin")!=-1) {
  90. $(".check").removeAttr("disabled")
  91. .html('获取验证码')
  92. }else {
  93. $(".check").removeAttr("disabled")
  94. .html('验证码')
  95. }
  96. clearInterval(time);
  97. count_down = countDown;
  98. }
  99. },1000)
  100. }else{
  101. showMsg(res.err)
  102. $(".notice").show();
  103. }
  104. }
  105. });
  106. }
  107. $(".button").on("click",function(){
  108. if (!myreg.test($("#text").val())) {
  109. //手机号码未填写及填写不正确
  110. showMsg('请正确填写手机号')
  111. return;
  112. }else if(!$("#text").val()||!$("#code").val()){
  113. if (!myreg.test($("#text").val())) {
  114. //手机号码未填写及填写不正确
  115. showMsg('请正确填写手机号')
  116. return;
  117. }else {
  118. showMsg("验证码不能为空")
  119. return;
  120. }
  121. }else {
  122. if(!hasLogin) {
  123. $.ajax({
  124. url:"/user/login",
  125. type:"post",
  126. dataType:"json",
  127. data:{
  128. phone:$("#text").val(),
  129. code:$("#code").val(),
  130. channel_id:source
  131. },
  132. success:function(res) {
  133. if(res&&res.errno==0) {
  134. clickRecord("applyClick","立即申请点击") // 立即申请
  135. // 判断进行到哪步
  136. var step=res.rst.data.user_info_step;
  137. token=res.rst.data.token;
  138. uid=res.rst.data.uid;
  139. hasLogin=true
  140. if(typeId) {
  141. // 未填写信息
  142. if(step<=3) {
  143. window.location.href="index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&code="+$("#code").val()+"&typeId="+typeId
  144. // 正在审核
  145. }else if(step==4) {
  146. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=1"+"&typeId="+typeId
  147. // 审核成功
  148. }else if(step==5) {
  149. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=2"+"&typeId="+typeId
  150. // 审核失败
  151. }else if(step==6) {
  152. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=3"+"&typeId="+typeId
  153. }
  154. }else {
  155. // 未填写信息
  156. if(step<=3) {
  157. window.location.href="index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&code="+$("#code").val()
  158. // 正在审核
  159. }else if(step==4) {
  160. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=1"
  161. // 审核成功
  162. }else if(step==5) {
  163. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=2"
  164. // 审核失败
  165. }else if(step==6) {
  166. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=3"
  167. }
  168. }
  169. }else {
  170. showMsg(res.rst.msg)
  171. }
  172. },
  173. error:function(err) {
  174. showMsg("网络错误,请稍后再试")
  175. }
  176. })
  177. }
  178. }
  179. })
  180. $(".button1").on("click",function(){
  181. // 审核失败,hasError=1
  182. if(typeId) {
  183. window.location.href=getLocation()+"index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&hasError="+1+"&typeId="+typeId
  184. }else {
  185. window.location.href=getLocation()+"index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&hasError="+1
  186. }
  187. })
  188. // 展示错误提示信息
  189. function showMsg(msg) {
  190. $(".alert-info").show();
  191. $(".alert-info p").text(msg);
  192. setTimeout(function() {
  193. $(".alert-info").hide();
  194. }, 1000);
  195. }
  196. //获取地址栏参数
  197. function parseQueryString(url) {
  198. var urlObj = {};
  199. var reg = /([^?=&]+)=([^?=&]+)/g;
  200. url.replace(reg, function($0, $1, $2) {
  201. urlObj[$1] = decodeURIComponent($2);
  202. })
  203. return urlObj;
  204. }
  205. // 埋点
  206. function clickRecord(eventId,eventName){
  207. $.ajax({
  208. url:"/user/clickRecord",
  209. type:"post",
  210. dataType:"json",
  211. data:{
  212. event_id:eventId,
  213. event_name:eventName,
  214. channel_id:source?source:1001
  215. },
  216. success:function(res) {
  217. }
  218. })
  219. }
  220. // 获取上级地址
  221. function getLocation() {
  222. var upper=window.location.href.split("/")[window.location.href.split("/").length-1]
  223. return window.location.href.replace(upper,"");
  224. }