|
|
// pages/service/renting/search/search.js
|
|
|
const app = getApp();
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
searchValue: '',
|
|
|
postList: [],
|
|
|
searchHistory:[{keyword:'法国巴黎'},{keyword:'埃菲尔铁塔'},{keyword:'北京'},{keyword:'西雅图'},{keyword:'美国洛杉矶'},{keyword:'北京'},{keyword:'北京'},{keyword:'北京'},],
|
|
|
currentModal: 0,
|
|
|
currentPost: 0,
|
|
|
hidden_img: false,
|
|
|
hasMore: true,
|
|
|
pageNumber: 0,
|
|
|
avatar: [],
|
|
|
},
|
|
|
//初始化postList
|
|
|
initPostList() {
|
|
|
this.setData({
|
|
|
pageNumber: 0,
|
|
|
hasMore: true,
|
|
|
});
|
|
|
this.data.postList = []
|
|
|
},
|
|
|
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: ''})
|
|
|
},
|
|
|
//搜索历史列表
|
|
|
getSearchHistory() {
|
|
|
let self = this;
|
|
|
let url = '/home/home/search_history';
|
|
|
let header = {
|
|
|
"XX-Token": wx.getStorageSync('token')
|
|
|
};
|
|
|
app.post(url, {}, header).then((res) => {
|
|
|
// console.log('搜索历史列表', res);
|
|
|
self.setData({
|
|
|
searchHistory: res
|
|
|
});
|
|
|
})
|
|
|
},
|
|
|
//点击搜索历史
|
|
|
clickHistory(e) {
|
|
|
const current = e.currentTarget.dataset.index;
|
|
|
const list = [{title:'温哥华+翡翠岛+路易斯湖五日游',time:'2018.4.28',name:'旦巴 在多伦多'}]//假数据
|
|
|
this.setData({
|
|
|
searchValue: this.data.searchHistory[current].keyword,
|
|
|
postList:list,
|
|
|
});
|
|
|
this.startSearch()
|
|
|
},
|
|
|
//清空历史搜索
|
|
|
clearHistory() {
|
|
|
let self = this;
|
|
|
let url = '/home/home/clear_search';
|
|
|
let header = {
|
|
|
"XX-Token": wx.getStorageSync('token')
|
|
|
};
|
|
|
app.post(url, {}, header).then((res) => {
|
|
|
// console.log('清空搜索历史列表', res);
|
|
|
self.getSearchHistory()
|
|
|
})
|
|
|
},
|
|
|
//个人信息弹框
|
|
|
showModal(e) {
|
|
|
let that = this;
|
|
|
const current = e.currentTarget.dataset.index;
|
|
|
if(that.data.currentModal === current) {
|
|
|
that.data.postList[current].showlabel_box = !that.data.postList[current].showlabel_box;
|
|
|
}else {
|
|
|
that.data.postList[current].showlabel_box = !that.data.postList[current].showlabel_box;
|
|
|
that.data.postList[that.data.currentModal].showlabel_box = false;
|
|
|
}
|
|
|
that.setData({
|
|
|
postList: that.data.postList,
|
|
|
currentModal: current
|
|
|
});
|
|
|
},
|
|
|
//复制微信号
|
|
|
clickCopy(e) {
|
|
|
const current = e.currentTarget.dataset.index;
|
|
|
wx.setClipboardData({
|
|
|
data: this.data.postList[current].wxn,
|
|
|
success:function (res) {
|
|
|
// console.log('复制微信号',res);
|
|
|
}
|
|
|
});
|
|
|
this.setData({
|
|
|
[`postList[${this.data.currentModal}].showlabel_box`]: false
|
|
|
});
|
|
|
},
|
|
|
//进入主页
|
|
|
enterHomePage(e) {
|
|
|
let self = this;
|
|
|
const current = e.currentTarget.dataset.index;
|
|
|
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/service/myindex/myindex?user_id=' + self.data.postList[current].user_id
|
|
|
});
|
|
|
self.setData({
|
|
|
[`postList[${self.data.currentModal}].showlabel_box`]: false
|
|
|
});
|
|
|
},
|
|
|
//举报
|
|
|
report(e) {
|
|
|
let self = this;
|
|
|
const current = e.currentTarget.dataset.index;
|
|
|
const to_user_id = self.data.postList[current].user_id;
|
|
|
const post_id = self.data.postList[current].id;
|
|
|
wx.navigateTo({url:'/pages/report/report?to_user_id=' + to_user_id + '&post_id=' + post_id});
|
|
|
self.setData({
|
|
|
[`postList[${self.data.currentModal}].showlabel_box`]: false
|
|
|
});
|
|
|
},
|
|
|
//查看文章详情
|
|
|
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,
|
|
|
})
|
|
|
|
|
|
},
|
|
|
//收藏、取消收藏
|
|
|
delArticles(e) {
|
|
|
let self = this;
|
|
|
const current = e.currentTarget.dataset.index;
|
|
|
let url = '/home/home/collect';
|
|
|
let url_del = '/home/home/collect_del';
|
|
|
let header = {
|
|
|
"XX-Token": wx.getStorageSync('token')
|
|
|
};
|
|
|
let params = {
|
|
|
id: self.data.postList[current].id,
|
|
|
};
|
|
|
if(self.data.postList[current].is_hits) {
|
|
|
app.post(url_del, params, header).then((res) => {
|
|
|
// console.log('取消收藏', res);
|
|
|
if(res.message == "操作成功") {
|
|
|
self.setData({
|
|
|
[`postList[${current}].is_hits`]: 0
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
}else {
|
|
|
app.post(url, params, header).then((res) => {
|
|
|
// console.log('收藏', res);
|
|
|
if(res.message == "操作成功") {
|
|
|
self.setData({
|
|
|
[`postList[${current}].is_hits`]: 1
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
//点赞/取消赞
|
|
|
clickZan(e) {
|
|
|
let self = this;
|
|
|
let current = e.currentTarget.dataset.index;
|
|
|
let postList = self.data.postList;
|
|
|
let url = '/home/home/like';
|
|
|
let url_del = '/home/home/like_del';
|
|
|
let header = {
|
|
|
"XX-Token": wx.getStorageSync('token')
|
|
|
};
|
|
|
let params = {
|
|
|
id: self.data.postList[current].id,
|
|
|
};
|
|
|
if(postList[current].is_paise) {
|
|
|
app.post(url_del, params, header).then((res) => {
|
|
|
// console.log('取消赞', res);
|
|
|
if(res.message == "操作成功") {//局部刷新赞数和头像
|
|
|
const post_like = postList[current].post_like - 1;
|
|
|
self.setData({
|
|
|
[`postList[${current}].is_paise`]: 0,
|
|
|
[`postList[${current}].post_like`]: post_like,
|
|
|
});
|
|
|
const paise_user = [];
|
|
|
postList[current].paise_user.map((item) => {
|
|
|
if(item !== res.data) {
|
|
|
paise_user.push(item)
|
|
|
}
|
|
|
});
|
|
|
self.setData({
|
|
|
[`postList[${current}].paise_user`]: paise_user,
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
}else {
|
|
|
app.post(url, params, header).then((res) => {
|
|
|
// console.log('点赞', res);
|
|
|
if(res.message == "操作成功") {//局部刷新赞数和头像
|
|
|
const post_like = postList[current].post_like + 1;
|
|
|
self.setData({
|
|
|
[`postList[${current}].is_paise`]: 1,
|
|
|
[`postList[${current}].post_like`]: post_like,
|
|
|
});
|
|
|
if(postList[current].paise_user !== undefined) {
|
|
|
const paise_user = postList[current].paise_user;
|
|
|
self.setData({
|
|
|
[`postList[${current}].paise_user`]: paise_user.concat(res.data),
|
|
|
})
|
|
|
}else {
|
|
|
const paise_user = [];
|
|
|
paise_user.push(res.data);
|
|
|
self.setData({
|
|
|
[`postList[${current}].paise_user`]: paise_user,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
//去评论
|
|
|
goComment() {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/service/comment/comment?post_id=' +
|
|
|
this.data.postList[this.data.currentPost].id +
|
|
|
'&is_post_list=' + true
|
|
|
})
|
|
|
},
|
|
|
//获取用户id
|
|
|
personInfo() {
|
|
|
let url = '/home/me/index';
|
|
|
let header = {
|
|
|
"XX-Token": wx.getStorageSync('token')
|
|
|
};
|
|
|
let params = {}
|
|
|
app.post(url, params, header).then((res) => {
|
|
|
console.log(res)
|
|
|
this.setData({
|
|
|
userId: res.id,
|
|
|
});
|
|
|
console.log(this.data.userId)
|
|
|
})
|
|
|
},
|
|
|
onLoad: function (options) {
|
|
|
const self = this;
|
|
|
self.setData({
|
|
|
id: +options.id,
|
|
|
order: +options.order,
|
|
|
select_id: +options.select_id,
|
|
|
});
|
|
|
self.personInfo();
|
|
|
self.getSearchHistory();
|
|
|
},
|
|
|
refreshPostCollect() {
|
|
|
const postList = this.data.postList;
|
|
|
const currentPost = this.data.currentPost;
|
|
|
// console.log('刷新前长度', postList[currentPost].is_hits);
|
|
|
if(this.data.is_collect) {
|
|
|
this.setData({
|
|
|
[`postList[${currentPost}].is_hits`]: 1,
|
|
|
})
|
|
|
}else {
|
|
|
this.setData({
|
|
|
[`postList[${currentPost}].is_hits`]: 0,
|
|
|
})
|
|
|
}
|
|
|
// console.log('刷新后长度', postList[currentPost].is_hits);
|
|
|
},
|
|
|
refreshPostComment() {
|
|
|
const postList = this.data.postList;
|
|
|
const currentPost = this.data.currentPost;
|
|
|
// console.log('刷新前长度', postList[currentPost].comments.length);
|
|
|
if(this.data.is_comment) {
|
|
|
this.setData({[`postList[${currentPost}].comments[0].length`]: this.data.length})
|
|
|
}
|
|
|
// console.log('刷新后长度', postList[currentPost].comments[0].length);
|
|
|
},
|
|
|
refreshPostLike() {
|
|
|
const postList = this.data.postList;
|
|
|
const currentPost = this.data.currentPost;
|
|
|
if(this.data.is_paise) {
|
|
|
const post_like = postList[currentPost].post_like +1;
|
|
|
this.setData({
|
|
|
[`postList[${currentPost}].is_paise`]: 1,
|
|
|
[`postList[${currentPost}].post_like`]: post_like,
|
|
|
[`postList[${currentPost}].paise_user`]: this.data.paise_user,
|
|
|
})
|
|
|
// console.log('点赞', postList[currentPost].post_like);
|
|
|
}else {
|
|
|
const post_like = postList[currentPost].post_like -1;
|
|
|
this.setData({
|
|
|
[`postList[${currentPost}].is_paise`]: 0,
|
|
|
[`postList[${currentPost}].post_like`]: post_like,
|
|
|
[`postList[${currentPost}].paise_user`]: this.data.paise_user,
|
|
|
})
|
|
|
// console.log('取消赞', postList[currentPost].post_like);
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
|
onReady: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
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 () {
|
|
|
|
|
|
}
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|