...
|
...
|
@@ -66,26 +66,37 @@ export default class Search extends Component { |
|
|
if (e.detail.value === '') {
|
|
|
return;
|
|
|
}
|
|
|
this.savaLateSearch(e);
|
|
|
this.saveLateSearch(e);
|
|
|
router.go('productList', {
|
|
|
query: e.detail.value
|
|
|
});
|
|
|
}
|
|
|
|
|
|
savaLateSearch(e) {
|
|
|
saveLateSearch(e) {
|
|
|
const latelySearch = this.state.latelySearch;
|
|
|
if (latelySearch.length >= 10) {
|
|
|
latelySearch.pop();
|
|
|
}
|
|
|
latelySearch.unshift({search_word: e.detail.value});
|
|
|
let setList = this.removeSameSearch(latelySearch, e.detail.value);
|
|
|
setList.unshift({search_word: e.detail.value});
|
|
|
try {
|
|
|
Taro.setStorageSync('latelySearch', latelySearch);
|
|
|
Taro.setStorageSync('latelySearch', setList);
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
}
|
|
|
this.setState({
|
|
|
latelySearch
|
|
|
})
|
|
|
// this.setState({
|
|
|
// latelySearch
|
|
|
// })
|
|
|
}
|
|
|
|
|
|
removeSameSearch(arr, search_word) {
|
|
|
let hash = [];
|
|
|
for (var i = 0; i < arr.length; i++) {
|
|
|
if (arr[i].search_word !== search_word) {
|
|
|
hash.push(arr[i]);
|
|
|
}
|
|
|
}
|
|
|
return hash;
|
|
|
}
|
|
|
|
|
|
onRemoveAllSearch() {
|
...
|
...
|
|