search.js
7.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
// pages/service/renting/search/search.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
searchValue: '',
postList: [],
searchHistory:[],
currentModal: 0,
currentPost: 0,
hidden_img: false,
hasMore: true,
pageNumber: 0,
avatar: [],
is_write:2,//1:已填写,2:未填写
},
goPostDetail(e) {
const id = +e.currentTarget.dataset.id;
const type = +e.currentTarget.dataset.type;
console.log('type', type);
if(type === 1) { //1是活动,2是拼餐
wx.navigateTo({
url: '/pages/activity/detail/detail?id=' + id,
})
}else {
wx.navigateTo({
url: '/pages/meal/detail/detail?id=' + id,
})
}
},
inputFocus() {
this.setData({postList:[]})
},
//输入搜索内容
inputKey(e) {
this.setData({searchValue: e.detail.value})
},
//点击搜索(搜索结果)
// startSearch() {
// let self = this;
// if(!self.data.hasMore) return;
// self.setData({hasMore: false});
// let url = '/home/home/search';
// let params = {
// keyword: self.data.searchValue,
// page: self.data.pageNumber,
// };
// let header = {
// "XX-Token": wx.getStorageSync('token')
// };
// if(self.data.searchValue === '') {
// wx.showToast({title:'搜索内容不能为空~',icon: 'none'})
// }else {
// self.getSearchHistory();
// app.post(url, params, header).then((res) => {
// // console.log('搜索结果', res);
// if(+res.page < res.page_size) {
// self.data.hasMore = true;
// }
// const list = res.data.map((item, index) => {
// return {...item, showlabel_box: false, more: item.more !== '' ? JSON.parse(item.more) : ''}
// });
// self.setData({
// postList: self.data.postList.concat(list)
// });
// // console.log('搜索结果', self.data.postList);
// })
// }
// },
//点击量
// hit(current) {
// let url = '/home/home/hits';
// let params = {
// id: this.data.postList[current].id,
// };
// let header = { "XX-Token": wx.getStorageSync('token') };
// app.post(url, params, header).then((res) => {
// // console.log('点击量',res);
// if(res.message == "操作成功") {
// const post_hits = this.data.postList[current].post_hits +1
// this.setData({
// [`postList[${current}].post_hits`]: post_hits
// });
// }
// })
// },
//清空输入框
clearInput() {
this.setData({searchValue: ''})
},
//搜索结果
startSearch() {
let self = this;
let url = '/portal/Active/findRes';
let header = {
"XX-Token": wx.getStorageSync('token')
};
let params = {
token: wx.getStorageSync('token'),
keyword:self.data.searchValue,
};
app.post(url, params, header).then((res) => {
console.log('搜索历史列表', res);
wx.hideLoading();
if(+res.code === 1) {
if(res.data.list.length === 0) {
wx.showToast({title:'暂无更多内容',icon:'none'})
}else {
self.setData({
postList: res.data.list
});
}
}
})
},
//点击热门搜索
clickHot(e) {
const current = e.currentTarget.dataset.index;
this.setData({
searchValue: this.data.hot[current].title,
});
wx.showLoading({title: '加载中',});
this.startSearch();
this.getSearchHistory()
},
//点击搜索历史
clickHistory(e) {
const current = e.currentTarget.dataset.index;
this.setData({
searchValue: this.data.history[current].title,
});
wx.showLoading({title: '加载中',});
this.startSearch();
this.getSearchHistory()
},
//清空历史搜索
clearHistory() {
let self = this;
let url = '/portal/Active/delHistory';
let params = {
token: wx.getStorageSync('token'),
};
app.post(url, params, {}).then((res) => {
console.log('清空搜索历史列表', res);
wx.showLoading({title: '加载中',});
if(+res.code === 1) {
wx.showToast({title:res.message,icon:'none'})
}
self.getSearchHistory()
})
},
// //查看文章详情
// goPostDetail(e) {
// const current = e.currentTarget.dataset.index;
// const list = this.data.postList.map((item,index) => {
// return {...item, showlabel_box: false}
// });//进入详情时关闭所有弹框
// this.setData({
// postList: list,
// currentPost: current
// });
// this.hit(current);
// wx.navigateTo({
// url: '../../rentingDetail/rentingDetail?post_id=' + this.data.postList[current].id,
// })
// },
//获取热门搜索和搜索历史
getSearchHistory() {
const self = this;
let url = '/portal/Active/find';
let params = {
// activeId: self.data.detail_id,
token: wx.getStorageSync('token'),
};
// let header = {
// "token": wx.getStorageSync('token')
// };
app.post(url, params, {}).then((res) => {
console.log('获取热门搜索和搜索历史', res);
if (+res.code === 1) {
wx.hideLoading();
self.setData({
hot: res.data.hot,
history:res.data.history
// end_time: res.data.active.time,
// over_hours:res.data.active.over_time,//几小时截止
});
// self.countDown();
}
// wx.hideLoading()
})
},
onLoad: function (options) {
const self = this;
self.setData({
id: +options.id,
order: +options.order,
select_id: +options.select_id,
});
self.getSearchHistory();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
// wx.showLoading({title: '加载中',});
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
const self = this;
if (!self.data.hasMore) {
wx.showToast({
title: '没有更多数据了~',
icon: 'none'
});
console.log('reach bottom', self.data.hasMore);
} else {
console.log('reach bottom', self.data.hasMore);
self.data.pageNumber++;
self.startSearch();
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})