You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
175 lines
4.9 KiB
175 lines
4.9 KiB
const api = require('../../../../utils/api')
|
|
import { getTimestamp } from '../../../../utils/common'
|
|
const app = getApp()
|
|
|
|
Component({
|
|
data: {
|
|
issueType: 'new',
|
|
pageNo: 1,
|
|
pageSize: 10,
|
|
timestamp: '',
|
|
issueList: [],
|
|
preloadVisible: true,
|
|
issueLoadMoreVisible: false,
|
|
loadMoreType: 'loading',
|
|
selectedIssueId: ''
|
|
},
|
|
lifetimes: {
|
|
attached () {
|
|
this.getIssueList ()
|
|
this.pulldownrefresh = this.selectComponent('#pulldownrefresh')
|
|
this.triggerEvent('getIssueComponent')
|
|
}
|
|
},
|
|
pageLifetimes: {
|
|
show () {
|
|
if (!app.globalData.previewImage) {
|
|
this.backAndRefreshIssueList()
|
|
}
|
|
app.globalData.previewImage = false
|
|
}
|
|
},
|
|
methods: {
|
|
// 页面滚动监听
|
|
onPageScroll (e) {
|
|
this.pulldownrefresh.onPageScroll(e)
|
|
},
|
|
onReachBottom () {
|
|
this.setData({
|
|
issueLoadMoreVisible: true
|
|
})
|
|
if (this.data.loadMoreType === 'loading') {
|
|
this.data.pageNo += 1
|
|
this.pullDownGetIssueList()
|
|
}
|
|
},
|
|
// 最新最热 tab切换
|
|
changeIssueType () {
|
|
if (this.data.issueType === 'new') {
|
|
this.setData({
|
|
issueType: 'hot',
|
|
preloadVisible: true,
|
|
issueList: [],
|
|
pageNo: 1,
|
|
issueLoadMoreVisible: false
|
|
})
|
|
this.getIssueList()
|
|
} else {
|
|
this.setData({
|
|
issueType: 'new',
|
|
preloadVisible: true,
|
|
issueList: [],
|
|
pageNo: 1,
|
|
issueLoadMoreVisible: false
|
|
})
|
|
this.getIssueList()
|
|
}
|
|
},
|
|
// 下拉刷新 获取议题列表
|
|
getIssueList () {
|
|
this.setData({
|
|
timestamp: getTimestamp(),
|
|
preloadVisible: true,
|
|
issueList: [],
|
|
pageNo: 1,
|
|
issueLoadMoreVisible: false
|
|
})
|
|
const para = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: '',
|
|
orderType: this.data.issueType === 'new' ? '0' : '1',
|
|
firstCategoryCode: ''
|
|
}
|
|
api.getIssueList(para).then(res => {
|
|
this.pulldownrefresh.stopRefresh()
|
|
console.log('获取议题列表', res)
|
|
this.setData({
|
|
issueList: [...res.data],
|
|
preloadVisible: false,
|
|
loadMoreType: res.data.length === 10 ? 'loading' : 'none'
|
|
})
|
|
}).catch(err => {
|
|
this.pulldownrefresh.stopRefresh()
|
|
this.setData({
|
|
issueList: [],
|
|
preloadVisible: false,
|
|
loadMoreType: 'none'
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 上拉加载更多
|
|
pullDownGetIssueList () {
|
|
const para = {
|
|
pageIndex: this.data.pageNo,
|
|
pageSize: this.data.pageSize,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: '',
|
|
orderType: this.data.issueType === 'new' ? '0' : '1',
|
|
firstCategoryCode: ''
|
|
}
|
|
api.getIssueList(para).then(res => {
|
|
console.log('获取议题列表', res)
|
|
this.setData({
|
|
issueList: [...this.data.issueList,...res.data],
|
|
preloadVisible: false,
|
|
loadMoreType: res.data.length === 10 ? 'loading' : 'none'
|
|
})
|
|
}).catch(err => {
|
|
this.setData({
|
|
issueList: [],
|
|
preloadVisible: false,
|
|
loadMoreType: 'none'
|
|
})
|
|
console.log(err)
|
|
})
|
|
},
|
|
// 跳转详情
|
|
navigateToIssueDetail (e) {
|
|
this.data.selectedIssueId = e.detail.issueId
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/discussionDetail/discussionDetail?type=issue&detailId=${e.detail.issueId}&showClassify=show`
|
|
})
|
|
},
|
|
// 跳转搜索页面
|
|
navigateToSearchDiscussion () {
|
|
wx.navigateTo({
|
|
url: `/subpages/discussion/pages/searchDiscussion/searchDiscussion?type=issue`
|
|
})
|
|
},
|
|
// 详情回列表,更新状态
|
|
backAndRefreshIssueList () {
|
|
if (this.data.selectedIssueId) {
|
|
const para = {
|
|
pageIndex: 1,
|
|
pageSize: 10,
|
|
timestamp: this.data.timestamp,
|
|
searchContent: '',
|
|
orderType: this.data.issueType === 'new' ? '0' : '1',
|
|
firstCategoryCode: '',
|
|
issueId: this.data.selectedIssueId
|
|
}
|
|
api.getIssueList(para).then(res => {
|
|
console.log('详情回列表,筛选刷新', res)
|
|
if (res.data.length === 1) {
|
|
this.data.issueList.forEach((item,index) => {
|
|
if (item.id === this.data.selectedIssueId) {
|
|
this.data.issueList.splice(index, 1, res.data[0])
|
|
}
|
|
})
|
|
} else {
|
|
const index = this.data.issueList.findIndex(item => item.id === this.data.selectedIssueId)
|
|
this.data.issueList.splice(index, 1)
|
|
}
|
|
this.setData({
|
|
issueList: this.data.issueList
|
|
})
|
|
}).finally(() => {
|
|
this.data.selectedIssueId = ''
|
|
})
|
|
}
|
|
}
|
|
}
|
|
})
|