Nenhuma Descrição

login.js 6.1KB

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