2024-01-25 13:47:25 +08:00

103 lines
2.2 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.setHistorySearch(historySearch);
this.setData({
searchList: res.data,
searchKeyword: event,
searchFlag: true
})
}
})
},
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)) {
historySearch.push(item);
this.setHistorySearch(historySearch);
this.setData({
searchList: res.data,
searchKeyword: item,
searchFlag: true
})
}
})
},
})