Bez popisu

extend.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. var page = 1
  2. var maxPage = 1
  3. var goodsData = []
  4. var source=""
  5. var loadingFlag = false;
  6. $().ready(function () {
  7. var qs = parseQueryString(window.location.href);
  8. if(qs.source) {source = qs.source}
  9. countLandingPage({click_source:'open',source:source})
  10. recommendlist(1)
  11. $(window).scroll(function () {
  12. if ($(window).scrollTop() >= $(document).height() - $(window).height() - 20) {
  13. //到达底部加载数据
  14. if (loadingFlag) {
  15. page++;
  16. recommendlist(page);//相关推荐
  17. }
  18. }
  19. })
  20. })
  21. //埋点
  22. function countLandingPage (data) {
  23. $.ajax({
  24. type:'post',
  25. url:'/user/log/countLandingPage',
  26. dataType:'json',
  27. data:data,
  28. success:function (res) {
  29. }
  30. })
  31. }
  32. function recommendlist(pageIndex) {
  33. loadingFlag = false;
  34. if (maxPage < page) {
  35. $(".loading").html("没有更多了")
  36. return;
  37. }
  38. $.ajax({
  39. type: "post",
  40. url: "/user/product/getProductListByCatId",
  41. dataType: 'json',
  42. data: {
  43. id: 6,
  44. num: 10,
  45. page: pageIndex
  46. },
  47. success: function (res) {
  48. if (res.errno == "0" && res.rst) {
  49. htmlEvent(res)
  50. }
  51. }
  52. })
  53. }
  54. function htmlEvent(res) {
  55. var data = res.rst.data;
  56. var content=""
  57. maxPage = res.rst.pageinfo.maxPage+1;
  58. //商品
  59. if (data.length > 0) {
  60. if (goodsData.length != 0) {
  61. goodsData = goodsData.concat(data);
  62. goodsData.forEach(function (item, index) {
  63. content+=`
  64. <li>
  65. <div class="top">
  66. <img class="icon" src="${item.icon}">
  67. <div class="word">
  68. <div class="name">${item.name}
  69. <div class="smallTitle" style="display:${item.prod_title.length==0?'none':'inline-block'}">${item.prod_title}</div>
  70. </div>
  71. <div class="descri">${item.description.substring(0, 11) + "..."}</div>
  72. </div>
  73. <a class="apply">申请</a>
  74. </div>
  75. <div class="bottom">
  76. <div class="limit">
  77. <div class="head">额度</div>
  78. ${item.upper_amount}-${item.lower_amount}
  79. </div>
  80. <div class="term">
  81. <div class="head">期限</div>
  82. ${item.term}
  83. </div>
  84. <div class="right">
  85. <div class="head" style="color:#fff;">1111</div>
  86. ${(item.applicants/10000).toFixed(2)}万人已经申请成功
  87. </div>
  88. </div>
  89. </li>`
  90. })
  91. } else {
  92. goodsData = res.rst.data;
  93. goodsData.forEach(function (item, index) {
  94. content+=`
  95. <li onclick='toDetail(${item.id},${JSON.stringify(item.link)})'>
  96. <div class="top">
  97. <img class="icon" src="${item.icon}">
  98. <div class="word">
  99. <div class="name">${item.name}
  100. <div class="smallTitle" style="display:${item.prod_title.length==0?'none':'inline-block'}">${item.prod_title}</div>
  101. </div>
  102. <div class="descri">${item.description.substring(0, 11) + "..."}</div>
  103. </div>
  104. <a class="apply">申请</a>
  105. </div>
  106. <div class="bottom">
  107. <div class="limit">
  108. <div class="head">额度</div>
  109. ${item.upper_amount}-${item.lower_amount}
  110. </div>
  111. <div class="term">
  112. <div class="head">期限</div>
  113. ${item.term}
  114. </div>
  115. <div class="right">
  116. <div class="head" style="color:#fff;">1111</div>
  117. ${(item.applicants/10000).toFixed(2)}万人已经申请成功
  118. </div>
  119. </div>
  120. </li>`
  121. })
  122. }
  123. loadingFlag = true;
  124. $('.list').html(content)
  125. $(".loading").html("努力加载中...")
  126. } else {
  127. $(".loading").html('暂无数据')
  128. }
  129. }
  130. function toDetail(id,link){
  131. var jsons = {
  132. product_Id:id,
  133. link:link,
  134. type:0
  135. };
  136. jsons = JSON.stringify(jsons);
  137. // 安卓
  138. if(navigator.userAgent.indexOf('Android') != -1){
  139. native.JSGetProductId(jsons)
  140. }
  141. }
  142. // 获取地址参数
  143. function parseQueryString(url) {
  144. var urlObj = {};
  145. var reg = /([^?=&]+)=([^?=&]+)/g;
  146. url.replace(reg, ($0, $1, $2) => {
  147. urlObj[$1] = decodeURIComponent($2);
  148. })
  149. return urlObj;
  150. }