index.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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>Aiberle官方商城</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. <header class="mui-bar mui-bar-nav" style="display: none;">
  15. <!--头部搜索框-->
  16. <div class="search-cotainer" >
  17. <div class="mui-input-row mui-search" >
  18. <input id="search" name="search" class="my-search-ipt" type="text" placeholder='大家都在搜"净水机"'>
  19. </div>
  20. <span class="iconfont icon-caidan"></span>
  21. <span class="my-btn-cancel">取消</span>
  22. </div>
  23. <div id="search-hot" style="display: none;">
  24. <div class="search-cotainer line-25" id="history">
  25. <p>历史搜索</p>
  26. <!--<button type="button" class="mui-btn">净水机</button>
  27. <button type="button" class="mui-btn">冲奶机</button>
  28. <button type="button" class="mui-btn">电动牙刷</button>-->
  29. </div>
  30. <!--<div class="search-cotainer line-25">
  31. <p>热门搜索</p>
  32. <button type="button" class="mui-btn">滤芯</button>
  33. <button type="button" class="mui-btn">奶粉罐</button>
  34. <button type="button" class="mui-btn">牙刷头</button>
  35. <button type="button" class="mui-btn">水箱</button>
  36. <button type="button" class="mui-btn">接水台</button>
  37. <button type="button" class="mui-btn">加湿器</button>
  38. </div>-->
  39. </div>
  40. </header>
  41. <footer class="mui-bar mui-bar-tab" id="footer-bar-tab">
  42. <a class="mui-tab-item mui-active">
  43. <span class="iconfont icon-shouye"></span>
  44. <span class="mui-tab-label">首页</span>
  45. </a>
  46. <a class="mui-tab-item">
  47. <span class="iconfont icon-gouwuche"></span>
  48. <span class="mui-tab-label">购物车</span>
  49. </a>
  50. <a class="mui-tab-item">
  51. <span class="iconfont icon-dingdan"></span>
  52. <span class="mui-tab-label">订单</span>
  53. </a>
  54. <a class="mui-tab-item">
  55. <span class="iconfont icon-wode"></span>
  56. <span class="mui-tab-label">我的</span>
  57. </a>
  58. </footer>
  59. <div class="mui-content" style="padding-top: 10px;">
  60. <div class="banner-box">
  61. <!--banner位置-->
  62. <div class="index-banner" style="display: none;"></div>
  63. </div>
  64. <div class="index-title" style="margin-top: 20px;">
  65. <strong style="font-size: 16px;">精选产品</strong><span class="mui-pull-right go_pro_list"><font>More</font><span class="mui-icon mui-icon-arrowright"></span></span>
  66. </div>
  67. <ul class="mui-table-view mui-grid-view my-view-no" id="index-pro-list" style="padding-bottom: 0;">
  68. <!--<li class="mui-table-view-cell mui-media mui-col-xs-12">
  69. <a>
  70. <img class="mui-media-object" src="images/index-1.jpg">
  71. <div class="index-pro-tit">[精选] Aiberle美国智能净饮水一体机</div>
  72. <p class="mui-text-left">4级ro净化、10s加热、3s出水<span class="f-price">¥2999.00</span></p>
  73. </a>
  74. </li>
  75. <li class="mui-table-view-cell mui-media mui-col-xs-12">
  76. <a>
  77. <img class="mui-media-object" src="images/index-1.jpg">
  78. <div class="index-pro-tit">[精选] Aiberle美国智能净饮水一体机</div>
  79. <p class="mui-text-left">4级ro净化、10s加热、3s出水<span class="f-price">¥2999.00</span></p>
  80. </a>
  81. </li>
  82. <li class="mui-table-view-cell mui-media mui-col-xs-6">
  83. <a><img class="mui-media-object" src="images/index-2.jpg">
  84. <div class="index-pro-tit">[育儿] Aiberle冲奶机</div>
  85. <p class="mui-text-left">一键操作、8s冲好一瓶奶x</p>
  86. <p class="l-price">¥799.00</p>
  87. </a>
  88. </li>
  89. <li class="mui-table-view-cell mui-media mui-col-xs-6">
  90. <a>
  91. <img class="mui-media-object" src="images/index-3.jpg">
  92. <div class="index-pro-tit">[宝妈] Aiberle电动牙刷</div>
  93. <p class="mui-text-left">智慧科技、呵护妈妈口腔</p>
  94. <p class="l-price">¥299.00</p>
  95. </a>
  96. </li>-->
  97. </ul>
  98. <div class="index-title" style="margin-top: 20px;">
  99. <strong style="font-size: 16px;">产品配件</strong><span class="mui-pull-right go_pro_list" pos="bottom"><font>More</font><span class="mui-icon mui-icon-arrowright"></span></span>
  100. </div>
  101. <div style="margin:8px 14px 30px 14px;">
  102. <div id="index-pro-items" class="mui-segmented-control">
  103. <!--<a class="mui-control-item" href="#item1">净水机配件</a>
  104. <a class="mui-control-item" href="#item2">冲奶机配件</a>
  105. <a class="mui-control-item" href="#item3">电动牙刷配件</a>-->
  106. </div>
  107. </div>
  108. </div>
  109. <ul id="menu">
  110. <li><span class="iconfont icon-guanbi"></span></li>
  111. <!--<li><label><div>净水机</div></label></li>
  112. <li class="line"><a href="javascript:;"><div>智能净水机</div></a></li>
  113. <li class="line"><a href="javascript:;"><div>智能净水机配件</div></a></li>
  114. <li><label><div>冲奶机</div></label></li>
  115. <li class="line"><a href="javascript:;"><div>智能冲奶机</div></a></li>
  116. <li class="line"><a href="javascript:;"><div>智能冲奶机配件</div></a></li>
  117. <li><label><div>电动牙刷</div></label></li>
  118. <li class="line"><a><div>声波女式电动牙刷</div></a></li>
  119. <li class="line"><a href="javascript:;"><div>声波女式电动牙刷配件</div></a></li>-->
  120. </ul>
  121. <!-- 加载ing -->
  122. <div class="loading covers">
  123. <div class="loading-bj"></div>
  124. <p>正在加载...</p>
  125. </div>
  126. <!-- 加载ing END -->
  127. <script src="js/mui.min.js"></script>
  128. <script src="js/jquery-2.1.1.min.js"></script>
  129. <script src="js/jquery.autocompleter.js"></script>
  130. <script src="js/main.js"></script>
  131. <script src="js/wechat-utils-1.0.js"></script>
  132. <script>
  133. // 读取值
  134. var colors = [];
  135. var histoty = JSON.parse(localStorage.getItem('search_histoty'));
  136. console.log(histoty)
  137. if(histoty != null) {
  138. var str = histoty.text;
  139. for(i = 0; i < str.length; i++) {
  140. var childTypeId = ''
  141. if(typeof(str[i].childTypeId) != "undefined") {
  142. childTypeId = 'childTypeid=' + str[i].childTypeId;
  143. }
  144. $("#history").append('<button type="button" class="mui-btn" name="' + str[i].id + '" typeid="' + str[i].typeId + '" ' + childTypeId + '>' + str[i].label + '</button>');
  145. }
  146. }
  147. /**
  148. *搜索框自动补全参数
  149. */
  150. //var colors = [{
  151. // "id": "1",
  152. // "label": "冲奶机"
  153. //}, {
  154. // "id": "2",
  155. // "label": "净水机"
  156. //}, {
  157. // "id": "3",
  158. // "label": "电动牙刷"
  159. //}, {
  160. // "id": "4",
  161. // "name":"lvxin",
  162. // "label": "滤芯"
  163. //}, {
  164. // "id": "5",
  165. // "label": "奶粉罐"
  166. //}, {
  167. // "id": "6",
  168. // "label": "牙刷头"
  169. //}, {
  170. // "id": "7",
  171. // "label": "水箱"
  172. //}, {
  173. // "id": "8",
  174. // "label": "接水台"
  175. //}, {
  176. // "id": "9",
  177. // "label": "加湿器"
  178. //}];
  179. mui.ready(function() {
  180. $.ajax(base_path + '/wechat/indexData?dates=' + new Date().getTime(), {
  181. data: {},
  182. dataType: 'json',
  183. xhrFields: {
  184. withCredentials: true
  185. },
  186. crossDomain: true,
  187. type: 'post',
  188. timeout: 15000,
  189. success: function(dt) {
  190. //判断一下
  191. if(dt.isRedirect) {
  192. location.href = dt.redirectURL;
  193. } else {
  194. console.log(dt)
  195. if(dt.status) {
  196. //遍历banner
  197. var bannerstr = "",
  198. dian = "";
  199. var banner_data = dt.data.banners;
  200. mui(banner_data).each(function(index) {
  201. if(index == 0) {
  202. bannerstr += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="' + banner_data[banner_data.length - 1].bannerImageCheckOutUrl + '"><img src="' + (banner_data[banner_data.length - 1].bannerImageUrl) + '"></a></div><div class="mui-slider-item mui-active"><a href="' + this.bannerImageCheckOutUrl + '"><img src="' + (this.bannerImageUrl) + '"></a></div>';
  203. dian += '<div class="mui-indicator mui-active"></div>'
  204. } else {
  205. bannerstr += '<div class="mui-slider-item"><a href="' + this.bannerImageCheckOutUrl + '"><img src="' + (this.bannerImageUrl) + '"></a></div>';
  206. dian += '<div class="mui-indicator"></div>'
  207. }
  208. if(index == (banner_data.length - 1) || (banner_data.length - 1) == 0) {
  209. bannerstr += '<div class="mui-slider-item mui-slider-item-duplicate"><a href="' + banner_data[0].bannerImageCheckOutUrl + '"><img src="' + (banner_data[0].bannerImageUrl) + '"></a></div>'
  210. }
  211. });
  212. dc('mui-slider-loop').innerHTML = bannerstr;
  213. dc('my-slider-indicator').innerHTML = dian;
  214. $("<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(".index-banner");
  215. //初始化banner自动轮播(interval:0为不自动轮播)单位ms
  216. var banner = mui('#slider');
  217. banner.slider({
  218. interval: 5000
  219. });
  220. //遍历精选置顶产品(100%宽度)
  221. var jingxuan1 = dt.data.selectProductTopper;
  222. var table = document.body.querySelector("#index-pro-list");
  223. mui(jingxuan1).each(function(index) {
  224. var li = document.createElement('li');
  225. li.className = 'mui-table-view-cell mui-media mui-col-xs-12';
  226. li.style.margin='0px 0px 7px 0px';
  227. //console.log(this.productColorList[0].colorDiscount)
  228. if(this.productColorList != null && this.productColorList.length > 0){
  229. li.innerHTML = '<a name="' + this.productId + '"><img class="mui-media-object" src="' + this.productChoicenessIm + '"><div class="index-pro-tit" style="margin-top: 10px;" >' + this.productName + '</div><p class="mui-text-left">' + this.productColorDes + '<span class="f-price">¥' + accDiv(this.productColorList[0].colorDiscount , 100) + '</span></p></a>';
  230. table.appendChild(li);
  231. }
  232. });
  233. //遍历精选产品(50%宽度)
  234. var jingxuan2 = dt.data.selectProduct;
  235. mui(jingxuan2).each(function(index) {
  236. var li = document.createElement('li');
  237. li.className = 'mui-table-view-cell mui-media mui-col-xs-6';
  238. if(this.productColorList != null && this.productColorList.length > 0){
  239. li.innerHTML = '<a name="' + this.productId + '"><img class="mui-media-object" style="background-color: #f9f7f8;border-radius: 5px;" src="' + this.productChoicenessIm + '"><div class="index-pro-tit" style="margin-top: 10px;">' + this.productName + '</div><p class="mui-text-left">' + this.productColorDes + '</p><p class="l-price" style="margin-top: 5px;">¥' + accDiv(this.productColorList[0].colorDiscount , 100) + '</p></a>';
  240. table.appendChild(li);
  241. }
  242. });
  243. //遍历菜单
  244. var caidanData = dt.data.productTypeList;
  245. var caidan = document.body.querySelector("#menu");
  246. mui(caidanData).each(function(index) {
  247. var li = document.createElement("li");
  248. li.innerHTML = '<label name="' + this.typeId + '"><div>' + this.typeName + '</div></label>';
  249. caidan.appendChild(li);
  250. colors.push({
  251. "id": colors.length + 1,
  252. "typeId": this.typeId,
  253. "label": this.typeName,
  254. "url":"1"
  255. });
  256. $.each(this.childTypeList, function() {
  257. var li = document.createElement("li");
  258. li.className = 'line';
  259. li.innerHTML = '<a name="' + this.typeId + '" item="' + this.childTypeId + '"><div>' + this.childTypeName + '</div></a>';
  260. caidan.appendChild(li);
  261. colors.push({
  262. "id": colors.length + 1,
  263. "typeId": this.typeId,
  264. "label": this.childTypeName,
  265. "childTypeId": this.childTypeId,
  266. "url":"1"
  267. });
  268. });
  269. //遍历产品配件
  270. if(this.typeId == 5) {
  271. console.log(this.childTypeList)
  272. var peijian = document.body.querySelector("#index-pro-items");
  273. peijian.innerHTML = '';
  274. $.each(this.childTypeList, function() {
  275. var a = document.createElement("a");
  276. a.className = 'mui-control-item';
  277. a.setAttribute("name", this.typeId);
  278. a.setAttribute("item", this.childTypeId);
  279. a.innerHTML = this.childTypeName;
  280. peijian.appendChild(a);
  281. });
  282. }
  283. });
  284. console.log(colors)
  285. //绑定搜索框自动补全
  286. $('#search').autocompleter({
  287. // marker for autocomplete matches
  288. highlightMatches: true,
  289. // object to local or url to remote search
  290. source: colors,
  291. // custom template 对应 自动补全参数
  292. template: '<span>{{ label }}</span>',
  293. // show hint
  294. hint: true,
  295. // abort source if empty field
  296. empty: false,
  297. // max results
  298. limit: 10,
  299. callback: function(value, index, selected) {
  300. //selected 包含 (id,label)
  301. console.log(selected)
  302. search(selected);
  303. }
  304. });
  305. } else {
  306. mui.alert("获取数据失败!");
  307. }
  308. }
  309. },
  310. error: function(xhr, type, errorThrown) {
  311. console.log(xhr);
  312. mui.alert("获取数据失败!网络错误");
  313. }
  314. });
  315. //搜索框焦点事件
  316. $('#search').on('focus', function(e) {
  317. window.scrollTo(0, 0, 500);
  318. $(".icon-caidan").hide();
  319. $('.my-btn-cancel').show();
  320. if($(this).val().length > 0) {
  321. $('#search-hot').hide(500);
  322. $(".autocompleter-list").css("height", $(document).height())
  323. } else {
  324. $("#search-hot").css("height",$(document.body).height()).show();
  325. $("body").css("overflow","hidden");
  326. }
  327. });
  328. //搜索框失去焦点事件
  329. $('#search').on('blur', function(e) {
  330. setTimeout(function(){
  331. $('#search-hot,.my-btn-cancel').hide();
  332. $("body").css("overflow","auto");
  333. $(".icon-caidan").show();
  334. },700);
  335. });
  336. //点击后把text赋值到搜索框
  337. $(document).on('tap', '#history button', function() {
  338. $('#search').val($(this).text());
  339. console.log($(this).text())
  340. $('#search-hot').hide();
  341. $("body").css("overflow","auto");
  342. var parameter = {};
  343. parameter["id"] = $(this).attr("name");
  344. parameter["label"] = $(this).text();
  345. parameter["typeId"] = $(this).attr("typeid");
  346. if(typeof($(this).attr("childtypeId")) != "undefined") {
  347. parameter["childTypeId"] = $(this).attr("childtypeid");
  348. }
  349. search(parameter);
  350. });
  351. //搜索框本地缓存
  352. function search(selected) {
  353. if(!window.localStorage) {
  354. mui.alert("您的浏览器不支持localStorage");
  355. } else {
  356. //自定义json数据
  357. var obj = {},
  358. searchobj = {};
  359. if(histoty != null) {
  360. var str = histoty.text;
  361. if(str.length > 2) {
  362. str.splice(2, 1)
  363. }
  364. str.splice(0, 0, selected)
  365. obj = {
  366. text: str
  367. }
  368. } else {
  369. obj = {
  370. text: [selected]
  371. };
  372. }
  373. searchobj = {
  374. text: [selected]
  375. }
  376. //json格式化插入
  377. localStorage.setItem('search_histoty', JSON.stringify(obj));
  378. sessionStorage.setItem('search_data', JSON.stringify(searchobj));
  379. mui.openWindow({
  380. url: 'pro-list.html?productId=' + selected.typeId
  381. });
  382. }
  383. }
  384. //监听搜索框值改变事件
  385. $('#search').on('input', function(e) {
  386. if($(this).val().length > 0) {
  387. $('#search-hot').hide();
  388. $(".autocompleter-list").css("height", $(document).height());
  389. } else {
  390. $('#search-hot').show();
  391. $("body").css("overflow","hidden");
  392. $(".autocompleter-list").css("height", "auto");
  393. }
  394. });
  395. $(".loading").hide().css("opacity", "0");
  396. });
  397. //取消搜索
  398. $(document).on('tap', '.my-btn-cancel', function() {
  399. $(this).hide();
  400. $('#search-hot').hide();
  401. $("body").css("overflow","auto");
  402. $('#search').autocompleter("close");
  403. $(".autocompleter-list").empty().css("height", "auto");
  404. $('.autocompleter-hint').removeClass('autocompleter-hint-show').empty();
  405. $(".icon-caidan").show();
  406. $('#search').blur();
  407. });
  408. //打开菜单
  409. $(document).on('tap', '.icon-caidan', function() {
  410. $("#menu").css("height", $(window).height());
  411. $("#menu>li").addClass("active");
  412. });
  413. //关闭菜单
  414. $(document).on('tap', '.icon-guanbi', function() {
  415. $("#menu>li").removeClass("active");
  416. $("#menu").css("height", "0px");
  417. });
  418. //精选产品详情
  419. $(document).on('tap', '#index-pro-list .mui-table-view-cell>a', function() {
  420. location.href = 'pro-details.html?productId=' + $(this).attr("name")
  421. });
  422. //产品详情-配件
  423. $(document).on('tap', '#index-pro-items>.mui-control-item', function() {
  424. location.href = 'pro-list.html?productId=' +$(this).attr("name")+'&childTypeId='+$(this).attr("item");
  425. });
  426. //more更多产品
  427. $(document).on('tap', '.go_pro_list', function() {
  428. if(typeof($(this).attr("pos"))!="undefined"){
  429. location.href="pro-list.html?productId=5";
  430. }else{
  431. location.href="pro-list.html";
  432. }
  433. });
  434. //菜单跳转
  435. $(document).on('tap', '#menu>.line>a', function() {
  436. location.href='pro-list.html?productId='+$(this).attr("name")+'&childTypeId='+$(this).attr("item");
  437. });
  438. </script>
  439. </body>
  440. </html>