productCategory.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. mui.init();
  2. mui('.mui-scroll-wrapper').scroll();
  3. var type=mobile.getUrlVars("type");
  4. if (!type){
  5. type = "";
  6. }
  7. var pageNumber = 1;
  8. var pageSize=10;
  9. var droploader;
  10. /**
  11. *初始化、添加监听
  12. */
  13. mui.ready(function(){
  14. getCategory();
  15. getProduct(type);
  16. $('.mui-bar-tab').on('tap', 'a', function(e) {
  17. location.href=$(this).attr("href");
  18. });
  19. $(".mui-segmented-control").on("tap",".mui-control-item",function(e){
  20. pageNumber=1;
  21. $(".section-list").empty();
  22. $(".dropload-down").remove();
  23. getProduct($(this).attr("data-id"));
  24. });
  25. //跳转
  26. $(".product").on('tap','li',function(){
  27. location.href=base+'/mobile/productDetail.jsp?id='+$(this).attr('data-id');
  28. });
  29. //推广
  30. $("#tuiguang").on('tap',function(){
  31. if(user.is_share=='1'){
  32. $("#share").show();
  33. }else{
  34. location.href=base+'/mobile/userInfo.jsp?flag=1';
  35. }
  36. });
  37. $("#kefu").on("tap",function(e){
  38. var html=[];
  39. html.push('<img src="'+mobile.getParam('customer_qrcode')+'" style="width:100%">' +
  40. '<a class="fs16" href="tel:'+mobile.getParam('customer_tel')+'">电话:'+mobile.getParam('customer_tel')+'</a>');
  41. mui.alert(html.join(""), '长按二维码联系客服');
  42. });
  43. //分享
  44. $(".share-bg").on('tap',function(){
  45. $("#share").hide();
  46. });
  47. //分享
  48. $(".share-img").on('tap',function(){
  49. $("#share").hide();
  50. });
  51. });
  52. function getCategory() {
  53. mobile.ajaxPost(base+'/productCategory/getList',{"navShow":"1"},function(json){
  54. if(json.data&&json.data.length>0){
  55. if (type){
  56. $(".mui-segmented-control .mui-scroll").append('<a class="mui-control-item" data-id="">全部</a>');
  57. }else{
  58. $(".mui-segmented-control .mui-scroll").append('<a class="mui-control-item mui-active" data-id="">全部</a>');
  59. }
  60. $.each(json.data,function (id,item) {
  61. if (item.id==type){
  62. $(".mui-segmented-control .mui-scroll").append('<a class="mui-control-item mui-active" data-id="'+item.id+'">'+item.cat_name+'</a>');
  63. }else{
  64. $(".mui-segmented-control .mui-scroll").append('<a class="mui-control-item" data-id="'+item.id+'">'+item.cat_name+'</a>');
  65. }
  66. });
  67. }
  68. });
  69. }
  70. /**
  71. *获取导航
  72. */
  73. function getProduct(type){
  74. if (droploader){
  75. droploader.lock();
  76. droploader.noData();
  77. droploader.resetload();
  78. }
  79. if(!type){
  80. type="";
  81. }
  82. droploader = $('.product-content').dropload({
  83. scrollArea : window,
  84. loadDownFn : function(me){
  85. mobile.ajaxPost(base+'/product/getList',{
  86. type: type,
  87. pageSize: pageSize,
  88. pageNumber: pageNumber
  89. },function(json){
  90. if(json.list&&json.list.length>0){
  91. if(pageNumber==json.totalPage){
  92. me.lock();
  93. me.noData();
  94. }else{
  95. pageNumber++;
  96. }
  97. var html=[];
  98. jQuery.each(json.list,function(id,item){
  99. html.push('<a class="section-item" href="'+base+'/mobile/productDetail.jsp?id='+item.id+'">');
  100. html.push('<div class="image-box">');
  101. html.push('<img class="product-lazy" data-original="'+imgUrl+item.product_main_img+'" style="width: 100%; display: block;">');
  102. if (item.time_status=='1'){
  103. html.push('<div class="section-item-status saled"></div>');
  104. }else if (item.time_status=='2'||item.time_status=='3'){
  105. html.push('<div class="section-item-status end"></div>');
  106. }
  107. html.push('</div>');
  108. html.push('<div class="info-box">');
  109. html.push('<div class="info-title">'+item.product_name+'</div>');
  110. html.push('<div class="items">');
  111. html.push('<div class="product-price item"><em>¥'+item.product_price+'<span class="del-line color3 ml5">'+item.product_old_price+'元</span></em></div>')
  112. html.push('<div class="fs12 color3">'+item.visit_num+'人关注</div>')
  113. html.push('</div></div>');
  114. html.push('</a>');
  115. });
  116. $(".section-list").append(html.join(""));
  117. droploader.resetload();
  118. $("img.product-lazy").lazyload({
  119. threshold : 200,
  120. effect: "fadeIn",
  121. placeholder: base+'/static/mobile/image/100.gif',
  122. skip_invisible : false
  123. });
  124. }else{
  125. droploader.lock();
  126. droploader.noData();
  127. droploader.resetload();
  128. }
  129. });
  130. }
  131. });
  132. }
  133. function checkTime(i){ //将0-9的数字前面加上0,例1变为01
  134. if(i<10)
  135. {
  136. i = "0" + i;
  137. }
  138. return i;
  139. }