No Description

category.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. var id = ''; //id
  2. var channel_id = ''; //渠道号
  3. var page =1; //页数
  4. var maxPage =1; //最大页数
  5. var categoryList = [];//列表数组
  6. var title = '' ; //标题
  7. var sessionid = '';
  8. var loadingFlag = false;
  9. var qs = parseQueryString(window.location.href);
  10. $().ready(function() {
  11. if(qs.id) {
  12. id = qs.id;
  13. }
  14. if(qs.title) {
  15. title = qs.title;
  16. }
  17. document.title = title;
  18. if(qs.channel_id) {
  19. channel_id = qs.channel_id;
  20. }
  21. if(qs.sessionid) {
  22. sessionid = qs.sessionid;
  23. document.cookie="PHPSESSID=" + qs.sessionid + ';path=/' ;
  24. }
  25. getBannerDescription(id); //获取banner信息
  26. getListData(id,page,channel_id);//获取list数据
  27. $(window).scroll(function(){
  28. if($(window).scrollTop()>= $(document).height()-$(window).height() - 20){
  29. //到达底部加载数据
  30. if(loadingFlag){
  31. page ++ ;
  32. getListData(id,page,channel_id);
  33. }
  34. }
  35. });
  36. })
  37. //获取地址栏参数
  38. function parseQueryString(url) {
  39. var urlObj = {};
  40. var reg = /([^?=&]+)=([^?=&]+)/g;
  41. url.replace(reg, ($0, $1, $2) => {
  42. urlObj[$1] = decodeURIComponent($2);
  43. })
  44. return urlObj;
  45. }
  46. //获取banner信息
  47. function getBannerDescription(id){
  48. $.ajax({
  49. type: "post",
  50. url: "/user/product/getH5Detail",
  51. data:{
  52. id : id
  53. },
  54. success:function(res){
  55. if(res.errno == "0" && res.rst){
  56. var data = res.rst;
  57. // $('body').css({ 'background':data.background_color })
  58. document.body.style.background='-o-linear-gradient(top, '+ data.background_color_up + ', '+ data.background_color_down + '))'
  59. document.body.style.background='-webkit-linear-gradient(top, '+ data.background_color_up + ', '+ data.background_color_down + '))'
  60. document.body.style.background='-ms-gradient(linear, left top, left bottom, from('+ data.background_color_up + '), to('+ data.background_color_down + '))'
  61. document.body.style.background='-moz-gradient(linear, left top, left bottom, from('+ data.background_color_up + '), to('+ data.background_color_down + '))'
  62. document.body.style.background='-webkit-gradient(linear, left top, left bottom, from('+ data.background_color_up + '), to('+ data.background_color_down + '))'
  63. // $('.list_top .apply_now').css('background','-webkit-linear-gradient(top, '+ data.background_color_up + ', '+ data.background_color_down + '))')
  64. $('.loading').css({ 'background':data.background_color_down })
  65. $('.category_banner').css({ 'background':' url('+ data.banner +') no-repeat', 'background-size':'100% 100%' })
  66. $('.category_banner .de_1').html(data.description);
  67. $('.category_banner .de_2').html(data.sub_description);
  68. }
  69. },
  70. error:function(err){
  71. console.log(err)
  72. }
  73. })
  74. }
  75. //获取list数据
  76. function getListData(id,page,channel_id){
  77. loadingFlag = false;
  78. if(maxPage < page){
  79. $(".loading").html("没有更多了")
  80. return;
  81. }
  82. $.ajax({
  83. type: "post",
  84. url: "/user/product/getH5DetailProductList",
  85. data:{
  86. id : id,
  87. page : page,
  88. channel_id:channel_id
  89. },
  90. success:function(res){
  91. if(res.errno == "0" && res.rst){
  92. maxPage = res.rst.pageinfo.maxPage;
  93. var data = res.rst.data;
  94. var html = '';
  95. categoryList = categoryList.concat(data)
  96. categoryList.forEach(function(item,index){
  97. html+='<li class="category_list" data_id = ' + item.id + ' data_title = ' + item.name + '><div class="list_top"><img src="'+ item.icon +'" class="list_icon" /> <div class="list_info"><h3 class="name">'+ item.name +'</h3><p class="description">'+ item.description +'</p></div><div class="applyNow"><div class="apply_now" data_id = ' + item.id + ' url=' + item.link + ' >立即申请</div></div></div><div class="list_bot"> <div class="list_bot_item"><p class="name">额度</p><p class="con" id="">'+ item.upper_amount +'-'+ item.lower_amount +'元</p></div><div class="list_bot_item"><p class="name">利率</p><p class="con" id="">'+ item.day_rate +'%</p></div><div class="list_bot_item"><p class="name">成功借款</p> <p class="con" id="">'+ item.applicants +'人</p> </div> </div> </li>'
  98. })
  99. loadingFlag = true;
  100. $('.category_con').html(html)
  101. toApply();//立即申请
  102. $(".loading").html("努力加载中...")
  103. }else{
  104. $(".loading").html("暂无数据")
  105. }
  106. },
  107. error:function(err){
  108. console.log(err)
  109. }
  110. })
  111. }
  112. //立即申请
  113. function toApply(){
  114. //category_list点击跳转原生
  115. $(".category_list").click(function () {
  116. var id = $(this).attr('data_id');
  117. var title = $(this).attr('data_title');
  118. toCategory(id,title);
  119. })
  120. $(".applyNow").click(function () {
  121. return false;
  122. })
  123. //立即申请点击跳转商户推广页
  124. $(".category_con li .apply_now").click(function () {
  125. var id = $(this).attr('data_id');
  126. var url = $(this).attr('url');
  127. window.location.href = url;
  128. shenqing(id);
  129. })
  130. }
  131. //立即申请点击跳转商户推广页
  132. function shenqing (id) {
  133. var jsons = {
  134. event:'nowApply',
  135. product:id
  136. };
  137. jsons = JSON.stringify(jsons);
  138. // console.log(jsons)
  139. if(navigator.userAgent.indexOf('Android') != -1){
  140. messageHandlers.censucEventCount(jsons)
  141. }else{
  142. window.webkit.messageHandlers.censucEventCount.postMessage(jsons)
  143. }
  144. }
  145. //category_list点击跳转原生
  146. function toCategory(id,title){
  147. var jsons = {
  148. productId:id,
  149. productTitle:title,
  150. prooductSkipEntersource:'H5HomeProductListSkip'
  151. };
  152. jsons = JSON.stringify(jsons);
  153. if(navigator.userAgent.indexOf('Android') != -1){
  154. messageHandlers.skipNativeDetail(jsons)
  155. }else{
  156. window.webkit.messageHandlers.skipNativeDetail.postMessage(jsons)
  157. }
  158. }