pro-details.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 + '</p></a>' +
  177. '<p class="mui-text-left"><span style="color: #ff3b3b;font-size: 15px;">¥' + (productInfo.productDiscount / 100).toFixed(2) + '</span> <span style="float: right;">' + productInfo.productSalesnum + '已售</span></p></a>' +
  178. zen + '</br>' +
  179. productInfo.imagetextContext +
  180. '';
  181. table.appendChild(li);
  182. getCartNumber(); //获取购物车数量
  183. fenxiang();
  184. $(".loading").hide().css("opacity", "0");
  185. } else {
  186. mui.alert("获取数据失败!");
  187. }
  188. }
  189. },
  190. error: function(xhr, type, errorThrown) {
  191. console.log(xhr);
  192. mui.alert("获取数据失败!网络错误");
  193. }
  194. });
  195. });
  196. $(document).on('tap', '.my-btn-buy-cancel', function() {
  197. $(".my-picker").removeClass("active");
  198. setTimeout(function() {
  199. $(".my-picker").remove(); //移除选择颜色列表
  200. }, 500);
  201. });
  202. //callback为用户点击蒙版时自动执行的回调;
  203. // var mask = mui.createMask(function() {
  204. // $(".my-picker").remove();//移除颜色列表
  205. // });
  206. var count = 0; //统计所有产品加减,数量默认0,当count<1的时候设置(结算)按钮失效
  207. //购物车数量加
  208. $(document).on('tap', '.mui-btn-numbox-plus', function() {
  209. ++count; //产品总数量
  210. var th = $(this);
  211. var parameter = {}; //ajax参数json集合
  212. if(typeof(th.attr("productid")) != "undefined") {
  213. parameter["productId"] = th.attr("productid"); //产品id
  214. if(typeof(th.attr("colorid")) != "undefined") {
  215. parameter["productColorId"] = th.attr("colorid"); //颜色id
  216. parameter["cartNum"] = 1; //需要加的产品数量,每次都是1
  217. $.ajax(base_path + '/wechat/cart/addProductToCart?dates=' + new Date().getTime(), {
  218. data: parameter,
  219. dataType: 'json',
  220. xhrFields: {
  221. withCredentials: true
  222. },
  223. crossDomain: true,
  224. type: 'post',
  225. timeout: 15000,
  226. success: function(dt) {
  227. if(dt.isRedirect) {
  228. location.href = dt.redirectURL;
  229. } else {
  230. if(dt.status) {
  231. th.parent().attr("cartid", dt.data);
  232. getCartNumber()
  233. console.log("增加数量成功!");
  234. } else {
  235. mui.alert("增加数量失败!");
  236. }
  237. }
  238. },
  239. error: function(xhr, type, errorThrown) {
  240. console.log(xhr);
  241. mui.alert("增加数量失败!网络错误");
  242. }
  243. });
  244. } else {
  245. mui.alert("没有获取到产品颜色id");
  246. }
  247. } else {
  248. mui.alert("没有获取到产品id");
  249. }
  250. });
  251. //购物车数量减
  252. $(document).on('tap', '.mui-btn-numbox-minus', function() {
  253. --count; //产品总数量
  254. var th = $(this);
  255. var val = mui(th.parent()[0]).numbox().getValue(); //获取当前产品数量
  256. if(val == 0) {
  257. th.parent().removeAttr("cartid");
  258. }
  259. var parameter = {}; //ajax参数json集合
  260. if(typeof(th.attr("colorid")) != "undefined") {
  261. parameter["productColorId"] = th.attr("colorid"); //产品颜色id
  262. parameter["cartNum"] = 1; //需要减的产品数量,每次都是1
  263. $.ajax(base_path + '/wechat/cart/deleteCart?dates=' + new Date().getTime(), {
  264. data: parameter,
  265. dataType: 'json',
  266. xhrFields: {
  267. withCredentials: true
  268. },
  269. crossDomain: true,
  270. type: 'get', //减少数量后台限制用get
  271. timeout: 15000,
  272. success: function(dt) {
  273. if(dt.isRedirect) {
  274. location.href = dt.redirectURL;
  275. } else {
  276. if(dt.status) {
  277. console.log("减少数量数量成功!");
  278. getCartNumber()
  279. } else {
  280. mui.alert("减少数量数量失败!");
  281. }
  282. }
  283. },
  284. error: function(xhr, type, errorThrown) {
  285. console.log(xhr);
  286. mui.alert("减少数量失败!网络错误");
  287. }
  288. });
  289. } else {
  290. mui.alert("没有获取到产品颜色id");
  291. }
  292. });
  293. ///立即购买-购物车按钮
  294. $(document).on('tap', '.add-gouwuche,.div-btn-buy-know', function() {
  295. var th = $(this);
  296. count = 0;
  297. //mask.show(); //显示遮罩层
  298. //在body尾部增加-产品颜色列表父级ul
  299. $("body").append('<div id="scroll" class="mui-scroll-wrapper my-picker"><div class="mui-scroll" style="top: 0;background-color: #fff;min-height: 100%;"><br/><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>');
  300. $.ajax(base_path + '/wechat/product/selectProductColor?dates=' + new Date().getTime(), {
  301. data: {
  302. "productId": productId //productId产品id
  303. },
  304. dataType: 'json',
  305. xhrFields: {
  306. withCredentials: true
  307. },
  308. crossDomain: true,
  309. type: 'post',
  310. timeout: 15000,
  311. success: function(dt) {
  312. if(dt.isRedirect) {
  313. location.href = dt.redirectURL;
  314. } else {
  315. if(dt.status) {
  316. console.log(dt)
  317. var data = dt.data.productColorList;
  318. var table = document.body.querySelector('.my-picker .mui-table-view'); //产品颜色列表父级ul
  319. table.innerHTML = '';
  320. //循环遍历产品颜色数组
  321. mui(data).each(function(index) {
  322. var li = document.createElement('li'); //创建li标签
  323. li.className = 'my-table-view-cell'; //給li标签设置className
  324. if(typeof(this.cartNum) != "undefined") {
  325. count += parseInt(this.cartNum);
  326. } else {
  327. this.cartNum = 0;
  328. }
  329. 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>';
  330. table.appendChild(li); //将li标签加入到-产品颜色列表父级ul
  331. });
  332. $(".my-picker").addClass("active"); //显示产品颜色加减数量列表
  333. console.log(count)
  334. // if(count > 0) {
  335. $(".my-btn-buy-know").removeAttr("disabled"); //激活结算按钮
  336. // }
  337. if(th.hasClass("add-gouwuche")) {
  338. $(".my-btn-buy-know").attr("cart", "cart");
  339. }
  340. mui(".mui-numbox").numbox(); //激活加减按钮组合
  341. } else {
  342. mui.alert("获取数据失败!");
  343. }
  344. }
  345. },
  346. error: function(xhr, type, errorThrown) {
  347. console.log(xhr);
  348. mui.alert("获取数据失败!网络错误");
  349. }
  350. });
  351. mui('#scroll').scroll({
  352. indicators: true, //是否显示滚动条
  353. bounce: false //是否启用回弹
  354. });
  355. });
  356. //确定事件
  357. $(document).on('tap', '.my-btn-buy-know', function() {
  358. //判断是点立即购买还是加入购物车的
  359. var cartidList = ''; //购物项id集合
  360. if($(this).attr("cart") == "cart") {
  361. if(count > 0) {
  362. //$(".mui-backdrop").css("opacity", 0).remove(); //移除遮罩层
  363. $(".my-picker").removeClass("active");
  364. setTimeout(function() {
  365. $(".my-picker").remove(); //移除选择颜色列表
  366. }, 500);
  367. mui.toast("加入购物车成功!");
  368. } else {
  369. mui.toast("请选择数量")
  370. }
  371. } else {
  372. $.each($(".my-picker .mui-numbox"), function(index) {
  373. var th = $(this);
  374. if(th.attr("cartid") != "undefined") {
  375. if(cartidList == '') {
  376. cartidList += th.attr("cartid");
  377. } else {
  378. cartidList += '-' + th.attr("cartid");
  379. }
  380. }
  381. });
  382. if(cartidList != "undefined" && count > 0) {
  383. $(".my-btn-buy-know").removeAttr("disabled"); //激活结算按钮
  384. if(!window.sessionStorage) {
  385. mui.alert("您的浏览器不支持sessionStorage");
  386. } else {
  387. //自定义json数据
  388. var obj = {
  389. text: [cartidList]
  390. };
  391. //json格式化插入 购物项id集合
  392. sessionStorage.setItem('pay_data', JSON.stringify(obj));
  393. location.href = 'clearing.html'; //跳转结算页面
  394. }
  395. } else {
  396. mui.toast("请选择数量")
  397. }
  398. }
  399. });
  400. //跳转首页
  401. $(document).on('tap', '.go-index', function() {
  402. location.href = 'index.html';
  403. });
  404. //跳转购物车
  405. $(document).on('tap', '.fixed-cart', function() {
  406. location.href = 'shopping-cart.html';
  407. });
  408. //获取购物车数量
  409. function getCartNumber() {
  410. $.ajax(base_path + '/wechat/cart/getCartNumByCartOpenId?dates=' + new Date().getTime(), {
  411. data: {},
  412. dataType: 'json',
  413. xhrFields: {
  414. withCredentials: true
  415. },
  416. crossDomain: true,
  417. type: 'get',
  418. timeout: 15000,
  419. success: function(dt) {
  420. if(dt.isRedirect) {
  421. location.href = dt.redirectURL;
  422. } else {
  423. if(dt.status) {
  424. if(dt.data > 0) {
  425. $(".fixed-cart .my-badge-danger").text(dt.data).show();
  426. } else {
  427. $(".fixed-cart .my-badge-danger").text(dt.data).hide();
  428. }
  429. } else {
  430. mui.alert("获取购物车数量失败!");
  431. }
  432. }
  433. },
  434. error: function(xhr, type, errorThrown) {
  435. console.log(xhr);
  436. mui.alert("获取购物车数量失败!网络错误");
  437. }
  438. });
  439. }
  440. //分享
  441. function fenxiang() {
  442. var src = location.href;
  443. src = "//s.iamberry.com/aiberle/wechat/pro-details.html?productId=" + productId;
  444. window.wxFriend = {
  445. "appId": "",
  446. "imgUrl": productIntroduceImg,
  447. "link": src,
  448. "desc": productRemark,
  449. "title": 'Aiberle | ' + productName,
  450. "netError": "您的网络异常,请刷新重试!如多次刷新无效,请向我们反应 ~",
  451. "shareTimeSuccess": "分享成功",
  452. "shareTimeCancel": "已取消分享",
  453. "shareAppSuccess": "分享成功!",
  454. "shareAppCancel": "已取消分享"
  455. };
  456. getConfig();
  457. }
  458. //返回顶部方法
  459. function gotoTop(acceleration, stime) {
  460. acceleration = acceleration || 0.1;
  461. stime = stime || 10;
  462. var x1 = 0,
  463. y1 = 0,
  464. x2 = 0,
  465. y2 = 0,
  466. x3 = 0,
  467. y3 = 0;
  468. if(document.documentElement) {
  469. x1 = document.documentElement.scrollLeft || 0;
  470. y1 = document.documentElement.scrollTop || 0
  471. }
  472. if(document.body) {
  473. x2 = document.body.scrollLeft || 0;
  474. y2 = document.body.scrollTop || 0
  475. }
  476. var x3 = window.scrollX || 0;
  477. var y3 = window.scrollY || 0;
  478. var x = Math.max(x1, Math.max(x2, x3));
  479. var y = Math.max(y1, Math.max(y2, y3));
  480. var speeding = 1 + acceleration;
  481. window.scrollTo(Math.floor(x / speeding), Math.floor(y / speeding));
  482. if(x > 0 || y > 0) {
  483. var run = "gotoTop(" + acceleration + ", " + stime + ")";
  484. window.setTimeout(run, stime)
  485. }
  486. };
  487. //绑定滚动条事件
  488. $(window).on("scroll", function() {
  489. //向下滚动距离大于180像素显示返回顶部,否则隐藏
  490. if($(window).scrollTop() > 180) {
  491. $(".return").show();
  492. } else {
  493. $(".return").hide();
  494. }
  495. });
  496. </script>
  497. </body>
  498. </html>