123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- var page = 1
- var maxPage = 1
- var goodsData = []
- var source=""
- var loadingFlag = false;
- $().ready(function () {
- var qs = parseQueryString(window.location.href);
- if(qs.source) {source = qs.source}
- countLandingPage({click_source:'open',source:source})
- recommendlist(1)
- $(window).scroll(function () {
- if ($(window).scrollTop() >= $(document).height() - $(window).height() - 20) {
- //到达底部加载数据
- if (loadingFlag) {
- page++;
- recommendlist(page);//相关推荐
- }
- }
- })
- })
- //埋点
- function countLandingPage (data) {
- $.ajax({
- type:'post',
- url:'/user/log/countLandingPage',
- dataType:'json',
- data:data,
- success:function (res) {
- }
- })
- }
- function recommendlist(pageIndex) {
- loadingFlag = false;
- if (maxPage < page) {
- $(".loading").html("没有更多了")
- return;
- }
- $.ajax({
- type: "post",
- url: "/user/product/getProductListByCatId",
- dataType: 'json',
- data: {
- id: 6,
- num: 10,
- page: pageIndex
- },
- success: function (res) {
- if (res.errno == "0" && res.rst) {
- htmlEvent(res)
- }
- }
- })
- }
- function htmlEvent(res) {
- var data = res.rst.data;
- var content=""
- maxPage = res.rst.pageinfo.maxPage+1;
- //商品
- if (data.length > 0) {
- if (goodsData.length != 0) {
- goodsData = goodsData.concat(data);
- goodsData.forEach(function (item, index) {
- content+=`
- <li>
- <div class="top">
- <img class="icon" src="${item.icon}">
- <div class="word">
- <div class="name">${item.name}
- <div class="smallTitle" style="display:${item.prod_title.length==0?'none':'inline-block'}">${item.prod_title}</div>
- </div>
- <div class="descri">${item.description.substring(0, 11) + "..."}</div>
- </div>
- <a class="apply">申请</a>
- </div>
- <div class="bottom">
- <div class="limit">
- <div class="head">额度</div>
- ${item.upper_amount}-${item.lower_amount}
- </div>
- <div class="term">
- <div class="head">期限</div>
- ${item.term}
- </div>
- <div class="right">
- <div class="head" style="color:#fff;">1111</div>
- ${(item.applicants/10000).toFixed(2)}万人已经申请成功
- </div>
- </div>
- </li>`
- })
- } else {
- goodsData = res.rst.data;
- goodsData.forEach(function (item, index) {
- content+=`
- <li onclick='toDetail(${item.id},${JSON.stringify(item.link)})'>
- <div class="top">
- <img class="icon" src="${item.icon}">
- <div class="word">
- <div class="name">${item.name}
- <div class="smallTitle" style="display:${item.prod_title.length==0?'none':'inline-block'}">${item.prod_title}</div>
- </div>
- <div class="descri">${item.description.substring(0, 11) + "..."}</div>
- </div>
- <a class="apply">申请</a>
- </div>
- <div class="bottom">
- <div class="limit">
- <div class="head">额度</div>
- ${item.upper_amount}-${item.lower_amount}
- </div>
- <div class="term">
- <div class="head">期限</div>
- ${item.term}
- </div>
- <div class="right">
- <div class="head" style="color:#fff;">1111</div>
- ${(item.applicants/10000).toFixed(2)}万人已经申请成功
- </div>
- </div>
- </li>`
- })
- }
- loadingFlag = true;
- $('.list').html(content)
- $(".loading").html("努力加载中...")
- } else {
- $(".loading").html('暂无数据')
- }
- }
- function toDetail(id,link){
- var jsons = {
- product_Id:id,
- link:link,
- type:0
- };
- jsons = JSON.stringify(jsons);
- // 安卓
- if(navigator.userAgent.indexOf('Android') != -1){
- native.JSGetProductId(jsons)
- }
- }
- // 获取地址参数
- function parseQueryString(url) {
- var urlObj = {};
- var reg = /([^?=&]+)=([^?=&]+)/g;
- url.replace(reg, ($0, $1, $2) => {
- urlObj[$1] = decodeURIComponent($2);
- })
- return urlObj;
- }
|