var goods_list = [] var loadingFlag = true; var page=1; var token = '' $().ready(function(){ getToken() $(window).scroll(function(){ if($(window).scrollTop()>= $(document).height()-$(window).height() - 20){ //到达底部加载数据 if(loadingFlag){ page ++ ; listGoods(); } } }); }) //获取token function getToken () { var param = '{"js_callback" : "callBackMethodName"}'; try{ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ window.webkit.messageHandlers.app_h5_get_token.postMessage(param); } if(navigator.userAgent.match(/android/i)){ obj4H5.app_h5_get_token(param); } }catch(e){ //TODO handle the exception // token='3411a38f800b591905df2150e28a8f95633' // listGoods(); } } function callBackMethodName (data) {//app token 回调 var data = JSON.parse(data) token = data.token; listGoods(); } function app_to_goodsdetail (goods_id,goods_list_index) { //跳转到详情页 var param = { 'goodsId':goods_id, 'commissionRate':goods_list[goods_list_index].commission_rate } param = JSON.stringify(param) try{ if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){ window.webkit.messageHandlers.app_h5_to_goodsdetail.postMessage(param); } if(navigator.userAgent.match(/android/i)){ obj4H5.app_h5_to_goodsdetail(param); } _czc.push(["_trackEvent",'优惠券专区','跳转详情','goods_id:' + goods_id]); //埋点 }catch(e){ //TODO handle the exception } } function listGoods () { //获取热销榜单 loadingFlag = false; $("#loading").show(); $.ajax({ url:'/api/goods/listGoods', type:'post', dataType:'json', headers:{ 'token': token }, data:{ page:page, id:4, type:'module' }, success:function (res){ $("#loading").hide(); loadingFlag = true; if(res.errno == 0){ if(res.rst.data.length == 0){ showMsg('暂无更多商品') return; } if(page == 1){ goods_list=res.rst.data; }else{ goods_list=goods_list.concat(res.rst.data) } var list_html = '',shopType; goods_list.forEach(function (item,index) { if(item.shop_type == 1){ //天猫 shopType = '' }else{ shopType = '' } list_html += '
' + item.title + '