chanpin_list.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. mui.init({
  2. pullRefresh: {
  3. container: '#pullrefresh_chanpin_list',
  4. down: {},
  5. up: {
  6. contentrefresh: '正在加载...',
  7. callback: pullupRefresh
  8. }
  9. }
  10. });
  11. var pageNumber = 0,
  12. pagesize = 10,
  13. proType = "1";
  14. function pullupRefresh() {
  15. pageNumber += 1;
  16. $.ajax(base_path + '/product/productIndex?dates=' + new Date().getTime(), {
  17. data: {
  18. "pageSize": pagesize,
  19. "pageNO": pageNumber,
  20. "productType": proType
  21. },
  22. dataType: 'json',
  23. type: 'post',
  24. timeout: 15000,
  25. xhrFields: {
  26. withCredentials: true
  27. },
  28. crossDomain: true,
  29. success: function(dt) {
  30. if (dt.isRedirect) {
  31. location.href = dt.redirectURL;
  32. } else {
  33. if(dt.status) {
  34. var chanpin_data = [];
  35. chanpin_data = dt.data.productList;
  36. mui('#pullrefresh_chanpin_list').pullRefresh().endPullupToRefresh(chanpin_data.length < pagesize);
  37. var table = document.body.querySelector('.my-tab-view-pull');
  38. mui(chanpin_data).each(function(index) {
  39. var pro_color = this.productColor;
  40. var li = document.createElement('li');
  41. var yuanjia = '<s class="gwc-pp">原价:¥' + accDiv(this.productPrice, 100) + '</s>';
  42. if(marquee != '' && this.productDiscount == '328000') {
  43. yuanjia = '<span class="mui-h6">购买即赠3年滤芯</span>'
  44. }
  45. var img='';
  46. img=this.colorImg;
  47. if($(".box-list-card .iconfont").hasClass("icon-list")) {
  48. li.className = 'mui-table-view-cell mui-media';
  49. li.innerHTML = '<a proid="' + this.productId + '" colorid="'+this.colorId+'" class="go_chanpin_details"><img class="mui-media-object mui-pull-left wh-100" style="background: #eff5f7;" src="' + img + '"><div class="mui-media-body gwc-tit">' + this.productName + '</div><div class="mui-ellipsis mui-h6">' + this.productColorDes + '</div><div class="shop-price">' + marquee + '<span class="price-sp">¥' + accDiv(this.productDiscount, 100) + '</span>' + yuanjia + '</div></div></a>">';
  50. } else {
  51. li.className = 'mui-table-view-cell mui-media mui-col-xs-6';
  52. li.innerHTML = '<a proid="' + this.productId + '" colorid="'+this.colorId+'" class="go_chanpin_details"><img class="mui-media-object" style="background: #eff5f7;" src="' + img + '"><div class="mui-media-body gwc-tit">' + this.productName + '</div><div class="mui-ellipsis mui-h6">' + this.productColorDes + '</div><div class="shop-price">' + marquee + '<span class="price-sp">¥' + accDiv(this.productDiscount, 100) + '</span>' + yuanjia + '</div></a>';
  53. }
  54. table.appendChild(li)
  55. mui('#pullrefresh_chanpin_list').pullRefresh().disablePullupToRefresh();
  56. });
  57. if(chanpin_data.length==0){
  58. mui('#pullrefresh_chanpin_list').pullRefresh().disablePullupToRefresh();
  59. var li = document.createElement('li');
  60. li.className = 'mui-table-view-cell mui-media mui-col-xs-12 mui-text-center';
  61. li.innerHTML='<img style="width:100px;display:block;margin:40px auto 0 auto;" src="images/null-4.png" /><h6 class="mui-text-center">暂无产品信息,逛逛别的产品吧!</h6>';
  62. table.appendChild(li);
  63. }
  64. } else {
  65. mui('#pullrefresh_chanpin_list').pullRefresh().endPullupToRefresh(true)
  66. }
  67. }
  68. },
  69. error: function(xhr, type, errorThrown) {
  70. console.log(xhr)
  71. }
  72. })
  73. };
  74. function search_pullrefresh(str) {
  75. if(str != null && str != '') {
  76. if(!checkParameter(str)) {
  77. mui.alert('您输入的格式有误,请重新输入!')
  78. } else {
  79. pageNumber = 0;
  80. $('.my-tab-view-pull').empty();
  81. search_str = str;
  82. mui('#pullrefresh_chanpin_list').pullRefresh().refresh(true);
  83. mui('#pullrefresh_chanpin_list').pullRefresh().pullupLoading()
  84. }
  85. } else {
  86. pageNumber = 0;
  87. $('.my-tab-view-pull').empty();
  88. search_str = str;
  89. mui('#pullrefresh_chanpin_list').pullRefresh().refresh(true);
  90. mui('#pullrefresh_chanpin_list').pullRefresh().pullupLoading()
  91. }
  92. };
  93. //mui.os.ios ? listener_ipt() : keyup_fn();
  94. //
  95. //function keyup_fn() {
  96. // $('body').on('keyup', '#chanpin-search', function(e) {
  97. // var currKey = 0,
  98. // e = e || event;
  99. // currKey = e.keyCode || e.which || e.charCode;
  100. // var keyName = String.fromCharCode(currKey);
  101. // if(currKey == "13") {
  102. // var str = $.trim($('#chanpin-search').val());
  103. // search_pullrefresh(str)
  104. // }
  105. // })
  106. //};
  107. //document.getElementById('chanpin-search').addEventListener('input', function(e) {
  108. // var value = e.target.value
  109. //});
  110. //function listener_ipt() {
  111. // document.getElementById('chanpin-search').onblur = function() {
  112. // var str = $.trim($('#chanpin-search').val());
  113. // search_pullrefresh(str)
  114. // }
  115. //};
  116. mui.ready(function() {
  117. proType = getParam("proType");
  118. proType == null ? proType = "1" : proType;
  119. //springFestivalPop();
  120. marquee_Show();
  121. if(proType != 1) {
  122. $(".tab-with-chanpin-list .mui-control-item:first-child").removeClass('mui-active');
  123. $(".tab-with-chanpin-list .mui-control-item:last-child").addClass('mui-active');
  124. }
  125. mui('#pullrefresh_chanpin_list').pullRefresh().pullupLoading();
  126. getCartNum();
  127. document.querySelector('.loading-bg').style.display = 'none'
  128. });
  129. function checkParameter(remark) {
  130. if(!/^[\u4e00-\u9fa5_a-zA-Z0-9-]+$/.test(remark)) {
  131. return false
  132. }
  133. return true
  134. };
  135. $(document).on('tap', '.box-list-card', function() {
  136. var listcard = $(this).children().first();
  137. if(listcard.hasClass("icon-list")) {
  138. listcard.removeClass("icon-list").addClass("icon-list-card");
  139. $(".my-tab-view-pull").removeClass("mui-table-view-chevron").addClass("mui-grid-view");
  140. $(".mui-media-object").removeClass("mui-pull-left wh-100");
  141. $(".my-tab-view-pull .mui-table-view-cell").addClass("mui-col-xs-6")
  142. } else {
  143. listcard.removeClass("icon-list-card").addClass("icon-list");
  144. $(".my-tab-view-pull").removeClass("mui-grid-view").addClass("mui-table-view-chevron");
  145. $(".mui-media-object").addClass("mui-pull-left wh-100");
  146. $(".my-tab-view-pull .mui-table-view-cell").removeClass("mui-col-xs-6")
  147. }
  148. });
  149. mui.each(document.querySelectorAll('.tab-with-chanpin-list .mui-control-item'), function(index, el) {
  150. el.addEventListener('tap', function() {
  151. pageNumber = 0;
  152. switch(index) {
  153. case 0:
  154. proType = 1;
  155. break;
  156. case 1:
  157. proType = 16;
  158. break;
  159. default:
  160. proType = 1;
  161. break
  162. }
  163. var href=location.href;
  164. if(href.indexOf("proType")>0){
  165. history.pushState("", "产品列表",'//'+location.host+ html_path +'/chanpin_list.html?proType='+proType);
  166. }
  167. $('.my-tab-view-pull').empty();
  168. mui('#pullrefresh_chanpin_list').pullRefresh().refresh(true);
  169. mui('#pullrefresh_chanpin_list').pullRefresh().pullupLoading()
  170. }, false)
  171. });