index.html 17 KB

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