...
|
...
|
@@ -15,14 +15,21 @@ Page({ |
|
|
hasMore: true,
|
|
|
pageNumber: 0,
|
|
|
avatar: [],
|
|
|
is_write:2,//1:已填写,2:未填写
|
|
|
},
|
|
|
//初始化postList
|
|
|
initPostList() {
|
|
|
this.setData({
|
|
|
pageNumber: 0,
|
|
|
hasMore: true,
|
|
|
});
|
|
|
this.data.postList = []
|
|
|
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:[]})
|
...
|
...
|
@@ -32,273 +39,163 @@ Page({ |
|
|
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;
|
|
|
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 url = '/portal/Active/findRes';
|
|
|
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,
|
|
|
token: wx.getStorageSync('token'),
|
|
|
keyword:self.data.searchValue,
|
|
|
};
|
|
|
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
|
|
|
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
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
})
|
|
|
},
|
|
|
//清空输入框
|
|
|
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
|
|
|
//点击热门搜索
|
|
|
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;
|
|
|
const list = [{title:'温哥华+翡翠岛+路易斯湖五日游',time:'2018.4.28',name:'旦巴 在多伦多'}]//假数据
|
|
|
this.setData({
|
|
|
searchValue: this.data.searchHistory[current].keyword,
|
|
|
postList:list,
|
|
|
searchValue: this.data.history[current].title,
|
|
|
});
|
|
|
this.startSearch()
|
|
|
wx.showLoading({title: '加载中',});
|
|
|
this.startSearch();
|
|
|
this.getSearchHistory()
|
|
|
},
|
|
|
//清空历史搜索
|
|
|
clearHistory() {
|
|
|
let self = this;
|
|
|
let url = '/home/home/clear_search';
|
|
|
let header = {
|
|
|
"XX-Token": wx.getStorageSync('token')
|
|
|
let url = '/portal/Active/delHistory';
|
|
|
let params = {
|
|
|
token: wx.getStorageSync('token'),
|
|
|
};
|
|
|
app.post(url, {}, header).then((res) => {
|
|
|
// console.log('清空搜索历史列表', res);
|
|
|
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()
|
|
|
})
|
|
|
},
|
|
|
//个人信息弹框
|
|
|
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,
|
|
|
})
|
|
|
// //查看文章详情
|
|
|
// 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')
|
|
|
};
|
|
|
// },
|
|
|
//获取热门搜索和搜索历史
|
|
|
getSearchHistory() {
|
|
|
const self = this;
|
|
|
let url = '/portal/Active/find';
|
|
|
let params = {
|
|
|
id: self.data.postList[current].id,
|
|
|
// activeId: self.data.detail_id,
|
|
|
token: wx.getStorageSync('token'),
|
|
|
};
|
|
|
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;
|
|
|
// let header = {
|
|
|
// "token": wx.getStorageSync('token')
|
|
|
// };
|
|
|
app.post(url, params, {}).then((res) => {
|
|
|
console.log('获取热门搜索和搜索历史', res);
|
|
|
if (+res.code === 1) {
|
|
|
wx.hideLoading();
|
|
|
self.setData({
|
|
|
[`postList[${current}].is_paise`]: 1,
|
|
|
[`postList[${current}].post_like`]: post_like,
|
|
|
hot: res.data.hot,
|
|
|
history:res.data.history
|
|
|
// end_time: res.data.active.time,
|
|
|
// over_hours:res.data.active.over_time,//几小时截止
|
|
|
});
|
|
|
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,
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
// self.countDown();
|
|
|
}
|
|
|
},
|
|
|
//去评论
|
|
|
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)
|
|
|
// wx.hideLoading()
|
|
|
})
|
|
|
|
|
|
},
|
|
|
onLoad: function (options) {
|
|
|
const self = this;
|
...
|
...
|
@@ -307,54 +204,8 @@ Page({ |
|
|
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);
|
|
|
}
|
|
|
},
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
...
|
...
|
@@ -366,7 +217,7 @@ Page({ |
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
|
|
|
wx.showLoading({title: '加载中',});
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
|