No Description

index.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var page=1;//页数
  2. var shopList=[]//商品详情列表
  3. var loadingFlag=false;//下拉到底的状态值
  4. var shopListHtml='';//列表数据
  5. var token=''
  6. var quan=''
  7. // 1.判断是否登录
  8. // 2.登录后获取token
  9. $().ready(function(){
  10. writeLogH5({action:'saleArea',channel:'H5',url:window.location.href});//埋点
  11. isLogin()//防止不登录
  12. // redGoodsList(1)
  13. $(window).scroll(function(){
  14. if($(window).scrollTop()>=$(document).height()-$(window).height()-180){
  15. if(loadingFlag) {
  16. page++; //页数
  17. redGoodsList(page);
  18. }
  19. }
  20. })
  21. })
  22. function isLogin() {
  23. var param='{"js_callback":"callBackMethod"}'
  24. try {
  25. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  26. window.webkit.messageHandlers.app_h5_isLogin.postMessage(param);
  27. }
  28. if (navigator.userAgent.match(/android/i)) {
  29. obj4H5.app_h5_isLogin(param);
  30. }
  31. } catch (error) {
  32. // redGoodsList(1)
  33. }
  34. }
  35. function callBackMethod(data) {
  36. var data=JSON.parse(data);
  37. // 登陆状态
  38. if(data.isLogin) {
  39. token=data.token;
  40. }else {
  41. token=''
  42. }
  43. redGoodsList(1)
  44. }
  45. // 获取商品列表
  46. function redGoodsList (page) {
  47. loadingFlag=false
  48. $(".loading").show();
  49. $.ajax({
  50. url:'/api/v2/goods/specialSaleBlock',
  51. type:'post',
  52. headers: {
  53. 'token': token
  54. },
  55. data:{
  56. 'page':page
  57. },
  58. success:function (res){
  59. $(".loading").hide();
  60. if(res.errno == 0){
  61. shopList=res.rst.data
  62. shopList.forEach(function(item) {
  63. item.goods_id=item.goods_id;
  64. item.is_coupon=item.is_coupon;
  65. item.coupon_price=item.coupon_price;
  66. item.discount_price=item.discount_price;
  67. item.commission_rate=item.commission_rate;
  68. item.coupon_start_time=item.coupon_start_time;
  69. item.coupon_end_time=item.coupon_end_time;
  70. // 佣金计算
  71. // 有券情况下
  72. if(new Date(item.coupon_end_time)>=new Date()||item.coupon_id&&item.is_coupon == 1) {
  73. quan = '<div class="quan" style="margin-left:'+(!item.commission_price?"0":".09rem")+'"><em>券</em><span>'+item.coupon_price+'元</span></div>'
  74. }else {
  75. quan = ""
  76. }
  77. 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" style="display:'+(!item.red_active_status==0?"none":"block")+'" alt=""><div class="envelopes" style="display:'+(!item.red_active_status==0?"none":"block")+'">'+item.red_active_money+'元红包</div></div>'+quan+'<div class="rebate" style="display:'+(!item.commission_price?"none":"block")+'">返 '+item.commission_price+'元</div></div></div></li>'
  78. });
  79. style="display:'item.red'"
  80. $(".list").html(shopListHtml)
  81. // 图片懒加载
  82. echo.init();
  83. if(shopList.length!=0) {
  84. loadingFlag=true
  85. }
  86. }
  87. },
  88. error:function () {
  89. $(".loading").hide();
  90. }
  91. })
  92. }
  93. //跳转到app详情页
  94. function shareWechatUrl(data) {
  95. var arr=data.split(",")
  96. writeLogH5({action:'go-detail',channel:'H5',url:window.location.href,categroy_id:3890,goods_id:unescape(arr[0])});//埋点
  97. var param = {
  98. "goods_id":unescape(arr[0]),
  99. "is_coupon":unescape(arr[1]),
  100. "coupon_price":unescape(arr[2]),
  101. "discount_price":unescape(arr[3]),
  102. "commission_rate":unescape(arr[4]),
  103. "coupon_start_time":unescape(arr[5]),
  104. "coupon_end_time":unescape(arr[6]),
  105. "title":unescape(arr[7]),
  106. "is_high_commission":unescape(arr[8]),
  107. "img":unescape(arr[9])
  108. }
  109. param = JSON.stringify(param)
  110. if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
  111. window.webkit.messageHandlers.app_h5_open_goodDetail.postMessage(param);
  112. }
  113. if (navigator.userAgent.match(/android/i)) {
  114. obj4H5.app_h5_open_goodDetail(param);
  115. }
  116. }
  117. // h5埋点
  118. function writeLogH5 (data) {
  119. $.ajax({
  120. type:'post',
  121. url:'/api/v2/channel/writeLogH5',
  122. dataType:'json',
  123. data:data,
  124. success:function (res) {
  125. }
  126. })
  127. }