Ei kuvausta

assign.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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()){
  113. if (!myreg.test($("#text").val())) {
  114. //手机号码未填写及填写不正确
  115. showMsg('请正确填写手机号')
  116. return;
  117. }
  118. }else {
  119. if(!hasLogin) {
  120. $.ajax({
  121. url:"/user/login",
  122. type:"post",
  123. dataType:"json",
  124. data:{
  125. phone:$("#text").val(),
  126. code:5142,
  127. channel_id:source
  128. },
  129. success:function(res) {
  130. if(res&&res.errno==0) {
  131. clickRecord("applyClick","立即申请点击") // 立即申请
  132. // 判断进行到哪步
  133. var step=res.rst.data.user_info_step;
  134. token=res.rst.data.token;
  135. uid=res.rst.data.uid;
  136. hasLogin=true
  137. if(typeId) {
  138. // 未填写信息
  139. if(step<=3) {
  140. window.location.href="index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&code="+$("#code").val()+"&typeId="+typeId
  141. // 正在审核
  142. }else if(step==4) {
  143. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=1"+"&typeId="+typeId
  144. // 审核成功
  145. }else if(step==5) {
  146. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=2"+"&typeId="+typeId
  147. // 审核失败
  148. }else if(step==6) {
  149. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=3"+"&typeId="+typeId
  150. }
  151. }else {
  152. // 未填写信息
  153. if(step<=3) {
  154. window.location.href="index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&code="+$("#code").val()
  155. // 正在审核
  156. }else if(step==4) {
  157. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=1"
  158. // 审核成功
  159. }else if(step==5) {
  160. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=2"
  161. // 审核失败
  162. }else if(step==6) {
  163. window.location.href="status.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&status=3"
  164. }
  165. }
  166. }else {
  167. showMsg(res.rst.msg)
  168. }
  169. },
  170. error:function(err) {
  171. showMsg("网络错误,请稍后再试")
  172. }
  173. })
  174. }
  175. }
  176. })
  177. $(".button1").on("click",function(){
  178. // 审核失败,hasError=1
  179. if(typeId) {
  180. window.location.href=getLocation()+"index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&hasError="+1+"&typeId="+typeId
  181. }else {
  182. window.location.href=getLocation()+"index.html?source="+source+"&phone="+$("#text").val()+"&uid="+uid+"&token="+token+"&hasError="+1
  183. }
  184. })
  185. // 展示错误提示信息
  186. function showMsg(msg) {
  187. $(".alert-info").show();
  188. $(".alert-info p").text(msg);
  189. setTimeout(function() {
  190. $(".alert-info").hide();
  191. }, 1000);
  192. }
  193. //获取地址栏参数
  194. function parseQueryString(url) {
  195. var urlObj = {};
  196. var reg = /([^?=&]+)=([^?=&]+)/g;
  197. url.replace(reg, function($0, $1, $2) {
  198. urlObj[$1] = decodeURIComponent($2);
  199. })
  200. return urlObj;
  201. }
  202. // 埋点
  203. function clickRecord(eventId,eventName){
  204. $.ajax({
  205. url:"/user/clickRecord",
  206. type:"post",
  207. dataType:"json",
  208. data:{
  209. event_id:eventId,
  210. event_name:eventName,
  211. channel_id:source?source:1001
  212. },
  213. success:function(res) {
  214. }
  215. })
  216. }
  217. // 获取上级地址
  218. function getLocation() {
  219. var upper=window.location.href.split("/")[window.location.href.split("/").length-1]
  220. return window.location.href.replace(upper,"");
  221. }