pro-list.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. <style>
  13. .my-picker {max-height: 100%;background-color: rgba(0, 0, 0, .5);}
  14. .my-btn-buy-know {width: 50%;border-radius: 0;bottom: 0;height: 50px;border: 1px solid #727171;position: fixed;right: 0;}
  15. .my-btn-buy-cancel {width: 50%;border-radius: 0;bottom: 0;height: 50px;border: 0;border-top: 1px solid #ccc;position: fixed;left: 0;}
  16. </style>
  17. </head>
  18. <body>
  19. <header class="mui-bar mui-bar-nav">
  20. <div id="pro-menu" class="mui-segmented-control">
  21. <!--<a class="mui-control-item mui-active" href="#item1">净水机</a>
  22. <a class="mui-control-item" href="#item2">冲奶机</a>
  23. <a class="mui-control-item" href="#item3">电动牙刷</a>-->
  24. </div>
  25. </header>
  26. <footer class="mui-bar mui-bar-tab" id="footer-bar-tab">
  27. <a class="mui-tab-item">
  28. <span class="iconfont icon-shouye"></span>
  29. <span class="mui-tab-label">首页</span>
  30. </a>
  31. <a class="mui-tab-item">
  32. <span class="iconfont icon-gouwuche"></span>
  33. <span class="mui-tab-label">购物车</span>
  34. </a>
  35. <a class="mui-tab-item">
  36. <span class="iconfont icon-dingdan"></span>
  37. <span class="mui-tab-label">订单</span>
  38. </a>
  39. <a class="mui-tab-item">
  40. <span class="iconfont icon-wode"></span>
  41. <span class="mui-tab-label">我的</span>
  42. </a>
  43. </footer>
  44. <div class="mui-content">
  45. <!--<div class="index-title">
  46. <strong>选购</strong>
  47. </div>-->
  48. <div id="item1" class="mui-control-content mui-active">
  49. <ul class="pro-table-pull">
  50. <!--产品列表区域-->
  51. </ul>
  52. <!--<div class="index-title">
  53. <strong>配件选购</strong>
  54. </div>-->
  55. <!--<ul class="mui-table-view mui-grid-view my-view-no" style="padding-bottom: 0;">
  56. <li class="mui-table-view-cell mui-media mui-col-xs-5">
  57. <a href="#"><img class="mui-media-object" src="images/chanpin-2.jpg"></a>
  58. </li>
  59. <li class="mui-table-view-cell mui-media mui-col-xs-7">
  60. <a>
  61. <div class="pro-tit">Aiberle智能净水机滤芯配件 t1、t2、t3、t4</div>
  62. <h6 class="mui-text-left">4级ro净化、只喝净水</h6>
  63. <p class="pro-price">¥79.00~320.00</p>
  64. <div class="mui-text-right">
  65. <span class="add-cart"><span class="iconfont icon-gouwuche"></span></span>
  66. <button type="button" class="btn-buy-now">立即购买</button>
  67. </div>
  68. </a>
  69. </li>
  70. <li class="mui-table-view-cell mui-media mui-col-xs-5">
  71. <a href="#"><img class="mui-media-object" src="images/chanpin-3.jpg"></a>
  72. </li>
  73. <li class="mui-table-view-cell mui-media mui-col-xs-7">
  74. <a>
  75. <div class="pro-tit">Aiberle智能净水机水箱配件</div>
  76. <h6 class="mui-text-left">优质安全材质,放心使用</h6>
  77. <p class="pro-price">¥99.00</p>
  78. <div class="mui-text-right">
  79. <span class="add-cart"><span class="iconfont icon-gouwuche"></span></span>
  80. <button type="button" class="btn-buy-now">立即购买</button>
  81. </div>
  82. </a>
  83. </li>
  84. </ul>-->
  85. </div>
  86. <div id="product-type">
  87. </div>
  88. <!--<div id="item2" class="mui-control-content">
  89. <ul class="pro-table-pull">
  90. </ul>
  91. </div>
  92. <div id="item3" class="mui-control-content">
  93. <ul class="pro-table-pull">
  94. </ul>
  95. </div>
  96. <div id="item4" class="mui-control-content">
  97. <ul class="pro-table-pull">
  98. </ul>
  99. </div>
  100. <div id="item5" class="mui-control-content">
  101. <ul class="pro-table-pull">
  102. </ul>
  103. </div>
  104. <div id="item6" class="mui-control-content">
  105. <ul class="pro-table-pull">
  106. </ul>
  107. </div>
  108. <div id="item7" class="mui-control-content">
  109. <ul class="pro-table-pull">
  110. </ul>
  111. </div>
  112. <div id="item10" class="mui-control-content">
  113. <ul class="pro-table-pull">
  114. </ul>
  115. </div>
  116. <div id="item11" class="mui-control-content">
  117. <ul class="pro-table-pull">
  118. </ul>
  119. </div>-->
  120. </div>
  121. <!-- 加载ing -->
  122. <div class="loading covers">
  123. <div class="loading-bj"></div>
  124. <p>加载中...</p>
  125. </div>
  126. <!-- 加载ing END -->
  127. <script src="js/mui.min.js"></script>
  128. <script src="js/jquery-2.1.1.min.js"></script>
  129. <script src="js/main.js"></script>
  130. <script src="js/wechat-utils-1.0.js"></script>
  131. <script>
  132. var search_data = null,
  133. typeId = '';
  134. if(!window.sessionStorage) {
  135. mui.alert("您的浏览器不支持sessionStorage");
  136. } else {
  137. //读取上一个页面带过来的sessionStorage
  138. search_data = JSON.parse(sessionStorage.getItem('search_data'));
  139. if(search_data != null) {
  140. typeId = search_data.text[0].typeId; //如果不为空就赋值給typeId(产品类型id)
  141. //$('#item'+typeId+']').addClass("mui-active").siblings().removeClass("mui-active");
  142. } else {
  143. typeId = getParam("productId");
  144. }
  145. }
  146. var mao = getParam("childTypeId"),
  147. maodian = '';
  148. mui.ready(function() {
  149. //页面首次加载区分
  150. if(typeId != '') {
  151. getProlist(typeId, null);
  152. } else {
  153. getProlist(null, null);
  154. }
  155. $(".loading").hide().css("opacity", "0"); //页面加载完成,隐藏loading
  156. });
  157. //查询产品列表(items代表显示类型)(load值为null代表没有从其他页面带参数,并且是首次加载,其他值代表选中的区域)
  158. function getProlist(items, load) {
  159. console.log(items, load);
  160. var parameter = {};
  161. if(items != null) {
  162. parameter["typeId"] = items;
  163. }
  164. $.ajax(base_path + '/wechat/product/productIndex?dates=' + new Date().getTime(), {
  165. data: parameter,
  166. dataType: 'json',
  167. xhrFields: {
  168. withCredentials: true
  169. },
  170. crossDomain: true,
  171. type: 'post',
  172. timeout: 15000,
  173. success: function(dt) {
  174. if(dt.isRedirect) {
  175. location.href = dt.redirectURL;
  176. } else {
  177. console.log(dt)
  178. if(dt.status) {
  179. var productTypeList = dt.data.productTypeList;
  180. var typeHtml = '';
  181. for(var k = 0; k < productTypeList.length; k++) {
  182. var typeId = productTypeList[k].typeId;
  183. typeHtml += '<div id="item' + typeId + '" class="mui-control-content">';
  184. typeHtml += '<ul class="pro-table-pull">';
  185. typeHtml += '</ul>';
  186. typeHtml += '</div>';
  187. }
  188. $("#product-type").html(typeHtml);
  189. var menu_data = dt.data.productTypeList;
  190. if(load == null) {
  191. var table = document.body.querySelector("#pro-menu");
  192. mui(menu_data).each(function(index) {
  193. var li = document.createElement('a');
  194. if(items != null) {
  195. if(items == this.typeId) {
  196. li.className = 'mui-control-item mui-active';
  197. } else {
  198. li.className = 'mui-control-item';
  199. }
  200. } else {
  201. if(index == 0) {
  202. li.className = 'mui-control-item mui-active';
  203. } else {
  204. li.className = 'mui-control-item';
  205. }
  206. }
  207. li.setAttribute("name", this.typeId);
  208. li.setAttribute("href", "#item" + (index + 1));
  209. li.innerHTML = this.typeName;
  210. table.appendChild(li);
  211. });
  212. }
  213. var pro_list = dt.data.productList;
  214. if(items == null) {
  215. items = 1
  216. }
  217. $(".mui-control-content").removeClass("mui-active");
  218. var table1 = document.body.querySelector('#item' + items + ' .pro-table-pull');
  219. $("#item" + items).addClass("mui-active");
  220. if(load != null) {
  221. document.body.querySelector(load + " .pro-table-pull");
  222. table1.innerHTML = '';
  223. }
  224. var n = '';
  225. mui(pro_list).each(function(index) {
  226. var div = document.createElement('div');
  227. div.className = 'index-title';
  228. div.innerHTML = '<strong>' + this.productChildTypeName + '</strong>';
  229. if(index == 0) {
  230. table1.appendChild(div);
  231. }
  232. if(n != '' && this.productChildTypeName != n) {
  233. table1.appendChild(div);
  234. }
  235. n = this.productChildTypeName;
  236. var li = document.createElement('li');
  237. li.setAttribute("name", this.productId);
  238. li.setAttribute("class", "product-id");
  239. var zen = '';
  240. console.log(this.productColorList)
  241. if(this.productColorList.length > 0) {
  242. $.each(this.productColorList[0].salesUserGiftList, function() {
  243. zen += this.giftName + "、"
  244. });
  245. }
  246. if(zen != '') {
  247. zen = '<div class="index-title"><p><span class="iconfont icon-liwu"></span>' + zen.substring(0, zen.length - 1) + '</p></div>';
  248. }
  249. if(mao != null && mao == this.productChildType) {
  250. li.setAttribute("id", "mao-" + this.productId);
  251. maodian = this.productId;
  252. mao = null;
  253. }
  254. var c = 'FFF',
  255. cList = '';
  256. mui(this.productColorList).each(function(index) {
  257. if(typeof(this.colorCode) != "undefined") {
  258. c = this.colorCode;
  259. }
  260. cList += '<i style="width:12px;height:12px;box-shadow: 0 0 1px rgba(0,0,0,.85);background:#' + c + ';display: inline-block;border-radius: 10px;margin: 0 3px 0 10px;"></i>';
  261. });
  262. if(this.productColorList != null && this.productColorList.length > 0){
  263. li.innerHTML = '<ul class="mui-table-view mui-grid-view my-view-no" style="padding-bottom: 0;"><li class="mui-table-view-cell mui-media mui-col-xs-5 mui-text-left"><a><img class="mui-media-object to-product" src="' + this.productParameterImg + '"></a></li><li class="mui-table-view-cell mui-media mui-col-xs-7"><a><div class="pro-tit to-product" >' + this.productName + '</div><h6 class="mui-text-left" style="white-space: pre-wrap;">' + this.productColorDes + '</h6><p class="pro-price"><span style="float:left;">¥' + accDiv(this.productColorList[0].colorDiscount,100) + '</span>'+cList+'</p><div class="mui-text-right"><span class="add-cart" name="' + this.productId + '" cartIsSource="1"><span class="iconfont icon-gouwuche"></span></span><button type="button" class="btn-buy-now" name="' + this.productId + '" cartIsSource="1">立即购买</button></div></a></li></ul>' + zen;
  264. table1.appendChild(li);
  265. }
  266. });
  267. if(maodian != '') {
  268. var t = $('#mao-' + maodian).offset().top;
  269. if(t > 300) {
  270. $(window).scrollTop(t, 500);
  271. }
  272. maodian = '';
  273. }
  274. } else {
  275. mui.alert("获取商品菜单失败!");
  276. }
  277. }
  278. },
  279. error: function(xhr, type, errorThrown) {
  280. console.log(xhr);
  281. mui.alert("获取商品菜单失败!网络错误");
  282. }
  283. });
  284. }
  285. //头部菜单点击事件
  286. $(document).on('tap', '#pro-menu .mui-control-item', function() {
  287. var th = $(this);
  288. if(!window.sessionStorage) {
  289. mui.alert("您的浏览器不支持sessionStorage");
  290. } else {
  291. //如果点击头部的菜单,则删除其他页面带过来的sessionStorage
  292. sessionStorage.removeItem('search_data');
  293. }
  294. //根据类型获取产品列表
  295. getProlist(th.attr("name"), th.attr("href"));
  296. var oldUrl = location.href; //原浏览器地址
  297. var newUrl = jsUrlHelper.delUrlParam(oldUrl, "childTypeId"); //删除url中的子类型参数
  298. newUrl = jsUrlHelper.putUrlParam(newUrl, 'productId', th.attr("name")); //修改url中的productId参数
  299. history.pushState(oldUrl, '产品类型', newUrl); //无刷新删除修改url地址参数
  300. console.log("url历史操作" + history.length + "次"); //获取历史操作过url地址几次
  301. mao = null;
  302. });
  303. //监听浏览器前进后退
  304. window.addEventListener("popstate", function() {
  305. var currentState = history.state;
  306. //根据类型获取产品列表
  307. mao = getParam("childTypeId"), ref = '';
  308. $.each($("#pro-menu .mui-control-item"), function() {
  309. if($(this).attr("name") == getParam("productId")) {
  310. ref = $(this).attr("href");
  311. $(this).addClass("mui-active");
  312. } else {
  313. $(this).removeClass("mui-active");
  314. }
  315. })
  316. getProlist(getParam("productId"), ref);
  317. });
  318. var count = 0; //统计所有产品加减,数量默认0,当count<1的时候设置(结算)按钮失效
  319. //购物车数量加
  320. $(document).on('tap', '.mui-btn-numbox-plus', function() {
  321. ++count; //产品总数量
  322. var th = $(this);
  323. var val = mui(th.parent()[0]).numbox().getValue(); //获取当前产品数量
  324. var parameter = {}; //ajax参数json集合
  325. if(typeof(th.attr("productid")) != "undefined") {
  326. parameter["productId"] = th.attr("productid"); //产品id
  327. if(typeof(th.attr("colorid")) != "undefined") {
  328. parameter["productColorId"] = th.attr("colorid"); //颜色id
  329. parameter["cartNum"] = 1; //需要减的产品数量,每次都是1
  330. $.ajax(base_path + '/wechat/cart/addProductToCart?dates=' + new Date().getTime(), {
  331. data: parameter,
  332. dataType: 'json',
  333. xhrFields: {
  334. withCredentials: true
  335. },
  336. crossDomain: true,
  337. type: 'post',
  338. timeout: 15000,
  339. success: function(dt) {
  340. if(dt.isRedirect) {
  341. location.href = dt.redirectURL;
  342. } else {
  343. if(dt.status) {
  344. th.parent().attr("cartid", dt.data);
  345. console.log("增加数量成功!");
  346. } else {
  347. mui.alert("增加数量失败!");
  348. }
  349. }
  350. },
  351. error: function(xhr, type, errorThrown) {
  352. console.log(xhr);
  353. mui.alert("增加数量失败!网络错误");
  354. }
  355. });
  356. } else {
  357. mui.alert("没有获取到产品颜色id");
  358. }
  359. } else {
  360. mui.alert("没有获取到产品id");
  361. }
  362. });
  363. //购物车数量减
  364. $(document).on('tap', '.mui-btn-numbox-minus', function() {
  365. --count; //产品总数量
  366. var th = $(this);
  367. var val = mui(th.parent()[0]).numbox().getValue(); //获取当前产品数量
  368. if(val == 0) {
  369. th.parent().removeAttr("cartid");
  370. }
  371. var parameter = {}; //ajax参数json集合
  372. if(typeof(th.attr("colorid")) != "undefined") {
  373. parameter["productColorId"] = th.attr("colorid"); //产品颜色id
  374. parameter["cartNum"] = 1; //需要减的产品数量,每次都是1
  375. $.ajax(base_path + '/wechat/cart/deleteCart?dates=' + new Date().getTime(), {
  376. data: parameter,
  377. dataType: 'json',
  378. xhrFields: {
  379. withCredentials: true
  380. },
  381. crossDomain: true,
  382. type: 'get', //减少数量后台限制用get
  383. timeout: 15000,
  384. success: function(dt) {
  385. if(dt.isRedirect) {
  386. location.href = dt.redirectURL;
  387. } else {
  388. if(dt.status) {
  389. console.log("减少数量数量成功!");
  390. } else {
  391. mui.alert("减少数量数量失败!");
  392. }
  393. }
  394. },
  395. error: function(xhr, type, errorThrown) {
  396. console.log(xhr);
  397. mui.alert("减少数量失败!网络错误");
  398. }
  399. });
  400. } else {
  401. mui.alert("没有获取到产品颜色id");
  402. }
  403. });
  404. //立即购买-购物车按钮 获取颜色列表
  405. $(document).on('tap', '.add-cart,.btn-buy-now', function() {
  406. count = 0;
  407. var th = $(this);
  408. //mask.show(); //显示遮罩层
  409. //在body尾部增加-产品颜色列表父级ul
  410. $("body").append('<div id="scroll" class="mui-scroll-wrapper my-picker"><div class="mui-scroll" style="top: 0;background-color: #fff;min-height: 100%;"><br/><ul class="mui-table-view mui-table-view-striped mui-table-view-condensed my-grid-view-no" style="margin-bottom: 50px;"></ul><button class="mui-btn my-btn-buy-cancel">取消</button><button class="mui-btn my-btn-buy-know" disabled="disabled">确定</button></div></div>');
  411. $.ajax(base_path + '/wechat/product/selectProductColor?dates=' + new Date().getTime(), {
  412. data: {
  413. "productId": th.attr("name") //productId产品id
  414. },
  415. dataType: 'json',
  416. xhrFields: {
  417. withCredentials: true
  418. },
  419. crossDomain: true,
  420. type: 'post',
  421. timeout: 15000,
  422. success: function(dt) {
  423. if(dt.isRedirect) {
  424. location.href = dt.redirectURL;
  425. } else {
  426. if(dt.status) {
  427. console.log(dt)
  428. var data = dt.data.productColorList;
  429. var table = document.body.querySelector('.my-picker .mui-table-view'); //产品颜色列表父级ul
  430. table.innerHTML = '';
  431. //循环遍历产品颜色数组
  432. mui(data).each(function(index) {
  433. var li = document.createElement('li'); //创建li标签
  434. li.className = 'my-table-view-cell'; //給li标签设置className
  435. if(typeof(this.cartNum) != "undefined") {
  436. count += parseInt(this.cartNum);
  437. } else {
  438. this.cartNum = 0;
  439. }
  440. li.innerHTML = '<div class="mui-table" ><div class="mui-table-cell mui-col-xs-3"><img class="my-media-object" src="' + this.colorProductPic + '" /></div><div class="mui-table-cell table-middle mui-col-xs-5">' + this.colorName + '<h6>' + this.colorDesc + '</h6><div style="color: #ff3b3b;">¥' + accDiv(this.colorDiscount, 100) + '</div></div><div class="mui-table-cell table-middle mui-col-xs-4"><div class="mui-numbox" data-numbox-min="0" data-numbox-max="99" cartid="' + this.cartId + '"><button class="mui-btn mui-btn-numbox-minus" type="button" productid="' + this.colorProductId + '" colorid="' + this.colorId + '">-</button><input class="mui-input-numbox" type="number" value="' + this.cartNum + '" readonly="readonly"/><button class="mui-btn mui-btn-numbox-plus" type="button" productid="' + this.colorProductId + '" colorid="' + this.colorId + '">+</button></div></div></div>';
  441. table.appendChild(li); //将li标签加入到-产品颜色列表父级ul
  442. });
  443. $(".my-picker").addClass("active"); //显示产品颜色加减数量列表
  444. // if(count > 0) {
  445. $(".my-btn-buy-know").removeAttr("disabled"); //激活结算按钮
  446. // }
  447. if(th.hasClass("add-cart")) {
  448. $(".my-btn-buy-know").attr("cart", "cart");
  449. }
  450. mui(".mui-numbox").numbox(); //激活加减按钮组合
  451. mui('#scroll').scroll();
  452. } else {
  453. mui.alert("获取数据失败!");
  454. }
  455. }
  456. },
  457. error: function(xhr, type, errorThrown) {
  458. console.log(xhr);
  459. mui.alert("获取数据失败!网络错误");
  460. }
  461. });
  462. mui('#scroll').scroll({
  463. indicators: true, //是否显示滚动条
  464. bounce: false //是否启用回弹
  465. });
  466. });
  467. $(document).on('tap', '.my-btn-buy-cancel', function() {
  468. //$(".mui-backdrop").css("opacity", 0).remove(); //移除遮罩层
  469. $(".my-picker").removeClass("active");
  470. setTimeout(function() {
  471. $(".my-picker").remove(); //移除选择颜色列表
  472. }, 500);
  473. });
  474. //确定事件
  475. $(document).on('tap', '.my-btn-buy-know', function() {
  476. //判断是点立即购买还是加入购物车的
  477. var cartidList = ''; //购物项id集合
  478. if($(this).attr("cart") == "cart") {
  479. if(count > 0) {
  480. //$(".mui-backdrop").css("opacity", 0).remove(); //移除遮罩层
  481. $(".my-picker").removeClass("active");
  482. setTimeout(function() {
  483. $(".my-picker").remove(); //移除选择颜色列表
  484. }, 500);
  485. mui.toast("加入购物车成功!");
  486. }else{
  487. mui.toast("请选择数量")
  488. }
  489. } else {
  490. $.each($(".my-picker .mui-numbox"), function(index) {
  491. var th = $(this);
  492. if(th.attr("cartid") != "undefined") {
  493. if(cartidList == '') {
  494. cartidList += th.attr("cartid");
  495. } else {
  496. cartidList += '-' + th.attr("cartid");
  497. }
  498. }
  499. });
  500. if(cartidList != "undefined" && count > 0) {
  501. $(".my-btn-buy-know").removeAttr("disabled"); //激活结算按钮
  502. if(!window.sessionStorage) {
  503. mui.alert("您的浏览器不支持sessionStorage");
  504. } else {
  505. //自定义json数据
  506. var obj = {
  507. text: [cartidList]
  508. };
  509. //json格式化插入 购物项id集合
  510. sessionStorage.setItem('pay_data', JSON.stringify(obj));
  511. location.href = 'clearing.html'; //跳转结算页面
  512. }
  513. } else {
  514. mui.toast("请选择数量")
  515. }
  516. }
  517. });
  518. //产品详情
  519. $(document).on('tap', '.to-product', function() {
  520. var productId = $(this).parents(".product-id").attr("name");
  521. location.href = 'pro-details.html?productId=' + productId;
  522. });
  523. </script>
  524. </body>
  525. </html>