酷店app

yhq.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. var goods_list = []
  2. var loadingFlag = true;
  3. var page=1;
  4. var token = ''
  5. $().ready(function(){
  6. getToken()
  7. $(window).scroll(function(){
  8. if($(window).scrollTop()>= $(document).height()-$(window).height() - 20){
  9. //到达底部加载数据
  10. if(loadingFlag){
  11. page ++ ;
  12. listGoods();
  13. }
  14. }
  15. });
  16. })
  17. //获取token
  18. function getToken () {
  19. var param = '{"js_callback" : "callBackMethodName"}';
  20. try{
  21. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  22. window.webkit.messageHandlers.app_h5_get_token.postMessage(param);
  23. }
  24. if(navigator.userAgent.match(/android/i)){
  25. obj4H5.app_h5_get_token(param);
  26. }
  27. }catch(e){
  28. //TODO handle the exception
  29. // token='3411a38f800b591905df2150e28a8f95633'
  30. // listGoods();
  31. }
  32. }
  33. function callBackMethodName (data) {//app token 回调
  34. var data = JSON.parse(data)
  35. token = data.token;
  36. listGoods();
  37. }
  38. function app_to_goodsdetail (goods_id,goods_list_index) {
  39. //跳转到详情页
  40. var param = {
  41. 'goodsId':goods_id,
  42. 'commissionRate':goods_list[goods_list_index].commission_rate
  43. }
  44. param = JSON.stringify(param)
  45. try{
  46. if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
  47. window.webkit.messageHandlers.app_h5_to_goodsdetail.postMessage(param);
  48. }
  49. if(navigator.userAgent.match(/android/i)){
  50. obj4H5.app_h5_to_goodsdetail(param);
  51. }
  52. _czc.push(["_trackEvent",'优惠券专区','跳转详情','goods_id:' + goods_id]); //埋点
  53. }catch(e){
  54. //TODO handle the exception
  55. }
  56. }
  57. function listGoods () {
  58. //获取热销榜单
  59. loadingFlag = false;
  60. $("#loading").show();
  61. $.ajax({
  62. url:'/api/goods/listGoods',
  63. type:'post',
  64. dataType:'json',
  65. headers:{
  66. 'token': token
  67. },
  68. data:{
  69. page:page,
  70. id:4,
  71. type:'module'
  72. },
  73. success:function (res){
  74. $("#loading").hide();
  75. loadingFlag = true;
  76. if(res.errno == 0){
  77. if(res.rst.data.length == 0){
  78. showMsg('暂无更多商品')
  79. return;
  80. }
  81. if(page == 1){
  82. goods_list=res.rst.data;
  83. }else{
  84. goods_list=goods_list.concat(res.rst.data)
  85. }
  86. var list_html = '',shopType;
  87. goods_list.forEach(function (item,index) {
  88. if(item.shop_type == 1){
  89. //天猫
  90. shopType = '<img src="../common/tianmao.png"/>'
  91. }else{
  92. shopType = '<img src="../common/taobao.png"/>'
  93. }
  94. list_html += '<li onclick="app_to_goodsdetail(' + item.goods_id + ',' + index + ')"><div class="goods_img"><img src="' + item.img + '"/></div><div class="goods_info"><p class="goods_title">' + item.title + '</p><div class="goods_shop"><div class="shop">'+ shopType + item.shop_title + '</span></div><span class="monthly_sale">月售:' + item.volume + '</span></div><div class="price_info"><div class="left"><div class="price">¥<span>'+item.discount_price+'</span></div><div class="quan"><em>券</em><span>'+item.coupon_price+'</span></div></div><div class="right">利润<span>'+item.commission_rate+'</span></div></div></div></li>'
  95. });
  96. $("#list").html(list_html)
  97. }else{
  98. showMsg(res.err)
  99. }
  100. },
  101. error:function (err){
  102. $("#loading").hide();
  103. showMsg('请稍后重试!')
  104. }
  105. })
  106. }
  107. //提示弹框
  108. function showMsg(msg) {
  109. var msgBox = document.getElementsByClassName('alert-info')[0];
  110. msgBox.children[0].innerText = msg;
  111. msgBox.style.display="block";
  112. setTimeout(function() {
  113. msgBox.style.display="none";
  114. }, 1500);
  115. }