var page=1;//页数 var shopList=[]//商品详情列表 var loadingFlag=false;//下拉到底的状态值 var shopListHtml='';//列表数据 var token='' var quan='' // 1.判断是否登录 // 2.登录后获取token $().ready(function(){ writeLogH5({action:'saleArea',channel:'H5',url:window.location.href});//埋点 isLogin()//防止不登录 $(window).scroll(function(){ if($(window).scrollTop()>=$(document).height()-$(window).height()-180){ if(loadingFlag) { page++; //页数 redGoodsList(page); } } }) }) function isLogin() { var param='{"js_callback":"callBackMethod"}' try { if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { window.webkit.messageHandlers.app_h5_isLogin.postMessage(param); } if (navigator.userAgent.match(/android/i)) { obj4H5.app_h5_isLogin(param); } } catch (error) { // redGoodsList(1) } } function callBackMethod(data) { var data=JSON.parse(data); // 登陆状态 if(data.isLogin) { token=data.token; }else { token='' } redGoodsList(1) } // 获取商品列表 function redGoodsList (page) { loadingFlag=false $(".loading").show(); $.ajax({ url:'/api/v2/goods/specialSaleBlock', type:'post', headers: { 'token': token }, data:{ 'page':page }, success:function (res){ $(".loading").hide(); if(res.errno == 0){ shopList=res.rst.data shopList.forEach(function(item) { item.goods_id=item.goods_id; item.is_coupon=item.is_coupon; item.coupon_price=item.coupon_price; item.discount_price=item.discount_price; item.commission_rate=item.commission_rate; item.coupon_start_time=item.coupon_start_time; item.coupon_end_time=item.coupon_end_time; // 佣金计算 // 有券情况下 if(new Date(item.coupon_end_time)>=new Date()||item.coupon_id&&item.is_coupon == 1) { quan = "
"+item.coupon_price+"元
" }else { quan = "" } shopListHtml+='
  • '+item.title+'

    ¥'+item.discount_price+'销量'+item.volume+'
    '+item.red_active_money+'元红包
    '+quan+'
    返 '+item.commission_price+'元
  • ' }); $(".list").html(shopListHtml) // 图片懒加载 echo.init(); if(shopList.length!=0) { loadingFlag=true } } }, error:function () { $(".loading").hide(); } }) } //跳转到app详情页 function shareWechatUrl(data) { var arr=data.split(",") writeLogH5({action:'go-detail',channel:'H5',url:window.location.href,categroy_id:3890,goods_id:unescape(arr[0])});//埋点 var param = { "goods_id":unescape(arr[0]), "is_coupon":unescape(arr[1]), "coupon_price":unescape(arr[2]), "discount_price":unescape(arr[3]), "commission_rate":unescape(arr[4]), "coupon_start_time":unescape(arr[5]), "coupon_end_time":unescape(arr[6]), "title":unescape(arr[7]), "is_high_commission":unescape(arr[8]), "img":unescape(arr[9]) } param = JSON.stringify(param) if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { window.webkit.messageHandlers.app_h5_open_goodDetail.postMessage(param); } if (navigator.userAgent.match(/android/i)) { obj4H5.app_h5_open_goodDetail(param); } } // h5埋点 function writeLogH5 (data) { $.ajax({ type:'post', url:'/api/v2/channel/writeLogH5', dataType:'json', data:data, success:function (res) { } }) }