104 lines
2.3 KiB
JavaScript
104 lines
2.3 KiB
JavaScript
import { imageBasUrl } from '../../utils/config'
|
|
const { httpRequest } = getApp();
|
|
|
|
Page({
|
|
data: {
|
|
searchKeyword: '',
|
|
searchFlag: false,
|
|
searchList: [],
|
|
historySearch: []
|
|
},
|
|
onShow() {
|
|
const historyData = my.getStorageSync({ key: 'historySearch' });
|
|
this.setData({
|
|
historySearch: historyData.data || [],
|
|
})
|
|
},
|
|
|
|
handleSearchClear() {
|
|
this.setData({
|
|
searchKeyword: '',
|
|
searchFlag: false
|
|
})
|
|
},
|
|
|
|
handleSearchSubmit(event) {
|
|
const historySearch = this.data.historySearch;
|
|
my.hideKeyboard();
|
|
const paramenter = {
|
|
path: '/find',
|
|
method: 'POST',
|
|
body: {
|
|
keyword: event
|
|
}
|
|
}
|
|
httpRequest(paramenter).then(res => {
|
|
console.log(res, Array.isArray(res.data), "findfind")
|
|
if (Array.isArray(res.data)) {
|
|
historySearch.push(event);
|
|
this.setData({
|
|
searchList: res.data,
|
|
searchKeyword: event,
|
|
searchFlag: true
|
|
})
|
|
this.setHistorySearch(historySearch);
|
|
}
|
|
})
|
|
},
|
|
|
|
handleSearchInput(event) {
|
|
this.setData({
|
|
searchKeyword: event
|
|
})
|
|
},
|
|
|
|
setHistorySearch(historySearch = []) {
|
|
this.setData({
|
|
historySearch,
|
|
})
|
|
my.setStorageSync('historySearch', historySearch);
|
|
},
|
|
|
|
clearHistoryList() {
|
|
my.confirm({
|
|
title: '温馨提示',
|
|
content: '你确定要删除历史记录吗',
|
|
confirmButtonText: '是',
|
|
cancelButtonText: '否',
|
|
success: (result) => {
|
|
console.log(result, "resultresult")
|
|
if (result.confirm) {
|
|
this.setHistorySearch();
|
|
}
|
|
},
|
|
});
|
|
},
|
|
|
|
historuNavigator(event) {
|
|
const historySearch = this.data.historySearch;
|
|
console.log(event, "event")
|
|
const item = event.target.dataset.item;
|
|
|
|
my.hideKeyboard();
|
|
const paramenter = {
|
|
path: '/find',
|
|
method: 'POST',
|
|
body: {
|
|
keyword: item
|
|
}
|
|
}
|
|
httpRequest(paramenter).then(res => {
|
|
console.log(res, Array.isArray(res.data), "findfind")
|
|
if (Array.isArray(res.data)) {
|
|
console.log(historySearch, 'historySearch')
|
|
historySearch.push(item);
|
|
this.setHistorySearch(historySearch);
|
|
this.setData({
|
|
searchList: res.data,
|
|
searchKeyword: item,
|
|
searchFlag: true
|
|
})
|
|
}
|
|
})
|
|
},
|
|
}) |