pro-details.html 20 KB

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