123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- 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 = "<div class='quan'><em>券</em><span>"+item.coupon_price+"元</span></div>"
- }else {
- quan = ""
- }
- shopListHtml+='<li onclick=shareWechatUrl("'+escape(item.goods_id)+","+escape(item.is_coupon)+","+escape(item.coupon_price)+","+escape(item.discount_price)+","+escape(item.commission_rate)+","+escape(item.coupon_start_time)+","+escape(item.coupon_end_time)+","+escape(item.title)+","+escape(item.is_high_commission)+","+escape(item.img)+'")><img class="picture lazy" src="./img/blank.gif" data-echo="'+item.img+'"><div class="info"><p class="title">'+item.title+'</p><div class="number"><span class="price">¥'+item.discount_price+'</span><span class="volume">销量'+item.volume+'</span></div><div class="cheap"><div class="left"><img class="icon" src="./img/quan.png" alt=""><div class="envelopes"> '+item.red_active_money+'元红包</div></div>'+quan+'<div class="rebate" style="display:'+(!item.commission_price?"none":"block")+'">返 '+item.commission_price+'元</div></div></div></li>'
- });
- $(".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) {
- }
- })
- }
|