作者 吴孟雨

优化搜索页、详情页

<!--pages/my/myindex/myindex.wxml-->
<block wx:if='{{userId==user.id}}'>
<view class='bannr_box' bindtap='uoloadImg'>
<view class='banner_box' bindtap='uoloadImg'>
<image class='banner_img' src='{{user.thumbnail}}'></image>
</view>
</block>
<block wx:else>
<view class='bannr_box' >
<view class='banner_box' >
<image class='banner_img' src='{{user.thumbnail}}'></image>
</view>
</block>
... ... @@ -17,11 +17,15 @@
</view>
</view>
<view class='content_box'>
<view class='item_list' wx:for='{{portal_post}}' wx:key=''>
<view wx:if="{{portal_post.length === 0}}" class="no-post">Ta还没有发表过文章~</view>
<view class='item_list' wx:for='{{portal_post}}' wx:key='' wx:if="{{portal_post.length > 0}}">
<block wx:if='{{item.is_top==1}}'>
<view class='list_title'>置顶</view>
</block>
<block wx:else=''>
<!--<block wx:if="{{item.time === '昨天' || item.time === '今天'||item.time === '前天'}}">-->
<!--<view class='list_title'>{{item.time}}</view>-->
<!--</block>-->
<block wx:if="{{item.time === '昨天' || item.time === '今天'||item.time === '前天'}}">
<view class='list_title'>{{item.time}}</view>
</block>
... ...
... ... @@ -70,7 +70,7 @@ Page({
},
getPost(url,params,header) {
app.post(url,params,header).then((res) => {
// console.log('三级分类', res);
console.log('三级分类', res);
this.setData({
portal_three: res,
// postImg: postImg
... ... @@ -90,11 +90,19 @@ Page({
};
self.getPost(url,params,header)
}else {
if(self.data.currentPortalOne === 2 || self.data.currentPortalOne === 3) {
let params = {
id: self.data.portal_two.category[self.data.value[0]].id,
};
console.log(('2-3'));
self.getPost(url,params,header)
}else {
let params = {
id: self.data.portal_two.category[self.data.value[1]].id,
};
self.getPost(url,params,header)
}
}
},
//点击一级分类
choosePortalOne(e) {
... ... @@ -111,10 +119,28 @@ Page({
},
// 滑动picker
bindChangePicker(e) {
console.log(e);
if(this.data.currentPortalOne === 2 || this.data.currentPortalOne === 3) {
if(e.detail.value[0] !== this.data.value[0] || e.detail.value[0] === this.data.value[0]) {
console.log('id',this.data.portal_two.category[this.data.value[0]].id);
this.getPortalThree()
}
}
this.setData({value: e.detail.value});
if(this.data.currentPortalOne !== 6 && this.data.currentPortalOne !== 7) {
console.log(e.detail.value);
if(this.data.currentPortalOne !== 6 && this.data.currentPortalOne !== 7 &&
this.data.currentPortalOne !== 2 && this.data.currentPortalOne !== 3
) {
this.getPortalThree()
}
// if(this.data.currentPortalOne === 2 || this.data.currentPortalOne === 3) {
// console.log(this.data.portal_two.category[this.data.value[0]].name);
// var name = this.data.portal_two.category[this.data.value[0]].name;
// if(name === '招租' || name === '求租') {
// console.log('调接口');
// this.getPortalThree()
// }
// }
},
//确定提交picker
submitPicker() {
... ... @@ -165,7 +191,7 @@ Page({
this.data.currentPortalOne === 4|| this.data.currentPortalOne === 5){
this.setData({
last_category_id:this.data.portal_three.category[this.data.value[1]].id,
select_id: this.data.portal_two.category[this.data.value[0]].id
select_id: this.data.portal_two.select[this.data.value[0]].id
});
}else {
this.setData({
... ... @@ -324,7 +350,7 @@ Page({
let header = {
"XX-Token": wx.getStorageSync('token')
};
// console.log(self.data.last_category_id, self.data.select_id,self.data.images);
console.log(self.data,self.data.last_category_id, self.data.select_id,self.data.images);
let params = {
category_id: self.data.last_category_id,//最后选的分类的id
type: self.data.select_id !== ''?self.data.select_id: '',//select_id,没有不传
... ...
... ... @@ -10,6 +10,7 @@ Page({
postList: [],
currentModal: 0,
currentPost: 0,
hidden_img: false,
},
//输入搜索内容
inputKey(e) {
... ... @@ -108,17 +109,48 @@ Page({
},
//复制微信号
clickCopy(e) {
const current = e.currentTarget.dataset.index;
wx.setClipboardData({
data: this.data.postList[this.data.currentPost].user_nickname,
data: this.data.postList[current].wxn,
success:function (res) {
// console.log('复制微信号',res);
}
})
});
this.setData({
[`postList[${this.data.currentModal}].showlabel_box`]: false
});
},
//进入主页
enterHomePage() {
enterHomePage(e) {
let self = this;
const current = e.currentTarget.dataset.index;
wx.navigateTo({
url: '/pages/my/myindex/myindex'
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;
let url = '/home/home/report';
let header = {
"XX-Token": wx.getStorageSync('token')
};
let params = {
to_user_id: self.data.postList[current].user_id,
post_id: self.data.postList[current].id,
};
app.post(url, params, header).then((res) => {
// console.log('举报', res);
wx.showToast({title: '举报成功',icon: 'none'});
// this.data.postList[this.data.currentModal].showlabel_box = false;
self.setData({
[`postList[${self.data.currentModal}].showlabel_box`]: false
});
})
},
//查看文章详情
... ... @@ -193,6 +225,21 @@ Page({
'&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({
... ... @@ -200,7 +247,8 @@ Page({
order: +options.order,
select_id: +options.select_id,
});
self.getSearchHistory()
self.personInfo();
self.getSearchHistory();
},
/**
... ...
... ... @@ -48,17 +48,19 @@
</view>
<view class="copy">
<view class='line'>|</view>
<view class='label-text' catchtap="clickCopy">复制</view>
<view class='label-text' catchtap="clickCopy" data-index="{{index}}">复制</view>
<view class='line'>|</view>
<view class='label-text' catchtap="enterHomePage">
<view class='label-text' catchtap="enterHomePage" data-index="{{index}}">
<text class='iconfont icon-jubao0201'></text>
<text>进入主页</text>
</view>
<block wx:if="{{userId !== item.user_id}}">
<view class='line'>|</view>
<view class='label-text'>
<view class='label-text' catchtap="report" data-index="{{index}}">
<text class='iconfont icon-jubao0201'></text>
<text>举报</text>
</view>
</block>
</view>
</view>
</view>
... ... @@ -95,10 +97,7 @@
</view>
</block>
<view class='list_content'>{{item.post_content}}</view>
<view class='list_img_box'>
<!--<block wx:for="{{postImg}}" wx:key="index">-->
<!--<image src='{{item.url}}' wx:for="{{item.photos}}" wx:key="index"></image>-->
<!--</block>-->
<view class='list_img_box' wx:if="{{item.more.photos[0].url !== ''}}">
<block wx:for="{{item.more.photos}}" wx:key="index">
<image src='{{item.url}}'></image>
</block>
... ...
... ... @@ -10,7 +10,6 @@ Page({
post_id: '',
type: '',
id: '',
hidden_img: false,
},
//回复
reply(e) {
... ... @@ -61,24 +60,48 @@ Page({
},
//复制微信号
clickCopy(e) {
clickCopy() {
wx.setClipboardData({
data: this.data.postList.wxn,
success: function(res) {
// console.log('复制微信号', res);
}
});
this.setData({
showlabel_box: false
})
},
//进入主页
enterHomePage(e) {
enterHomePage() {
let self = this;
const current = e.currentTarget.dataset.index;
// // console.log(current);
wx.navigateTo({
url: '/pages/service/myindex/myindex?user_id=' + self.data.postList.user_id
});
this.setData({
showlabel_box: false
})
},
//举报
report() {
let self = this;
let url = '/home/home/report';
let header = {
"XX-Token": wx.getStorageSync('token')
};
let params = {
to_user_id: self.data.postList.user_id,
post_id: self.data.postList.id,
};
app.post(url, params, header).then((res) => {
// console.log('举报', res);
wx.showToast({title: '举报成功',icon: 'none'});
// this.data.postList[this.data.currentModal].showlabel_box = false;
self.setData({
showlabel_box: false
})
})
},
//获取文章详情
getPostDetail() {
let self = this;
... ... @@ -90,21 +113,18 @@ Page({
id: self.data.post_id,
};
app.post(url, params, header).then((res) => {
// console.log('文章详情', res);
console.log('more', res[0].more);
if (res[0].more !== null) {
const postImg = res.map((item) => {
return JSON.parse(item.more);
});
self.setData({
postList: res[0],
postImg: postImg
});
self.data.postImg.forEach((item,index) => {
item.photos.forEach((item) => {
if(item.url === "") {
self.setData({hidden_img: true})
}
self.setData({
postList: res[0],
})
});//判断没有发布图片时显示空
})
},
... ...
... ... @@ -25,7 +25,7 @@
<text class='iconfont icon-zhuye'></text>
<text>进入主页</text>
</view>
<block wx:if="{{userId !== postList.user_id}}">
<block wx:if="{{userId !== postList.user_id}}" catchtap="report">
<view class='line'>|</view>
<view class='label-text'>
<text class='iconfont icon-jubao0201'></text>
... ... @@ -69,7 +69,7 @@
</view>
</block>
<view class='list_content'>{{postList.post_content}}</view>
<view class='list_img_box' wx:if="{{!hidden_img}}">
<view class='list_img_box'>
<block wx:for="{{postImg}}" wx:key="index">
<image src='{{item.url}}' wx:for="{{item.photos}}" wx:key="index"
data-index="{{index}}" bindtap="previewImg"></image>
... ...