pro-details.html 19 KB

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