pro-list.html 20 KB

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