chanpin_list.js 7.7 KB

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