Authored by 王水玲

还原搜索联想词

... ... @@ -111,7 +111,8 @@ const Search = {
},
getSuggest(params) {
return api.get('', _.assign({
method: 'app.search.fuzzy'
method: 'app.search.fuzzy',
app_type: 1
}, params), {code: 200}).then(result => {
let list = result.data || [];
let suggest = [];
... ...
... ... @@ -15,8 +15,7 @@ var $searchWrap = $('.search-wrapper'),
$clearInput = $('.clear-input');
var goodsTpl = require('../../tpl/common/bag-goods.hbs');
// var searchHintTpl = require('../../tpl/header/search-hint.hbs');
var searchHintTpl = require('../../tpl/header/search-hint.hbs');
var delayer;
... ... @@ -182,78 +181,60 @@ $searchKey.keyup(function(e) {
}
});
// 关键词搜索联想
// function searchSuggest(key) {
// $.get('//www.yohoblk.com/product/query/suggest', {
// keyword: key
// }, function(data) {
// if (data.length >= 1) {
// $searchHint.html(searchHintTpl({list: data})).show();
// } else {
// $searchHint.hide();
// }
// });
// }
function searchSuggest(key) {
$.get('//www.yohoblk.com/product/query/suggest', {
keyword: key
}, function(data) {
if (data.length >= 1) {
$searchHint.html(searchHintTpl({list: data})).show();
} else {
$searchHint.hide();
}
});
}
$searchKey.keyup(function(e) {
var key = $searchKey.val();
$searchKey.keyup(function(e) {
var val = $.trim($(this).val()),
$child = $searchHint.find('li'),
$act = $searchHint.find('.action'),
$focus;
if (e.which === 13) {
if (key) {
if (e.which > 36 && e.which < 41) {
if (e.which === 38) {
$focus = $act.prev();
if (!$act.length || !$focus.length) {
$focus = $child.eq($child.length - 1);
}
} else if (e.which === 40) {
$focus = $act.next();
if (!$act.length || !$focus.length) {
$focus = $child.eq(0);
}
} else {
return;
}
$child.removeClass('action');
$focus.addClass('action');
$(this).val($focus.find('.search-value').text());
} else if (e.which === 13) {
if (val) {
$searchForm.submit();
}
} else {
if ($searchHint && $searchHint.length) {
val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
searchSuggest(val);
}
}
if (key) {
if (val) {
$clearInput.show();
} else {
$clearInput.hide();
}
});
// 搜索联动代码,由于接口暂不支持,先注释
// $searchKey.keyup(function(e) {
// var val = $.trim($(this).val()),
// $child = $searchHint.find('li'),
// $act = $searchHint.find('.action'),
// $focus;
//
// if (e.which > 36 && e.which < 41) {
//
// if (e.which === 38) {
// $focus = $act.prev();
// if (!$act.length || !$focus.length) {
// $focus = $child.eq($child.length - 1);
// }
// } else if (e.which === 40) {
// $focus = $act.next();
// if (!$act.length || !$focus.length) {
// $focus = $child.eq(0);
// }
// } else {
// return;
// }
//
// $child.removeClass('action');
// $focus.addClass('action');
// $(this).val($focus.find('.search-value').text());
// } else if (e.which === 13) {
// if (val) {
// $searchForm.submit();
// }
// } else {
// if ($searchHint && $searchHint.length) {
// val = val.replace(new RegExp('\'', 'gm'), ''); // 去掉特殊字符
// searchSuggest(val);
// }
// }
//
// if (val) {
// $clearInput.show();
// } else {
// $clearInput.hide();
// }
// });
});
// ie8输入框提示特殊处理
// 应产品要求所有浏览器获得焦点提示文字隐藏
... ...