shopping-cart.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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. <script type="text/javascript">
  13. // 屏蔽分享
  14. window.hiddenAllWechatMenu = true;
  15. </script>
  16. <style>
  17. .order_operate{
  18. color: #000; border-radius: 0px;border: 1px solid rgba(0,0,0,.5);
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <!--底部菜单开始-->
  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-liebiao"></span>
  31. <span class="mui-tab-label">列表</span>
  32. </a>
  33. <a class="mui-tab-item mui-active">
  34. <span class="iconfont icon-gouwuche"></span>
  35. <span class="mui-tab-label">购物车</span>
  36. </a>
  37. <a class="mui-tab-item">
  38. <span class="iconfont icon-huiyuan"></span>
  39. <span class="mui-tab-label">会员</span>
  40. </a>
  41. </footer>
  42. <!--底部菜单结束-->
  43. <div class="mui-content">
  44. <div class="gwc_null">
  45. <img width="100px" src="images/cart-null.png">
  46. <h4 style="margin: 10px 0 20px 0;">购物车还是空的</h4>
  47. <a href="javascript:;" class="mui-btn my-btn-danger order_operate go_web_shop" style=" color: #000; border-radius: 0px; border: 1px solid #000; padding: 7px 0px 7px 0px; width: 100px;font-family: 微软雅黑; font-size: 16px;background-color: #fff;margin: 0 auto;">立即选购</a>
  48. </div>
  49. <div class="shopping-box">
  50. <div class="shoping-tt">
  51. <ul class="mui-table-view my-grid-view-no shopping-cart-list">
  52. <!--购物车列表-->
  53. </ul>
  54. </div>
  55. <div class="buy-footer1">
  56. <table class="tb-clearing">
  57. <tr>
  58. <td class="quanxuan">
  59. <input type="checkbox" name="checkbox" class="all_check" /> 全选
  60. </td>
  61. <td class="mui-text-center">合计:<span class="count_price_box">¥<span class="count_price">0.0</span></span>元</td>
  62. <td>
  63. <a id="go-clearing" class="mui-btn mui-pull-right add_gwc1 go-clearing">结算(0)</a>
  64. </td>
  65. </tr>
  66. </table>
  67. </div>
  68. </div>
  69. </div>
  70. <!-- 加载ing begin-->
  71. <div class="loading covers">
  72. <div class="loading-bj"></div>
  73. <p>正在加载...</p>
  74. </div>
  75. <!-- 加载ing end -->
  76. <script src="js/mui.min.js"></script>
  77. <script src="js/jquery-2.1.1.min.js"></script>
  78. <script src="js/main.js"></script>
  79. <script src="js/wechat-utils-1.0.js"></script>
  80. <script>
  81. window.addEventListener('pageshow', function(e) {
  82. // 通过persisted属性判断是否存在 BF Cache
  83. if(e.persisted) {
  84. location.reload();
  85. }
  86. });
  87. var channelType = getParam("channelType"); //渠道类型
  88. var channelId = getParam("channelId"); //渠道id
  89. if(channelType == null || channelId == null ){
  90. channelType = 0;
  91. channelId=0;
  92. }
  93. mui.ready(function() {
  94. $.ajax(base_path + '/wechat/cart/selectCartByOpenId?dates=' + new Date().getTime(), {
  95. data: {
  96. "channelType": channelType,
  97. "channelId": channelId
  98. },
  99. dataType: 'json',
  100. xhrFields: {
  101. withCredentials: true
  102. },
  103. crossDomain: true,
  104. type: 'post',
  105. timeout: 15000,
  106. success: function(dt) {
  107. if(dt.isRedirect) {
  108. location.href = dt.redirectURL;
  109. } else {
  110. if(dt.status) {
  111. console.log(dt);
  112. var table = document.body.querySelector('.shopping-cart-list');
  113. if(dt.data.cartList.length==0){
  114. $(".shopping-box,.buy-footer1").hide();
  115. $(".gwc_null").show();
  116. }else{
  117. mui.each(dt.data.cartList, function(index) {
  118. $("#footer-bar-tab").hide();
  119. var li = document.createElement("li");
  120. li.className = 'mui-table-view-cell mui-media';
  121. var num = this.cartNum;
  122. var proStatus='',disabled='';
  123. if(this.productStatus!=1 || this.colorAllNum<=this.colorSoldNum){
  124. proStatus='<div class="xiajia">已售罄</div>';
  125. disabled='disabled="disabled"';
  126. }
  127. li.innerHTML = '<div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red btn-del" name="' + this.cartColorId + '">删除</a></div> <div class="mui-slider-handle"><input name="checkbox" type="checkbox" class="mui-pull-left mt-mr-che" '+disabled+'/><span class="mui-media-object mui-pull-left wh-100"><img src="' + this.productIntroduceImg + '" /></span><div class="mui-media-body"><div class="wt-space gwc_tit">' + this.productName + '</div><small class="gwc_pp">颜色:' + this.productColor + '</small><div class="price"><span class="price_sp">¥' + (this.productDiscount / 100).toFixed(2) + '</span></div><p class="mui-ellipsis"></p><div class="mui-numbox" data-numbox-min="1" data-numbox-max="99"><button class="mui-btn mui-btn-numbox-minus" type="button" colorid='+this.cartColorId+'>-</button><input class="mui-input-numbox" type="tel" value="' + this.cartNum + '" readonly="readonly" disabled="disabled" cartid="'+this.cartId+'"/><button class="mui-btn mui-btn-numbox-plus" type="button" colorid='+this.cartColorId+'>+</button></div></div>'+proStatus+'</div>';
  128. table.appendChild(li);
  129. });
  130. if($(".shopping-cart-list input[type='checkbox']:not(:disabled)").length>0){//判断购物车列表未下架的产品数量>0
  131. $(".shopping-cart-list input[type='checkbox']:not(:disabled)").prop('checked', true); //选中所有未下架产品
  132. $(".all_check").prop('checked', true);//全选按钮选中
  133. $("#go-clearing").removeClass("add_gwc1").addClass("add_gwc").text('去结算('+$(".shopping-cart-list input[type=checkbox]:not(:disabled):checked").length+')');//点亮结算按钮
  134. }
  135. mui(".mui-numbox").numbox(); //激活加减按钮组合
  136. $(".loading").hide().css("opacity", "0");//隐藏(正在加载...)
  137. calculator();
  138. }
  139. } else {
  140. mui.alert("获取数据失败!");
  141. }
  142. }
  143. },
  144. error: function(xhr, type, errorThrown) {
  145. console.log(xhr);
  146. mui.alert("获取数据失败!网络错误");
  147. }
  148. });
  149. // var str="";
  150. // for (i=0;i<3;i++) {
  151. // str+='<li class="mui-table-view-cell mui-media"><div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red btn-del">删除</a></div> <div class="mui-slider-handle"><input name="checkbox" type="checkbox" class="mui-pull-left mt-mr-che" disabled="disabled"/><span class="mui-media-object mui-pull-left wh-100"><img src="images/pro-bai.png" /></span><div class="mui-media-body"><div class="wt-space gwc_tit">柔性声波牙刷</div><small class="gwc_pp">颜色:极光白</small><div class="price"><span class="price_sp">¥2999.00</span></div><p class="mui-ellipsis"></p><div class="mui-numbox" data-numbox-min="1" data-numbox-max="99"><button class="mui-btn mui-btn-numbox-minus" type="button" disabled="">-</button><input class="mui-input-numbox" type="number" value="1" readonly="readonly"><button class="mui-btn mui-btn-numbox-plus" type="button">+</button></div></div><div class="xiajia">已售罄</div></div></li>';
  152. // str+='<li class="mui-table-view-cell mui-media"><div class="mui-slider-right mui-disabled"><a class="mui-btn mui-btn-red btn-del">删除</a></div> <div class="mui-slider-handle"><input name="checkbox" type="checkbox" class="mui-pull-left mt-mr-che" checked/><span class="mui-media-object mui-pull-left wh-100"><img src="images/pro-bai.png" /></span><div class="mui-media-body"><div class="wt-space gwc_tit">柔性声波牙刷</div><small class="gwc_pp">颜色:极光白</small><div class="price"><span class="price_sp">¥2999.00</span></div><p class="mui-ellipsis"></p><div class="mui-numbox" data-numbox-min="1" data-numbox-max="99"><button class="mui-btn mui-btn-numbox-minus" type="button" disabled="">-</button><input class="mui-input-numbox" type="number" value="1" readonly="readonly"><button class="mui-btn mui-btn-numbox-plus" type="button">+</button></div></div></div></li>';
  153. // }
  154. // document.querySelector('.shopping-cart-list').innerHTML=str;
  155. //
  156. // if($(".mui-table-view input[type='checkbox']:checked").length>0){
  157. // $("#go-clearing").removeClass('add_gwc1').addClass('add_gwc').text("结算("+$(".mui-table-view input[type='checkbox']:checked").length+")");
  158. // calculator();
  159. // }else{
  160. //
  161. // }
  162. // mui(".mui-numbox").numbox();
  163. // $(".loading").hide().css("opacity", "0");//隐藏(正在加载...)
  164. });
  165. //拖拽后显示操作图标,点击删除;
  166. mui('body').on('tap', '.btn-del', function(event) {
  167. var btnArray = ['取消', '确定'];
  168. var elem = this;
  169. var li = elem.parentNode.parentNode;
  170. mui.confirm('您确定要删除吗?', '提示', btnArray, function(e) {
  171. if(e.index == 1) {
  172. $.ajax(base_path + '/wechat/cart/deleteCartByProductId?dates=' + new Date().getTime(), {
  173. data: {
  174. "colorId": elem.getAttribute("name")
  175. },
  176. dataType: 'json',
  177. xhrFields: {
  178. withCredentials: true
  179. },
  180. crossDomain: true,
  181. type: 'get',
  182. timeout: 15000,
  183. success: function(dt) {
  184. if(dt.isRedirect) {
  185. location.href = dt.redirectURL;
  186. } else {
  187. if(dt.status == true) {
  188. li.parentNode.removeChild(li);
  189. if($(".shopping-cart-list>li").length < 1) {
  190. $(".shopping-box,.buy-footer1").hide();
  191. $(".gwc_null,#footer-bar-tab").show();
  192. }
  193. calculator();
  194. mui.toast("删除成功!");
  195. } else {
  196. mui.toast("删除失败!");
  197. }
  198. }
  199. },
  200. error: function(xhr, type, errorThrown) {
  201. console.log(xhr);
  202. }
  203. });
  204. } else {
  205. mui.toast("您取消了删除!");
  206. setTimeout(function() {
  207. mui.swipeoutClose(li);
  208. }, 0);
  209. }
  210. });
  211. });
  212. //购物车数量加
  213. $(document).on('tap', '.mui-btn-numbox-plus', function() {
  214. var th = $(this);
  215. var val = mui(th.parent()[0]).numbox().getValue(); //获取当前产品数量
  216. var parameter = {}; //ajax参数json集合
  217. if(typeof(th.attr("colorid")) != "undefined") {
  218. parameter["colorId"] = th.attr("colorid"); //颜色id
  219. parameter["cartNum"] = 1; //需要加的产品数量,每次都是1
  220. $.ajax(base_path + '/wechat/cart/addProductToCart?dates=' + new Date().getTime(), {
  221. data: parameter,
  222. dataType: 'json',
  223. xhrFields: {
  224. withCredentials: true
  225. },
  226. crossDomain: true,
  227. type: 'get',
  228. timeout: 15000,
  229. success: function(dt) {
  230. if(dt.isRedirect) {
  231. location.href = dt.redirectURL;
  232. } else {
  233. if(dt.status) {
  234. th.parent().attr("cartid", dt.data);
  235. console.log("增加数量成功!");
  236. } else {
  237. mui.alert("增加数量失败!");
  238. }
  239. }
  240. },
  241. error: function(xhr, type, errorThrown) {
  242. console.log(xhr);
  243. mui.alert("增加数量失败!网络错误");
  244. }
  245. });
  246. } else {
  247. mui.alert("没有获取到产品颜色id");
  248. }
  249. });
  250. //购物车数量减
  251. $(document).on('tap', '.mui-btn-numbox-minus', function() {
  252. var th = $(this);
  253. var val = mui(th.parent()[0]).numbox().getValue(); //获取当前产品数量
  254. var parameter = {}; //ajax参数json集合
  255. if(typeof(th.attr("colorid")) != "undefined") {
  256. parameter["colorId"] = th.attr("colorid"); //产品颜色id
  257. parameter["cartNum"] = 1; //需要减的产品数量,每次都是1
  258. $.ajax(base_path + '/wechat/cart/deleteCart?dates=' + new Date().getTime(), {
  259. data: parameter,
  260. dataType: 'json',
  261. xhrFields: {
  262. withCredentials: true
  263. },
  264. crossDomain: true,
  265. type: 'get', //减少数量后台限制用get
  266. timeout: 15000,
  267. success: function(dt) {
  268. if(dt.isRedirect) {
  269. location.href = dt.redirectURL;
  270. } else {
  271. if(dt.status) {
  272. console.log("减少数量数量成功!");
  273. } else {
  274. mui.alert("减少数量数量失败!");
  275. }
  276. }
  277. },
  278. error: function(xhr, type, errorThrown) {
  279. console.log(xhr);
  280. mui.alert("减少数量失败!网络错误");
  281. }
  282. });
  283. } else {
  284. mui.alert("没有获取到产品颜色id");
  285. }
  286. });
  287. //全选/取消全选
  288. $(document).on('click', 'input[type="checkbox"]', function(e) {
  289. if($(this).hasClass("all_check")) {
  290. if($(this).prop("checked") == true) {
  291. console.log("全选")
  292. if($(".shopping-cart-list input[type='checkbox']:not(:disabled)").length>0){
  293. $(".shopping-cart-list input[type='checkbox']:not(:disabled)").prop('checked', true);
  294. $("#go-clearing").removeClass('add_gwc1').addClass('add_gwc').text("去结算(" + $(".shopping-cart-list input[type='checkbox']:checked").length + ")");
  295. }
  296. } else {
  297. console.log("取消全选")
  298. $("input[type='checkbox']").prop('checked', false);
  299. $("#go-clearing").removeClass('add_gwc').addClass('add_gwc1').text("去结算(" + $(".shopping-cart-list input[type='checkbox']:checked").length + ")");
  300. }
  301. } else {
  302. $(".all_check").prop('checked', false);
  303. if($(".shopping-cart-list input[type='checkbox']:checked").length > 0) {
  304. $("#go-clearing").removeClass('add_gwc1').addClass('add_gwc').text("去结算(" + $(".shopping-cart-list input[type='checkbox']:checked").length + ")");
  305. if(($("input[type='checkbox']:checked").length + 1) == $("input[type='checkbox']").length) {
  306. $("input[type='checkbox']").prop('checked', true);
  307. }
  308. } else {
  309. $("#go-clearing").removeClass('add_gwc').addClass('add_gwc1').text("去结算(" + $(".shopping-cart-list input[type='checkbox']:checked").length + ")");
  310. }
  311. }
  312. calculator();
  313. });
  314. //跳转产品列表页面
  315. mui('body').on('tap', '.go_web_shop', function() {
  316. mui.openWindow({
  317. url: 'pro-list.html'
  318. });
  319. });
  320. //结算事件
  321. mui('body').on('tap', '.go-clearing', function() {
  322. if($(".shopping-cart-list input[type='checkbox']:checked").length > 0) {
  323. var cartidList = ''; //购物项id集合
  324. $.each($(".shopping-cart-list input[type='checkbox']:not(:disabled):checked"), function(index) {
  325. var th = $(this).parent().find('.mui-input-numbox');
  326. if(typeof(th.attr("cartid")) != "undefined") {
  327. var a = '';
  328. if(index != 0) {
  329. a = '-' + th.attr("cartid"); //组装购物项id
  330. } else {
  331. a = th.attr("cartid");
  332. }
  333. cartidList += a;
  334. }
  335. });
  336. if(!window.sessionStorage) {
  337. mui.alert("您的浏览器不支持sessionStorage");
  338. } else {
  339. //自定义json数据
  340. var obj = {
  341. text: [cartidList]
  342. };
  343. //json格式化插入 购物项id集合
  344. sessionStorage.setItem('pay_data', JSON.stringify(obj));
  345. if(channelType > 0 && channelType > 0){
  346. location.href = 'channel-clearing.html?channelType='+channelType+'&channelId='+channelId; //跳转结算页面
  347. }else{
  348. location.href = 'clearing.html'; //跳转结算页面
  349. }
  350. }
  351. } else {
  352. mui.alert('您还没有选中商品', '消息提醒', function() {
  353. console.log("您关闭了警告框");
  354. });
  355. }
  356. });
  357. //监听加减框组合值
  358. mui('body').on('change', '.mui-input-numbox', function() {
  359. calculator();
  360. });
  361. //重新计算
  362. function calculator() {
  363. var count = 0;
  364. var num = 0;
  365. $(".mui-table-view li").each(function() {
  366. if($(this).find("input[type='checkbox']:not(:disabled)").prop('checked') == true) {
  367. num = parseFloat($(this).find(".price_sp").text().replace(/¥/g, "") * $(this).find(".mui-input-numbox").val()).toFixed(2);
  368. count = accAdd(count, num);
  369. }
  370. });
  371. $(".count_price").text(accAdd(count, 0).toFixed(2));
  372. $("#go-clearing").text('去结算('+$(".shopping-cart-list input[type=checkbox]:not(:disabled):checked").length+')');
  373. if($(".shopping-cart-list input[type='checkbox']:not(:disabled):checked").length<1){
  374. $("#go-clearing").removeClass("add_gwc").addClass("add_gwc1");
  375. }else{
  376. $("#go-clearing").removeClass("add_gwc1").addClass("add_gwc");
  377. }
  378. }
  379. </script>
  380. </body>
  381. </html>