pro-list.html 7.2 KB

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