index.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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">
  65. <strong>精选产品</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">
  99. <strong>产品配件</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. //console.log(this.productColorList[0].colorDiscount)
  227. if(this.productColorList != null && this.productColorList.length > 0){
  228. li.innerHTML = '<a name="' + this.productId + '"><img class="mui-media-object" src="' + this.productChoicenessIm + '"><div class="index-pro-tit">' + this.productName + '</div><p class="mui-text-left">' + this.productColorDes + '<span class="f-price">¥' + accDiv(this.productColorList[0].colorDiscount , 100) + '</span></p></a>';
  229. table.appendChild(li);
  230. }
  231. });
  232. //遍历精选产品(50%宽度)
  233. var jingxuan2 = dt.data.selectProduct;
  234. mui(jingxuan2).each(function(index) {
  235. var li = document.createElement('li');
  236. li.className = 'mui-table-view-cell mui-media mui-col-xs-6';
  237. if(this.productColorList != null && this.productColorList.length > 0){
  238. li.innerHTML = '<a name="' + this.productId + '"><img class="mui-media-object" src="' + this.productChoicenessIm + '"><div class="index-pro-tit">' + this.productName + '</div><p class="mui-text-left">' + this.productColorDes + '</p><p class="l-price">¥' + accDiv(this.productColorList[0].colorDiscount , 100) + '</p></a>';
  239. table.appendChild(li);
  240. }
  241. });
  242. //遍历菜单
  243. var caidanData = dt.data.productTypeList;
  244. var caidan = document.body.querySelector("#menu");
  245. mui(caidanData).each(function(index) {
  246. var li = document.createElement("li");
  247. li.innerHTML = '<label name="' + this.typeId + '"><div>' + this.typeName + '</div></label>';
  248. caidan.appendChild(li);
  249. colors.push({
  250. "id": colors.length + 1,
  251. "typeId": this.typeId,
  252. "label": this.typeName,
  253. "url":"1"
  254. });
  255. $.each(this.childTypeList, function() {
  256. var li = document.createElement("li");
  257. li.className = 'line';
  258. li.innerHTML = '<a name="' + this.typeId + '" item="' + this.childTypeId + '"><div>' + this.childTypeName + '</div></a>';
  259. caidan.appendChild(li);
  260. colors.push({
  261. "id": colors.length + 1,
  262. "typeId": this.typeId,
  263. "label": this.childTypeName,
  264. "childTypeId": this.childTypeId,
  265. "url":"1"
  266. });
  267. });
  268. //遍历产品配件
  269. if(this.typeId == 5) {
  270. console.log(this.childTypeList)
  271. var peijian = document.body.querySelector("#index-pro-items");
  272. peijian.innerHTML = '';
  273. $.each(this.childTypeList, function() {
  274. var a = document.createElement("a");
  275. a.className = 'mui-control-item';
  276. a.setAttribute("name", this.typeId);
  277. a.setAttribute("item", this.childTypeId);
  278. a.innerHTML = this.childTypeName;
  279. peijian.appendChild(a);
  280. });
  281. }
  282. });
  283. console.log(colors)
  284. //绑定搜索框自动补全
  285. $('#search').autocompleter({
  286. // marker for autocomplete matches
  287. highlightMatches: true,
  288. // object to local or url to remote search
  289. source: colors,
  290. // custom template 对应 自动补全参数
  291. template: '<span>{{ label }}</span>',
  292. // show hint
  293. hint: true,
  294. // abort source if empty field
  295. empty: false,
  296. // max results
  297. limit: 10,
  298. callback: function(value, index, selected) {
  299. //selected 包含 (id,label)
  300. console.log(selected)
  301. search(selected);
  302. }
  303. });
  304. } else {
  305. mui.alert("获取数据失败!");
  306. }
  307. }
  308. },
  309. error: function(xhr, type, errorThrown) {
  310. console.log(xhr);
  311. mui.alert("获取数据失败!网络错误");
  312. }
  313. });
  314. //搜索框焦点事件
  315. $('#search').on('focus', function(e) {
  316. window.scrollTo(0, 0, 500);
  317. $(".icon-caidan").hide();
  318. $('.my-btn-cancel').show();
  319. if($(this).val().length > 0) {
  320. $('#search-hot').hide(500);
  321. $(".autocompleter-list").css("height", $(document).height())
  322. } else {
  323. $("#search-hot").css("height",$(document.body).height()).show();
  324. $("body").css("overflow","hidden");
  325. }
  326. });
  327. //搜索框失去焦点事件
  328. $('#search').on('blur', function(e) {
  329. setTimeout(function(){
  330. $('#search-hot,.my-btn-cancel').hide();
  331. $("body").css("overflow","auto");
  332. $(".icon-caidan").show();
  333. },700);
  334. });
  335. //点击后把text赋值到搜索框
  336. $(document).on('tap', '#history button', function() {
  337. $('#search').val($(this).text());
  338. console.log($(this).text())
  339. $('#search-hot').hide();
  340. $("body").css("overflow","auto");
  341. var parameter = {};
  342. parameter["id"] = $(this).attr("name");
  343. parameter["label"] = $(this).text();
  344. parameter["typeId"] = $(this).attr("typeid");
  345. if(typeof($(this).attr("childtypeId")) != "undefined") {
  346. parameter["childTypeId"] = $(this).attr("childtypeid");
  347. }
  348. search(parameter);
  349. });
  350. //搜索框本地缓存
  351. function search(selected) {
  352. if(!window.localStorage) {
  353. mui.alert("您的浏览器不支持localStorage");
  354. } else {
  355. //自定义json数据
  356. var obj = {},
  357. searchobj = {};
  358. if(histoty != null) {
  359. var str = histoty.text;
  360. if(str.length > 2) {
  361. str.splice(2, 1)
  362. }
  363. str.splice(0, 0, selected)
  364. obj = {
  365. text: str
  366. }
  367. } else {
  368. obj = {
  369. text: [selected]
  370. };
  371. }
  372. searchobj = {
  373. text: [selected]
  374. }
  375. //json格式化插入
  376. localStorage.setItem('search_histoty', JSON.stringify(obj));
  377. sessionStorage.setItem('search_data', JSON.stringify(searchobj));
  378. mui.openWindow({
  379. url: 'pro-list.html?productId=' + selected.typeId
  380. });
  381. }
  382. }
  383. //监听搜索框值改变事件
  384. $('#search').on('input', function(e) {
  385. if($(this).val().length > 0) {
  386. $('#search-hot').hide();
  387. $(".autocompleter-list").css("height", $(document).height());
  388. } else {
  389. $('#search-hot').show();
  390. $("body").css("overflow","hidden");
  391. $(".autocompleter-list").css("height", "auto");
  392. }
  393. });
  394. $(".loading").hide().css("opacity", "0");
  395. });
  396. //取消搜索
  397. $(document).on('tap', '.my-btn-cancel', function() {
  398. $(this).hide();
  399. $('#search-hot').hide();
  400. $("body").css("overflow","auto");
  401. $('#search').autocompleter("close");
  402. $(".autocompleter-list").empty().css("height", "auto");
  403. $('.autocompleter-hint').removeClass('autocompleter-hint-show').empty();
  404. $(".icon-caidan").show();
  405. $('#search').blur();
  406. });
  407. //打开菜单
  408. $(document).on('tap', '.icon-caidan', function() {
  409. $("#menu").css("height", $(window).height());
  410. $("#menu>li").addClass("active");
  411. });
  412. //关闭菜单
  413. $(document).on('tap', '.icon-guanbi', function() {
  414. $("#menu>li").removeClass("active");
  415. $("#menu").css("height", "0px");
  416. });
  417. //精选产品详情
  418. $(document).on('tap', '#index-pro-list .mui-table-view-cell>a', function() {
  419. location.href = 'pro-details.html?productId=' + $(this).attr("name")
  420. });
  421. //产品详情-配件
  422. $(document).on('tap', '#index-pro-items>.mui-control-item', function() {
  423. location.href = 'pro-list.html?productId=' +$(this).attr("name")+'&childTypeId='+$(this).attr("item");
  424. });
  425. //more更多产品
  426. $(document).on('tap', '.go_pro_list', function() {
  427. if(typeof($(this).attr("pos"))!="undefined"){
  428. location.href="pro-list.html?productId=5";
  429. }else{
  430. location.href="pro-list.html";
  431. }
  432. });
  433. //菜单跳转
  434. $(document).on('tap', '#menu>.line>a', function() {
  435. location.href='pro-list.html?productId='+$(this).attr("name")+'&childTypeId='+$(this).attr("item");
  436. });
  437. </script>
  438. </body>
  439. </html>