pro-details.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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/icons-extra.css" />
  11. <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  12. <link rel="stylesheet" type="text/css" href="css/main.css" />
  13. <style>
  14. .return {position: fixed;right: 10px;bottom: 140px;background: rgba(0, 0, 0, .1);padding: 12px;border-radius: 50%;height: 50px;width: 50px;text-align: center;opacity: .9;color: #333;display: none;}
  15. .my-picker {max-height: 100%;background-color: rgba(0, 0, 0, .5);}
  16. .my-btn-buy-know {width: 50%;border-radius: 0;bottom: 0;height: 50px;border: 1px solid #727171;position: fixed;right: 0;}
  17. .my-btn-buy-cancel {width: 50%;border-radius: 0;bottom: 0;height: 50px;border: 0;border-top: 1px solid #ccc;position: fixed;left: 0;}
  18. </style>
  19. </head>
  20. <body>
  21. <footer class="mui-bar mui-bar-tab">
  22. <ul class="mui-table-view mui-table-view-striped mui-table-view-condensed my-grid-view-no">
  23. <li class="mui-table-view-cell">
  24. <div class="mui-table">
  25. <div class="mui-table-cell mui-col-xs-4 table-middle go-index"><img style="width: 60%;vertical-align: middle;" src="images/logo.png" /></div>
  26. <div class="mui-table-cell mui-col-xs-4 table-middle add-gouwuche" style="background-color: #ccc;color: #fff;font-size: 18px;">加入购物车</div>
  27. <div class="mui-table-cell mui-col-xs-4 table-middle div-btn-buy-know">立即购买</div>
  28. </div>
  29. </li>
  30. </ul>
  31. </footer>
  32. <div class="mui-content">
  33. <div class="banner-box-pro" style="display: none;">
  34. <!--<div id="slider" class="mui-slider">
  35. <div class="mui-slider-group mui-slider-loop">-->
  36. <!-- 额外增加的一个节点(循环轮播:第一个节点是最后一张轮播) -->
  37. <!--<div class="mui-slider-item mui-slider-item-duplicate">
  38. <a href="#">
  39. <img src="images/banner-3.jpg">
  40. </a>
  41. </div>-->
  42. <!-- 第一张 -->
  43. <!--<div class="mui-slider-item">
  44. <a href="#">
  45. <img src="images/banner-1.jpg">
  46. </a>
  47. </div>-->
  48. <!-- 第二张 -->
  49. <!--<div class="mui-slider-item">
  50. <a href="#">
  51. <img src="images/banner-2.jpg">
  52. </a>
  53. </div>-->
  54. <!-- 第三张 -->
  55. <!--<div class="mui-slider-item">
  56. <a href="#">
  57. <img src="images/banner-3.jpg">
  58. </a>
  59. </div>-->
  60. <!-- 额外增加的一个节点(循环轮播:最后一个节点是第一张轮播) -->
  61. <!--<div class="mui-slider-item mui-slider-item-duplicate">
  62. <a href="#">
  63. <img src="images/banner-1.jpg">
  64. </a>
  65. </div>
  66. </div>
  67. <div class="mui-slider-indicator">
  68. <div class="mui-indicator mui-active"></div>
  69. <div class="mui-indicator"></div>
  70. <div class="mui-indicator"></div>
  71. </div>
  72. </div>-->
  73. </div>
  74. <ul class="mui-table-view mui-grid-view my-view-no" style="padding-bottom: 0;">
  75. <!--<li class="mui-table-view-cell mui-media mui-col-xs-12" style="padding-right: 2px;">
  76. <a href="#">
  77. <div class="index-pro-tit">[精选] Aiberle美国智能净饮水一体机</div>
  78. <p class="mui-text-left">4级ro净化、10s加热、3s出水<span style="float: right;color: #ff3b3b;">¥2999.00</span></p>
  79. </a>
  80. </li>
  81. <li>
  82. <div class="index-title">
  83. <p><span class="iconfont icon-liwu"></span>美国aiberle咖啡杯、美国aiberle加湿器</p>
  84. </div>
  85. </li>
  86. <li class="mui-table-view-cell mui-media mui-col-xs-12">
  87. <a href="#"><img class="mui-media-object" src="images/details-1.jpg">
  88. </a>
  89. </li>-->
  90. </ul>
  91. </div>
  92. <div class="fixed-cart">
  93. <span class="iconfont icon-gouwuche"></span>
  94. <span class="mui-badge my-badge-danger">0</span>
  95. </div>
  96. <div class="return">
  97. <span onClick="gotoTop(0.1,10);return false;" class="mui-icon-extra mui-icon-extra-top"></span>
  98. </div>
  99. <!-- 加载ing -->
  100. <div class="loading covers">
  101. <div class="loading-bj"></div>
  102. <p>加载中...</p>
  103. </div>
  104. <!-- 加载ing END -->
  105. <script src="js/mui.min.js"></script>
  106. <script src="js/jquery-2.1.1.min.js"></script>
  107. <script src="js/main.js"></script>
  108. <script src="js/wechat-utils-1.0.js"></script>
  109. <script>
  110. var productId = getParam("productId"),
  111. productName = '',
  112. productRemark = '',
  113. productIntroduceImg = '';
  114. console.log(productId);
  115. mui.ready(function() {
  116. var slider = mui("#slider");
  117. $.ajax(base_path + '/wechat/product/getProductByProductId?dates=' + new Date().getTime(), {
  118. data: {
  119. "productId": productId
  120. },
  121. dataType: 'json',
  122. xhrFields: {
  123. withCredentials: true
  124. },
  125. crossDomain: true,
  126. type: 'post',
  127. timeout: 15000,
  128. success: function(dt) {
  129. //判断一下
  130. if(dt.isRedirect) {
  131. location.href = dt.redirectURL;
  132. } else {
  133. console.log(dt.data)
  134. if(dt.status) {
  135. var bannerstr = "",
  136. dian = "";
  137. console.log(dt.data.product)
  138. var banner_data = dt.data.product.pictureList;
  139. mui(banner_data).each(function(index) {
  140. if(index == 0) {
  141. bannerstr += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="' + banner_data[banner_data.length - 1].pictureUrl + '"><img src="' + (banner_data[banner_data.length - 1].pictureUrl) + '"></a></div><div class="mui-slider-item mui-active"><a href="#"><img src="' + (this.pictureUrl) + '"></a></div>';
  142. dian += '<div class="mui-indicator mui-active"></div>'
  143. } else {
  144. bannerstr += '<div class="mui-slider-item"><a href="#"><img src="' + (this.pictureUrl) + '"></a></div>';
  145. dian += '<div class="mui-indicator"></div>'
  146. }
  147. if(index == (banner_data.length - 1) || (banner_data.length - 1) == 0) {
  148. bannerstr += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="#"><img src="' + (banner_data[0].pictureUrl) + '"></a></div>'
  149. }
  150. });
  151. dc('mui-slider-loop').innerHTML = bannerstr;
  152. dc('my-slider-indicator').innerHTML = dian;
  153. $("<div id='slider' class='mui-slider'><div class='mui-slider-group mui-slider-loop' id='mui-slider-loop'>" + bannerstr + "</div><div id='my-slider-indicator' class='mui-slider-indicator my-slider-indicator'>" + dian + "</div></div>").insertBefore(".banner-box-pro");
  154. //初始化banner自动轮播(interval:0为不自动轮播)单位ms
  155. var banner = mui('#slider');
  156. banner.slider({
  157. interval: 5000
  158. });
  159. var productInfo = dt.data.product;
  160. var table = document.body.querySelector(".my-view-no");
  161. var li = document.createElement('li');
  162. li.className = 'mui-table-view-cell mui-media mui-col-xs-12';
  163. var zen = '';
  164. if(productInfo.productColorList.length > 0) {
  165. $.each(productInfo.productColorList[0].salesUserGiftList, function() {
  166. zen += this.giftName + "、"
  167. });
  168. }
  169. if(zen != '') {
  170. zen = '<div class="details-title"><p><span class="iconfont icon-liwu"></span>' + zen.substring(0, zen.length - 1) + '</p></div>';
  171. }
  172. productName = productInfo.productName;
  173. productRemark = productInfo.productColorDes;
  174. productIntroduceImg = productInfo.productParameterImg;
  175. li.innerHTML = '<a><div class="index-pro-tit">' + productInfo.productName + '</div>' +
  176. '<p class="mui-text-left">' + productInfo.productColorDes + '<span style="float: right;color: #ff3b3b;">¥' + (productInfo.productDiscount / 100).toFixed(2) + '</span></p></a>' +
  177. zen + '</br>' +
  178. productInfo.imagetextContext +
  179. '';
  180. table.appendChild(li);
  181. getCartNumber(); //获取购物车数量
  182. fenxiang();
  183. $(".loading").hide().css("opacity", "0");
  184. } else {
  185. mui.alert("获取数据失败!");
  186. }
  187. }
  188. },
  189. error: function(xhr, type, errorThrown) {
  190. console.log(xhr);
  191. mui.alert("获取数据失败!网络错误");
  192. }
  193. });
  194. });
  195. $(document).on('tap', '.my-btn-buy-cancel', function() {
  196. $(".my-picker").removeClass("active");
  197. setTimeout(function() {
  198. $(".my-picker").remove(); //移除选择颜色列表
  199. }, 500);
  200. });
  201. //callback为用户点击蒙版时自动执行的回调;
  202. // var mask = mui.createMask(function() {
  203. // $(".my-picker").remove();//移除颜色列表
  204. // });
  205. var count = 0; //统计所有产品加减,数量默认0,当count<1的时候设置(结算)按钮失效
  206. //购物车数量加
  207. $(document).on('tap', '.mui-btn-numbox-plus', function() {
  208. ++count; //产品总数量
  209. var th = $(this);
  210. var parameter = {}; //ajax参数json集合
  211. if(typeof(th.attr("productid")) != "undefined") {
  212. parameter["productId"] = th.attr("productid"); //产品id
  213. if(typeof(th.attr("colorid")) != "undefined") {
  214. parameter["productColorId"] = th.attr("colorid"); //颜色id
  215. parameter["cartNum"] = 1; //需要加的产品数量,每次都是1
  216. $.ajax(base_path + '/wechat/cart/addProductToCart?dates=' + new Date().getTime(), {
  217. data: parameter,
  218. dataType: 'json',
  219. xhrFields: {
  220. withCredentials: true
  221. },
  222. crossDomain: true,
  223. type: 'post',
  224. timeout: 15000,
  225. success: function(dt) {
  226. if(dt.isRedirect) {
  227. location.href = dt.redirectURL;
  228. } else {
  229. if(dt.status) {
  230. th.parent().attr("cartid", dt.data);
  231. getCartNumber()
  232. console.log("增加数量成功!");
  233. } else {
  234. mui.alert("增加数量失败!");
  235. }
  236. }
  237. },
  238. error: function(xhr, type, errorThrown) {
  239. console.log(xhr);
  240. mui.alert("增加数量失败!网络错误");
  241. }
  242. });
  243. } else {
  244. mui.alert("没有获取到产品颜色id");
  245. }
  246. } else {
  247. mui.alert("没有获取到产品id");
  248. }
  249. });
  250. //购物车数量减
  251. $(document).on('tap', '.mui-btn-numbox-minus', function() {
  252. --count; //产品总数量
  253. var th = $(this);
  254. var val = mui(th.parent()[0]).numbox().getValue(); //获取当前产品数量
  255. if(val == 0) {
  256. th.parent().removeAttr("cartid");
  257. }
  258. var parameter = {}; //ajax参数json集合
  259. if(typeof(th.attr("colorid")) != "undefined") {
  260. parameter["productColorId"] = th.attr("colorid"); //产品颜色id
  261. parameter["cartNum"] = 1; //需要减的产品数量,每次都是1
  262. $.ajax(base_path + '/wechat/cart/deleteCart?dates=' + new Date().getTime(), {
  263. data: parameter,
  264. dataType: 'json',
  265. xhrFields: {
  266. withCredentials: true
  267. },
  268. crossDomain: true,
  269. type: 'get', //减少数量后台限制用get
  270. timeout: 15000,
  271. success: function(dt) {
  272. if(dt.isRedirect) {
  273. location.href = dt.redirectURL;
  274. } else {
  275. if(dt.status) {
  276. console.log("减少数量数量成功!");
  277. getCartNumber()
  278. } else {
  279. mui.alert("减少数量数量失败!");
  280. }
  281. }
  282. },
  283. error: function(xhr, type, errorThrown) {
  284. console.log(xhr);
  285. mui.alert("减少数量失败!网络错误");
  286. }
  287. });
  288. } else {
  289. mui.alert("没有获取到产品颜色id");
  290. }
  291. });
  292. ///立即购买-购物车按钮
  293. $(document).on('tap', '.add-gouwuche,.div-btn-buy-know', function() {
  294. var th = $(this);
  295. count = 0;
  296. //mask.show(); //显示遮罩层
  297. //在body尾部增加-产品颜色列表父级ul
  298. $("body").append('<div id="scroll" class="mui-scroll-wrapper my-picker"><div class="mui-scroll" style="top: 0;background-color: #fff;min-height: 100%;"><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>');
  299. $.ajax(base_path + '/wechat/product/selectProductColor?dates=' + new Date().getTime(), {
  300. data: {
  301. "productId": productId //productId产品id
  302. },
  303. dataType: 'json',
  304. xhrFields: {
  305. withCredentials: true
  306. },
  307. crossDomain: true,
  308. type: 'post',
  309. timeout: 15000,
  310. success: function(dt) {
  311. if(dt.isRedirect) {
  312. location.href = dt.redirectURL;
  313. } else {
  314. if(dt.status) {
  315. console.log(dt)
  316. var data = dt.data.productColorList;
  317. var table = document.body.querySelector('.my-picker .mui-table-view'); //产品颜色列表父级ul
  318. table.innerHTML = '';
  319. //循环遍历产品颜色数组
  320. mui(data).each(function(index) {
  321. var li = document.createElement('li'); //创建li标签
  322. li.className = 'my-table-view-cell'; //給li标签设置className
  323. if(typeof(this.cartNum) != "undefined") {
  324. count += parseInt(this.cartNum);
  325. } else {
  326. this.cartNum = 0;
  327. }
  328. 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>';
  329. table.appendChild(li); //将li标签加入到-产品颜色列表父级ul
  330. });
  331. $(".my-picker").addClass("active"); //显示产品颜色加减数量列表
  332. console.log(count)
  333. // if(count > 0) {
  334. $(".my-btn-buy-know").removeAttr("disabled"); //激活结算按钮
  335. // }
  336. if(th.hasClass("add-gouwuche")) {
  337. $(".my-btn-buy-know").attr("cart", "cart");
  338. }
  339. mui(".mui-numbox").numbox(); //激活加减按钮组合
  340. } else {
  341. mui.alert("获取数据失败!");
  342. }
  343. }
  344. },
  345. error: function(xhr, type, errorThrown) {
  346. console.log(xhr);
  347. mui.alert("获取数据失败!网络错误");
  348. }
  349. });
  350. mui('#scroll').scroll({
  351. indicators: true, //是否显示滚动条
  352. bounce: false //是否启用回弹
  353. });
  354. });
  355. //确定事件
  356. $(document).on('tap', '.my-btn-buy-know', function() {
  357. //判断是点立即购买还是加入购物车的
  358. var cartidList = ''; //购物项id集合
  359. if($(this).attr("cart") == "cart") {
  360. if(count > 0) {
  361. //$(".mui-backdrop").css("opacity", 0).remove(); //移除遮罩层
  362. $(".my-picker").removeClass("active");
  363. setTimeout(function() {
  364. $(".my-picker").remove(); //移除选择颜色列表
  365. }, 500);
  366. mui.toast("加入购物车成功!");
  367. } else {
  368. mui.toast("请选择数量")
  369. }
  370. } else {
  371. $.each($(".my-picker .mui-numbox"), function(index) {
  372. var th = $(this);
  373. if(th.attr("cartid") != "undefined") {
  374. if(cartidList == '') {
  375. cartidList += th.attr("cartid");
  376. } else {
  377. cartidList += '-' + th.attr("cartid");
  378. }
  379. }
  380. });
  381. if(cartidList != "undefined" && count > 0) {
  382. $(".my-btn-buy-know").removeAttr("disabled"); //激活结算按钮
  383. if(!window.sessionStorage) {
  384. mui.alert("您的浏览器不支持sessionStorage");
  385. } else {
  386. //自定义json数据
  387. var obj = {
  388. text: [cartidList]
  389. };
  390. //json格式化插入 购物项id集合
  391. sessionStorage.setItem('pay_data', JSON.stringify(obj));
  392. location.href = 'clearing.html'; //跳转结算页面
  393. }
  394. } else {
  395. mui.toast("请选择数量")
  396. }
  397. }
  398. });
  399. //跳转首页
  400. $(document).on('tap', '.go-index', function() {
  401. location.href = 'index.html';
  402. });
  403. //跳转购物车
  404. $(document).on('tap', '.fixed-cart', function() {
  405. location.href = 'shopping-cart.html';
  406. });
  407. //获取购物车数量
  408. function getCartNumber() {
  409. $.ajax(base_path + '/wechat/cart/getCartNumByCartOpenId?dates=' + new Date().getTime(), {
  410. data: {},
  411. dataType: 'json',
  412. xhrFields: {
  413. withCredentials: true
  414. },
  415. crossDomain: true,
  416. type: 'get',
  417. timeout: 15000,
  418. success: function(dt) {
  419. if(dt.isRedirect) {
  420. location.href = dt.redirectURL;
  421. } else {
  422. if(dt.status) {
  423. if(dt.data > 0) {
  424. $(".fixed-cart .my-badge-danger").text(dt.data).show();
  425. } else {
  426. $(".fixed-cart .my-badge-danger").text(dt.data).hide();
  427. }
  428. } else {
  429. mui.alert("获取购物车数量失败!");
  430. }
  431. }
  432. },
  433. error: function(xhr, type, errorThrown) {
  434. console.log(xhr);
  435. mui.alert("获取购物车数量失败!网络错误");
  436. }
  437. });
  438. }
  439. //分享
  440. function fenxiang() {
  441. var src = location.href;
  442. src = "//s.iamberry.com/aiberle/wechat/pro-details.html?productId=" + productId;
  443. window.wxFriend = {
  444. "appId": "",
  445. "imgUrl": productIntroduceImg,
  446. "link": src,
  447. "desc": productRemark,
  448. "title": 'Aiberle | ' + productName,
  449. "netError": "您的网络异常,请刷新重试!如多次刷新无效,请向我们反应 ~",
  450. "shareTimeSuccess": "分享成功",
  451. "shareTimeCancel": "已取消分享",
  452. "shareAppSuccess": "分享成功!",
  453. "shareAppCancel": "已取消分享"
  454. };
  455. getConfig();
  456. }
  457. //返回顶部方法
  458. function gotoTop(acceleration, stime) {
  459. acceleration = acceleration || 0.1;
  460. stime = stime || 10;
  461. var x1 = 0,
  462. y1 = 0,
  463. x2 = 0,
  464. y2 = 0,
  465. x3 = 0,
  466. y3 = 0;
  467. if(document.documentElement) {
  468. x1 = document.documentElement.scrollLeft || 0;
  469. y1 = document.documentElement.scrollTop || 0
  470. }
  471. if(document.body) {
  472. x2 = document.body.scrollLeft || 0;
  473. y2 = document.body.scrollTop || 0
  474. }
  475. var x3 = window.scrollX || 0;
  476. var y3 = window.scrollY || 0;
  477. var x = Math.max(x1, Math.max(x2, x3));
  478. var y = Math.max(y1, Math.max(y2, y3));
  479. var speeding = 1 + acceleration;
  480. window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
  481. if(x > 0 || y > 0) {
  482. var run = "gotoTop(" + acceleration + ", " + stime + ")";
  483. window.setTimeout(run, stime)
  484. }
  485. };
  486. //绑定滚动条事件
  487. $(window).on("scroll", function() {
  488. //向下滚动距离大于180像素显示返回顶部,否则隐藏
  489. if($(window).scrollTop() > 180) {
  490. $(".return").show();
  491. } else {
  492. $(".return").hide();
  493. }
  494. });
  495. </script>
  496. </body>
  497. </html>