pro-list.html 20 KB

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