Authored by uedxwg

历史错误修改

@@ -11,11 +11,19 @@ var $ = require('jquery'), @@ -11,11 +11,19 @@ var $ = require('jquery'),
11 11
12 var swiper, 12 var swiper,
13 $fixTitleBar, 13 $fixTitleBar,
  14 + $brandText,
  15 + $brandHref,
14 $brandList = $('.brand-list'); 16 $brandList = $('.brand-list');
15 17
16 var searchH = $('.newbrand-search').outerHeight(), 18 var searchH = $('.newbrand-search').outerHeight(),
17 headerH = $('.yoho-header').outerHeight(), 19 headerH = $('.yoho-header').outerHeight(),
18 brandSwipe = parseInt(searchH) + parseInt(headerH) - 1, 20 brandSwipe = parseInt(searchH) + parseInt(headerH) - 1,
  21 + minBrandListTop,
  22 + searchArray = [],
  23 + clearTextHammer,
  24 + removeHistory,
  25 + searchList,
  26 + yohoHistory,
19 minBrandListTop; 27 minBrandListTop;
20 28
21 var brandsData, 29 var brandsData,
@@ -109,6 +117,21 @@ function searchResult() { @@ -109,6 +117,21 @@ function searchResult() {
109 117
110 // 插入 dom,绑定事件 118 // 插入 dom,绑定事件
111 $('.search-result').html(html); 119 $('.search-result').html(html);
  120 + $('.search-result .brand-list p').each(function (index) {
  121 + searchList = new Hammer($('.search-result .brand-list p').eq(index)[0]);
  122 + searchList.on('tap', function() {
  123 + $brandText = $('.search-result .brand-list p').eq(index).find('a').html();
  124 + $brandHref = $('.search-result .brand-list p').eq(index).find('a').attr('href');
  125 + if (localStorage.getItem('yohoHistory')) {
  126 + yohoHistory = localStorage.getItem('yohoHistory');
  127 + searchArray.push(yohoHistory);
  128 + }
  129 + if (searchArray.toString().split($brandText).length < 2) {
  130 + searchArray.push('{"searchName":"' + $brandText + '","searchHref":"' + $brandText + '"}');
  131 + }
  132 + localStorage.setItem('yohoHistory', searchArray);
  133 + });
  134 + });
112 } 135 }
113 136
114 if ($('.brand-search-page').length) { 137 if ($('.brand-search-page').length) {
@@ -116,6 +139,7 @@ if ($('.brand-search-page').length) { @@ -116,6 +139,7 @@ if ($('.brand-search-page').length) {
116 $keyword = $('#keyword'); 139 $keyword = $('#keyword');
117 140
118 $keyword.on('input', function() { 141 $keyword.on('input', function() {
  142 + $('.history').css('display', 'none');
119 if ($keyword.val().length) { 143 if ($keyword.val().length) {
120 searchResult(); 144 searchResult();
121 $(this).closest('.search-box').css('width', '11.25rem'); 145 $(this).closest('.search-box').css('width', '11.25rem');
@@ -137,4 +161,20 @@ if ($('.brand-search-page').length) { @@ -137,4 +161,20 @@ if ($('.brand-search-page').length) {
137 $('form.search-box').on('submit', function() { 161 $('form.search-box').on('submit', function() {
138 return false; 162 return false;
139 }); 163 });
  164 + if (localStorage && localStorage.getItem('yohoHistory')) {
  165 + yohoHistory = $.parseJSON('[' + localStorage.getItem('yohoHistory') + ']');
  166 + if (yohoHistory) {
  167 + $.each(yohoHistory, function(index, content) {
  168 + $('<a href="' + content.searchHref + '">' + content.searchName + '</a>').appendTo('.historyList');
  169 + });
  170 + }
  171 + } else {
  172 + $('.history').css('display', 'none');
  173 + }
  174 +
  175 + removeHistory = new Hammer($('.removeHistory')[0]);
  176 + removeHistory.on('tap', function(e) {
  177 + $('.historyList').html(' ');
  178 + localStorage.clear();
  179 + });
140 } 180 }
@@ -37,7 +37,6 @@ $input.on('input', function() { @@ -37,7 +37,6 @@ $input.on('input', function() {
37 $clear.removeClass('hide'); 37 $clear.removeClass('hide');
38 } 38 }
39 }); 39 });
40 -  
41 cHammer = new Hammer($clear[0]); 40 cHammer = new Hammer($clear[0]);
42 cHammer.on('tap', function() { 41 cHammer.on('tap', function() {
43 $input.val('').trigger('input'); 42 $input.val('').trigger('input');
@@ -194,6 +194,51 @@ @@ -194,6 +194,51 @@
194 194
195 .search-result { 195 .search-result {
196 padding-top: 176rem / $pxConvertRem; 196 padding-top: 176rem / $pxConvertRem;
197 - } 197 + }
  198 + .history{
  199 + width: 100%;
  200 + height: auto;
  201 + overflow: hidden;
  202 + position: absolute;
  203 + left: 0;
  204 + top: 176rem / $pxConvertRem;
  205 + > h6{
  206 + width: 100%;
  207 + height: 88rem / $pxConvertRem;
  208 + line-height: 88rem / $pxConvertRem;
  209 + color: #999;
  210 + text-indent: .6rem;
  211 + font-size: 36em / $pxConvertRem;
  212 + }
  213 + .historyList{
  214 + width: 100%;
  215 + height: auto;
  216 + overflow: hidden;
  217 + display: block;
  218 + > a{
  219 + width: auto;
  220 + height: 58rem / $pxConvertRem;
  221 + overflow: hidden;
  222 + line-height: 58rem / $pxConvertRem;
  223 + margin: 0 0 20rem / $pxConvertRem .6rem;
  224 + padding: 0 20rem / $pxConvertRem;
  225 + float: left;
  226 + background-color:#f8f8f8;
  227 + color: #444;
  228 + }
  229 + }
  230 + > span{
  231 + width: auto;
  232 + height: 68rem / $pxConvertRem;
  233 + overflow: hidden;
  234 + display: inline-block;
  235 + line-height: 68rem / $pxConvertRem;
  236 + border:1px solid #e6e6e6;
  237 + padding: 0 28rem / $pxConvertRem;
  238 + font-size: 48em / $pxConvertRem;
  239 + margin-left: .6rem;
  240 + color: #000;
  241 + }
  242 + }
198 243
199 } 244 }
@@ -27,20 +27,20 @@ @@ -27,20 +27,20 @@
27 .clear-input { 27 .clear-input {
28 position: absolute; 28 position: absolute;
29 top: 24rem / $pxConvertRem; 29 top: 24rem / $pxConvertRem;
30 - right: 100rem / $pxConvertRem; 30 + right: 145rem / $pxConvertRem;
31 font-size: 32rem / $pxConvertRem; 31 font-size: 32rem / $pxConvertRem;
32 color: #b2b2b2; 32 color: #b2b2b2;
33 } 33 }
34 34
35 .search { 35 .search {
36 position: absolute; 36 position: absolute;
37 - top: 16rem / $pxConvertRem; 37 + top: 18rem / $pxConvertRem;
38 left: 515rem / $pxConvertRem; 38 left: 515rem / $pxConvertRem;
39 border: none; 39 border: none;
40 background: transparent; 40 background: transparent;
41 color: #000; 41 color: #000;
42 font-size: 32rem / $pxConvertRem; 42 font-size: 32rem / $pxConvertRem;
43 - line-height: 64rem / $pxConvertRem; 43 + line-height: 56rem / $pxConvertRem;
44 } 44 }
45 } 45 }
46 46
@@ -10,6 +10,11 @@ @@ -10,6 +10,11 @@
10 </div> 10 </div>
11 </form> 11 </form>
12 </div> 12 </div>
  13 + <div class="history">
  14 + <h6>历史纪录</h6>
  15 + <div class="historyList"></div>
  16 + <span class='removeHistory'>清空搜索历史</span>
  17 + </div>
13 <div class="search-result"> 18 <div class="search-result">
14 </div> 19 </div>
15 </div> 20 </div>
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 <i class="search-icon iconfont">&#xe60f;</i> 6 <i class="search-icon iconfont">&#xe60f;</i>
7 <input type="text" placeholder="搜索商品" name="query"> 7 <input type="text" placeholder="搜索商品" name="query">
8 <i class="clear-input iconfont hide">&#xe626;</i> 8 <i class="clear-input iconfont hide">&#xe626;</i>
9 - <span id="search" class="search" type="submit">搜索</span> 9 + <button id="search" class="search" type="submit">搜索</button>
10 </form> 10 </form>
11 </div> 11 </div>
12 <div class="search-items"> 12 <div class="search-items">