Commit 37bcd045 by liangyuhang

添加关键词和单个历史记录删除,搜索结果页添加下拉刷新列表

parent 5eaf8318
<!--pages/library/library.wxml--> <!--pages/library/library.wxml-->
<view class="container"> <view class="container">
<view class="condition-con"> <view class="condition">
<view class="condition-list"> <view class="list">
<block wx:for="{{conditions}}" wx:key="index"> <block wx:for="{{conditions}}" wx:key="index">
<view class="condition {{tabIndex==index? 'active' : ''}}" data-index="{{index}}" data-name="{{item.name}}" bind:tap="switchTap" > <view class="tab {{tabIndex==index? 'active' : ''}}" data-index="{{index}}" data-name="{{item.name}}" bind:tap="switchTap" >
{{item.name}} {{item.name}}
</view> </view>
</block> </block>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
</view> </view>
<!-- 列表 --> <!-- 列表 -->
<view class="list-con"> <view style="margin-top: 100rpx;">
<eventList eventList="{{eventList}}"></eventList> <eventList eventList="{{eventList}}"></eventList>
</view> </view>
</view> </view>
/* pages/library/library.wxss */ /* pages/library/library.wxss */
/* 条件 */ /* 条件 */
.condition-con{ .condition{
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
height: 80rpx; height: 80rpx;
background-color: #025FEA; background-color: #025FEA;
z-index: 999; z-index: 999;
margin-bottom: -1000rpx;
} }
.condition-list{ .list{
display: flex; display: flex;
padding: 0 30rpx; padding: 0 30rpx;
line-height: 80rpx; line-height: 80rpx;
} }
.condition{ .tab{
width: 20vh; width: 20vh;
text-align: center; text-align: center;
font-size: 30rpx; font-size: 30rpx;
...@@ -38,7 +39,5 @@ ...@@ -38,7 +39,5 @@
} }
.list-con{
margin-top: 100rpx;
}
<!--pages/report/report.wxml--> <!--pages/report/report.wxml-->
<view class="container"> <view class="container">
<view class="condition-con"> <view class="condition">
<view class="condition-list"> <view class="list">
<block wx:for="{{conditions}}" wx:key="index"> <block wx:for="{{conditions}}" wx:key="index">
<view class="condition {{tabIndex==index? 'active' : ''}}" data-index="{{index}}" data-name="{{item.name}}" bind:tap="switchTap" > <view class="tab {{tabIndex==index? 'active' : ''}}" data-index="{{index}}" data-name="{{item.name}}" bind:tap="switchTap" >
{{item.name}} {{item.name}}
</view> </view>
</block> </block>
...@@ -11,5 +11,7 @@ ...@@ -11,5 +11,7 @@
</view> </view>
<!-- 列表 --> <!-- 列表 -->
<reportList reportList="{{reportList}}"></reportList> <view style="margin-top: 100rpx;">
<reportList reportList="{{reportList}}"></reportList>
</view>
</view> </view>
\ No newline at end of file
/* pages/report/report.wxss */ /* pages/report/report.wxss */
/* 条件 */ /* 条件 */
.condition-con{ .condition{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 80rpx; height: 80rpx;
background-color: #025FEA; background-color: #025FEA;
z-index: 999;
} }
.condition-list{ .list{
display: flex; display: flex;
padding: 0 30rpx; padding: 0 30rpx;
line-height: 80rpx; line-height: 80rpx;
} }
.condition{ .tab{
width: 20vh; width: 20vh;
text-align: center; text-align: center;
font-size: 30rpx; font-size: 30rpx;
......
...@@ -7,9 +7,10 @@ Page({ ...@@ -7,9 +7,10 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
keyword:'',
historySearch: [], historySearch: [],
hotSearchList: [] hotSearchList: [],
keyword:'',
currentTag:''
}, },
/** /**
...@@ -50,11 +51,13 @@ Page({ ...@@ -50,11 +51,13 @@ Page({
toSearchResult(){ toSearchResult(){
if (this.data.keyword.trim()) { if (this.data.keyword.trim()) {
let _keyword=this.data.keyword.trim();
// 记录搜索 // 记录搜索
let historySearch = wx.getStorageSync('historySearch') || []; let historySearch = wx.getStorageSync('historySearch') || [];
historySearch = historySearch.filter(item => item !== this.data.keyword) historySearch = historySearch.filter(item => item !== _keyword)
historySearch.unshift(this.data.keyword); historySearch.unshift(_keyword);
console.log(this.data.keyword) console.log(_keyword)
if (historySearch.length>10){ if (historySearch.length>10){
historySearch.pop(); historySearch.pop();
} }
...@@ -62,8 +65,17 @@ Page({ ...@@ -62,8 +65,17 @@ Page({
// 跳转到搜索结果页 // 跳转到搜索结果页
wx.navigateTo({ wx.navigateTo({
url: '/pages/search-result/search-result?keyword=' + this.data.keyword, url: '/pages/search-result/search-result?keyword=' + _keyword,
})
// 清了本页关键词
this.setData({
keyword:''
}) })
} else {
wx.showToast({
title: '请输入关键词!',
icon: 'none'
})
} }
}, },
// 获取搜索历史 // 获取搜索历史
...@@ -103,6 +115,24 @@ Page({ ...@@ -103,6 +115,24 @@ Page({
}); });
this.toSearchResult() this.toSearchResult()
}, },
// 长按历史搜索标签
touchTag(e){
// console.log("我长按了")
// 赋给currentTag,当tag和currentTag一样时显示右上角的删除图标
this.setData({
currentTag: e.currentTarget.dataset.keyword
});
},
// 移除单个搜索历史
clearOneTag(){
// console.log("点击了移除单个搜索历史")
let historySearch = wx.getStorageSync('historySearch') || [];
historySearch = historySearch.filter(item => item !== this.data.currentTag)
wx.setStorageSync('historySearch', historySearch);
//刷新搜索历史
this.getHistorySearch();
},
// 跳转事件详情页 // 跳转事件详情页
toEventDetail(e){ toEventDetail(e){
let _eventId=e.currentTarget.dataset.id let _eventId=e.currentTarget.dataset.id
...@@ -110,6 +140,13 @@ Page({ ...@@ -110,6 +140,13 @@ Page({
url: '/pages/event-detail/event-detail?eventId='+ _eventId, url: '/pages/event-detail/event-detail?eventId='+ _eventId,
}) })
}, },
// 清除关键词
clearKeyword(){
// console.log("清除关键词")
this.setData({
keyword:''
})
},
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
<view class='search-box'> <view class='search-box'>
<input placeholder="请输入关键词搜索" class='sear-input' bindconfirm='toSearchResult' bindinput='getSearchInput' value='{{keyword}}'></input> <input placeholder="请输入关键词搜索" class='sear-input' bindconfirm='toSearchResult' bindinput='getSearchInput' value='{{keyword}}'></input>
<image src='../../image/search.png' class='search-img'></image> <image src='../../image/search.png' class='search-img'></image>
<view class='delete' wx:if="{{keyword.length>0}}" bindtap="clearKeyword">
<image src='../../image/delete.png' ></image>
</view>
</view> </view>
<text class='cancel' bindtap='cancel'>取消</text> <text class='cancel' bindtap='cancel'>取消</text>
</view> </view>
...@@ -19,7 +22,8 @@ ...@@ -19,7 +22,8 @@
</view> </view>
<block wx:for="{{historySearch}}" wx:key='item'> <block wx:for="{{historySearch}}" wx:key='item'>
<view class='list'> <view class='list'>
<text class='tags' bindtap='onHistorySearch' data-keyword="{{item}}">{{item}}</text> <text class='tags' capture-bind:longpress="touchTag" bindtap='onHistorySearch' data-keyword="{{item}}">{{item}}</text>
<image src="../../image/delete.png" wx:if="{{currentTag==item}}" bindtap="clearOneTag"></image>
</view> </view>
</block> </block>
</view> </view>
......
...@@ -45,6 +45,20 @@ ...@@ -45,6 +45,20 @@
top: 14rpx; top: 14rpx;
display: block; display: block;
} }
.search-bar .search-box .delete {
width: 18rpx;
height: 18rpx;
position: absolute;
right: 50rpx;
top: -5rpx;
display: block;
z-index: 999;
}
.search-bar .search-box .delete image {
width: 32rpx;
height: 32rpx;
padding: 18rpx;
}
/* 历史搜索 */ /* 历史搜索 */
.history-search{ .history-search{
...@@ -68,7 +82,7 @@ ...@@ -68,7 +82,7 @@
height: 30rpx; height: 30rpx;
} }
.history-search .list { .history-search .list {
overflow: hidden; position: relative;
font-size: 26rpx; font-size: 26rpx;
text-align: center; text-align: center;
display: inline-block; display: inline-block;
...@@ -86,6 +100,13 @@ ...@@ -86,6 +100,13 @@
margin-bottom: 20rpx; margin-bottom: 20rpx;
padding: 10rpx 30rpx; padding: 10rpx 30rpx;
} }
.history-search .list image{
position: absolute;
right: 10rpx;
top: -10rpx;
width: 30rpx;
height: 30rpx;
}
/* 热门搜索 */ /* 热门搜索 */
.hot-search{ .hot-search{
......
...@@ -7,12 +7,13 @@ Page({ ...@@ -7,12 +7,13 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
page:1, list:[],
size:10,
keyword:'', keyword:'',
type:1, type:1,
list:[], page:1,
total:0 size:10,
total:0,
isloading:false
}, },
/** /**
...@@ -39,6 +40,17 @@ Page({ ...@@ -39,6 +40,17 @@ Page({
this.getListByKeyword(); this.getListByKeyword();
}, },
getListByKeyword(){ getListByKeyword(){
if(!this.data.keyword.trim()){
wx.showToast({
title: '请输入关键词!',
icon: 'none'
})
return
}
this.setData({
isloading:true
})
var params = { var params = {
page: this.data.page, page: this.data.page,
size: this.data.size, size: this.data.size,
...@@ -50,6 +62,9 @@ Page({ ...@@ -50,6 +62,9 @@ Page({
}else{ }else{
this.getReportListByKeyword(params); this.getReportListByKeyword(params);
} }
this.setData({
isloading:false
})
}, },
//根据关键词查询事件列表 //根据关键词查询事件列表
getEventListByKeyword(params){ getEventListByKeyword(params){
...@@ -57,16 +72,11 @@ Page({ ...@@ -57,16 +72,11 @@ Page({
// console.log(res) // console.log(res)
if(res){ if(res){
this.setData({ this.setData({
list:res.data.data.list, list:this.data.list.concat(res.data.data.list),
total:res.data.data.total total:res.data.data.total
}) })
} }
}).catch(() => { })
wx.showToast({
title: '请求失败!',
icon: 'none'
})
});
}, },
//根据关键词查询报告列表 //根据关键词查询报告列表
getReportListByKeyword(params){ getReportListByKeyword(params){
...@@ -74,24 +84,24 @@ Page({ ...@@ -74,24 +84,24 @@ Page({
// console.log(res) // console.log(res)
if(res){ if(res){
this.setData({ this.setData({
list:res.data.data.list, list:this.data.list.concat(res.data.data.list),
total:res.data.data.total total:res.data.data.total
}) })
} }
}).catch(() => { })
wx.showToast({
title: '请求失败!',
icon: 'none'
})
});
}, },
switchTap(e) { switchTap(e) {
var _type = e.currentTarget.dataset.type; var _type = e.currentTarget.dataset.type;
this.setData({ this.setData({
type: _type list:[],
type: _type,
page:1,
size:10,
total:0
}); });
this.getListByKeyword(); this.getListByKeyword();
}, },
//绑定输出内容
getSearchInput(e){ getSearchInput(e){
this.setData({ this.setData({
keyword: e.detail.value keyword: e.detail.value
...@@ -101,9 +111,42 @@ Page({ ...@@ -101,9 +111,42 @@ Page({
cancel(){ cancel(){
wx.navigateBack({}) wx.navigateBack({})
}, },
//搜索 //本页面再次搜索
search(){ search(){
this.getListByKeyword(); if(this.data.keyword.trim()){
wx.showLoading({
title: '加载中...'
})
let _keyword=this.data.keyword.trim();
// 记录搜索
let historySearch = wx.getStorageSync('historySearch') || [];
historySearch = historySearch.filter(item => item !== _keyword)
historySearch.unshift(_keyword);
if (historySearch.length>10){
historySearch.pop();
}
wx.setStorageSync('historySearch', historySearch);
//search-page传过来的trim过了,这里新绑定的没有
this.setData({
keyword: _keyword
})
this.getListByKeyword();
wx.hideLoading()
} else {
wx.showToast({
title: '请输入关键词!',
icon: 'none'
})
}
},
// 清除关键词
clearKeyword(){
this.setData({
keyword:''
})
}, },
/** /**
...@@ -131,7 +174,20 @@ Page({ ...@@ -131,7 +174,20 @@ Page({
* 页面上拉触底事件的处理函数 * 页面上拉触底事件的处理函数
*/ */
onReachBottom: function () { onReachBottom: function () {
// console.log("触底了")
if(this.data.page * this.data.size>=this.data.total){
//下一页无数据
return wx.showToast({
title: '没有下一页了!',
icon: 'none'
})
}
// 防止加载时刷新
if(this.data.isloading) return
this.setData({
page:this.data.page+1
})
this.getListByKeyword();
}, },
/** /**
......
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
"usingComponents": { "usingComponents": {
"eventList": "/components/eventList/eventList", "eventList": "/components/eventList/eventList",
"reportList": "/components/reportList/reportList" "reportList": "/components/reportList/reportList"
},
} "enablePullDownRefresh": true
} }
\ No newline at end of file
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
<view class='search-box'> <view class='search-box'>
<input class='sear-input' value="{{keyword}}" bindinput='getSearchInput' confirm-type='search' bindconfirm='search'></input> <input class='sear-input' value="{{keyword}}" bindinput='getSearchInput' confirm-type='search' bindconfirm='search'></input>
<image src='../../image/search.png' class='search-img'></image> <image src='../../image/search.png' class='search-img'></image>
<view class='delete' wx:if="{{keyword.length>0}}" bindtap="clearKeyword">
<image src='../../image/delete.png' ></image>
</view>
</view> </view>
<text class='cancel' bindtap='cancel'>取消</text> <text class='cancel' bindtap='cancel'>取消</text>
</view> </view>
......
...@@ -50,6 +50,20 @@ ...@@ -50,6 +50,20 @@
top: 14rpx; top: 14rpx;
display: block; display: block;
} }
.search-bar .search-box .delete {
width: 18rpx;
height: 18rpx;
position: absolute;
right: 50rpx;
top: -5rpx;
display: block;
z-index: 999;
}
.search-bar .search-box .delete image {
width: 32rpx;
height: 32rpx;
padding: 18rpx;
}
.fixed-box .tabs { .fixed-box .tabs {
width: 100%; width: 100%;
......
...@@ -5,11 +5,11 @@ const imgURL = baseURL+'/app/' ...@@ -5,11 +5,11 @@ const imgURL = baseURL+'/app/'
const request = function(url,options){ const request = function(url,options){
wx.getStorageSync('token') wx.getStorageSync('token')
let token = wx.getStorageSync('token') let token = wx.getStorageSync('token')
// if(url!='/mobile/login' && !token){ if(url!='/mobile/login' && !token){
// wx.reLaunch({ wx.reLaunch({
// url: '/pages/login/login', url: '/pages/login/login',
// }) })
// } }
return new Promise((resolve,reject)=>{ return new Promise((resolve,reject)=>{
wx.request({ wx.request({
url:baseURL+url, url:baseURL+url,
...@@ -24,6 +24,7 @@ const request = function(url,options){ ...@@ -24,6 +24,7 @@ const request = function(url,options){
resolve(res) resolve(res)
} else if(res.data.code == 401 || res.data.code == 402){ } else if(res.data.code == 401 || res.data.code == 402){
//token过期或者账号在其他地方登录 //token过期或者账号在其他地方登录
console.log('token过期或者账号在其他地方登录')
reject() reject()
wx.reLaunch({ wx.reLaunch({
url: '/pages/login/login', url: '/pages/login/login',
...@@ -63,7 +64,7 @@ const request = function(url,options){ ...@@ -63,7 +64,7 @@ const request = function(url,options){
// get // get
export const getRequest = (url, data) => { export const getRequest = (url, data) => {
// wx.showNavigationBarLoading() wx.showNavigationBarLoading()
return request(url,{ return request(url,{
method:"GET", method:"GET",
data data
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment