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