pro-list.html 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  8. <title>产品列表</title>
  9. <link rel="stylesheet" type="text/css" href="css/mui.min.css" />
  10. <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  11. <link rel="stylesheet" type="text/css" href="css/main.css" />
  12. <script>
  13. //屏蔽分享
  14. document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
  15. WeixinJSBridge.call('hideOptionMenu');
  16. });
  17. </script>
  18. </head>
  19. <body>
  20. <!--底部菜单开始-->
  21. <footer class="mui-bar mui-bar-tab" id="footer-bar-tab">
  22. <a class="mui-tab-item">
  23. <span class="iconfont icon-shouye"></span>
  24. <span class="mui-tab-label">首页</span>
  25. </a>
  26. <a class="mui-tab-item mui-active">
  27. <span class="iconfont icon-liebiao"></span>
  28. <span class="mui-tab-label">列表</span>
  29. </a>
  30. <a class="mui-tab-item">
  31. <span class="iconfont icon-gouwuche"></span>
  32. <span class="mui-tab-label">购物车</span>
  33. </a>
  34. <a class="mui-tab-item">
  35. <span class="iconfont icon-huiyuan"></span>
  36. <span class="mui-tab-label">会员</span>
  37. </a>
  38. </footer>
  39. <!--底部菜单结束-->
  40. <!--内容开始-->
  41. <div>
  42. <!--头部选项卡-->
  43. <div id="pro-top-menu" class="mui-segmented-control">
  44. <!--(默认选中哪个就加上mui-active),其他不加-->
  45. <!--<a class="mui-control-item mui-active">声波牙刷</a>
  46. <a class="mui-control-item">刷头</a>-->
  47. </div>
  48. </div>
  49. <!--下拉刷新容器-->
  50. <div id="pullrefresh_pro_list" class="mui-content mui-scroll-wrapper" style="top: 44px;">
  51. <div class="mui-scroll">
  52. <ul class="mui-table-view mui-grid-view my-grid-view-no my-table-pull">
  53. <!--<li class="mui-table-view-cell mui-media mui-col-xs-6">
  54. <a>
  55. <img class="mui-media-object" src="images/pro-bai.png">
  56. <div class="pro-name">柔性声波牙刷</div>
  57. <h6>极光白</h6>
  58. <div class="pro-price">¥199.00</div>
  59. </a>
  60. </li>-->
  61. </ul>
  62. </div>
  63. </div>
  64. <!--内容结束-->
  65. <!-- 加载ing begin-->
  66. <div class="loading covers">
  67. <div class="loading-bj"></div>
  68. <p>正在加载...</p>
  69. </div>
  70. <!-- 加载ing end -->
  71. <script src="js/mui.min.js"></script>
  72. <script src="js/jquery-2.1.1.min.js"></script>
  73. <script src="js/main.js"></script>
  74. <script src="js/wechat-utils-1.0.js"></script>
  75. <script>
  76. window.addEventListener('pageshow', function(e) {
  77. // 通过persisted属性判断是否存在 BF Cache
  78. if(e.persisted) {
  79. location.reload();
  80. }
  81. });
  82. var typeId = getParam("typeId");//从URL带过来的产品类型id
  83. var pageNumber = 0,pagesize = 10;//pageNumber第几页,pagesize每页条数
  84. mui.init({
  85. pullRefresh: {
  86. container: '#pullrefresh_pro_list',//上拉加载容器
  87. down: {
  88. //callback: pulldownRefresh
  89. },
  90. up: {
  91. contentrefresh: '正在加载...',//上拉加载时显示的文字
  92. callback: pullupRefresh//上拉加载的回调方法
  93. }
  94. }
  95. });
  96. /**
  97. * 上拉加载具体业务实现
  98. */
  99. function pullupRefresh() {
  100. ++pageNumber;//每次上拉页数+1
  101. $.ajax(base_path + '/wechat/product/listProductColorByTypeId?dates=' + new Date().getTime(), {
  102. data: {
  103. "typeId":typeId,//产品类型id
  104. "pageNO":pageNumber,//pageNo第几页
  105. "pageSize":pagesize//pageSize每页条数
  106. },
  107. dataType: 'json',
  108. xhrFields: {
  109. withCredentials: true
  110. },
  111. crossDomain: true,
  112. type: 'get',
  113. timeout: 15000,
  114. success: function(dt) {
  115. if(dt.isRedirect) {
  116. location.href = dt.redirectURL;
  117. } else {
  118. if(dt.status) {//判断接口返回状态status
  119. var table = document.body.querySelector('.my-table-pull');//table是插入数据li的父级容器
  120. mui('#pullrefresh_pro_list').pullRefresh().endPullupToRefresh(dt.data.lastPage?false:true);//endPullupToRefresh(ture)表示没有更多数据了,停止上拉加载
  121. mui.each(dt.data.list, function(index) {
  122. var li = document.createElement('li');//创建li标签
  123. li.className='mui-table-view-cell mui-media mui-col-xs-6';//給li标签className
  124. li.innerHTML = '<a name="'+this.colorId+'" style="margin-top: 15px;">'
  125. +'<img class="mui-media-object" src="'+ this.productIntroduceImg +'"><div class="pro-name">'+this.productName+'</div>'
  126. // +'<h6 style="margin-top: 5px;">'+this.colorName+'</h6>'
  127. +'<div class="pro-price" style="margin-top: 10px;">¥'+ this.productShowPrice +'</div></a>';
  128. table.appendChild(li);//将li插入table
  129. });
  130. } else {
  131. mui.alert("获取产品列表失败!");
  132. }
  133. }
  134. },
  135. error: function(xhr, type, errorThrown) {
  136. console.log(xhr);
  137. mui.alert("获取产品列表失败!网络错误");
  138. }
  139. });
  140. }
  141. mui.ready(function() {//ready事件
  142. //获取产品类型
  143. $.ajax(base_path + '/wechat/product/listProductType?dates=' + new Date().getTime(), {
  144. data: {},// ajax参数 没有则不写
  145. dataType: 'json',
  146. xhrFields: {
  147. withCredentials: true
  148. },
  149. crossDomain: true,
  150. type: 'get',
  151. timeout: 15000,
  152. success: function(dt) {
  153. if(dt.isRedirect) {//先判断isRedirect,然后跳转redirectURL
  154. location.href = dt.redirectURL;
  155. } else {
  156. if(dt.status) {//判断接口返回状态status
  157. var table = document.body.querySelector("#pro-top-menu");//table是插入数据li的父级容器
  158. //mui.each()循环
  159. mui.each(dt.data, function(index) {
  160. var li = document.createElement('a');//创建a元素标签
  161. if(typeId != null) {//判断产品类型id不为null
  162. if(typeId == this.typeId) { //判断产品类型相等则选中
  163. li.className = 'mui-control-item mui-active';//选中的样式为mui-active
  164. } else {
  165. li.className = 'mui-control-item';
  166. }
  167. } else {
  168. if(index == 0) {//URL没有产品id则默认选中第0个
  169. li.className = 'mui-control-item mui-active';
  170. typeId=this.typeId;
  171. } else {
  172. li.className = 'mui-control-item';
  173. }
  174. }
  175. li.setAttribute("name",this.typeId);//防止页面id重复,所以把typeId放在name里面
  176. li.innerHTML=this.typeName;
  177. table.appendChild(li);//将li插入table
  178. });
  179. mui('#pullrefresh_pro_list').pullRefresh().pullupLoading();
  180. $(".loading").hide().css("opacity", "0"); //隐藏(正在加载...)
  181. } else {
  182. mui.alert("获取产品类型失败!");
  183. }
  184. }
  185. },
  186. error: function(xhr, type, errorThrown) {
  187. console.log(xhr);
  188. mui.alert("获取产品类型失败!网络错误");
  189. }
  190. });
  191. });
  192. //头部选项卡点击事件
  193. $(document).on('tap', '#pro-top-menu>a', function() {
  194. typeId=$(this).attr("name");//当前点击的类型id
  195. pageNumber=0;//页数归零
  196. $('.my-table-pull').empty();//清空产品列表
  197. mui('#pullrefresh_pro_list').pullRefresh().refresh(true);
  198. // mui('#pullrefresh_pro_list').pullRefresh().pullupLoading();//重新加载数据
  199. mui('.mui-scroll-wrapper').scroll().scrollTo(0,0,500);//500毫秒滚动到顶
  200. });
  201. //跳转产品详情
  202. $(document).on('tap', '.my-table-pull>li>a', function() {
  203. location.href='pro-details.html?colorId='+$(this).attr("name");
  204. });
  205. </script>
  206. </body>
  207. </html>