Sin descripción

index.js_1 4.7KB

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