pro-details.html 17 KB

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