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.
86 lines
2.6 KiB
86 lines
2.6 KiB
import { getViewedList } from "../../../api/moment"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event.js')
|
|
const tdsdk = require('../../../libs/tdweapp')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
data: {
|
|
height: app.globalData.fragmentHeight,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
top: 0,
|
|
messageList: [],
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize:15
|
|
}
|
|
},
|
|
onLoad: function (options) {
|
|
this.setData({ height: app.globalData.fragmentHeight })
|
|
event.on('EventMessage', this, this.onEvent)
|
|
this.fetchMessageList()
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 501) {
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({ messageList: [], ['form.pageNum']: 1, loading: true, finished: false })
|
|
this.fetchMessageList()
|
|
},
|
|
fetchMessageList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if (this.data.loading) {
|
|
this.data.requesting = true
|
|
} else {
|
|
this.setData({ requesting: true })
|
|
}
|
|
getViewedList(this.data.form).then(result => {
|
|
this.doResult(result)
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
doResult: function(result){
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `messageList[${this.data.messageList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
if(this.data.form.pageNum == 1){
|
|
this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false })
|
|
} else {
|
|
this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
|
|
}
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false })
|
|
}
|
|
},
|
|
lookItem: function (e) {
|
|
var item = this.data.messageList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
if(item.articleDetailDto && this.data.tabIndex == 1){
|
|
wx.navigateTo({ url: '/pages/article/detail/index?id=' + item.articleDetailDto.id })
|
|
} else {
|
|
wx.navigateTo({ url: '/pages/article/detail/index?id=' + item.id })
|
|
}
|
|
},
|
|
onShow: function () {
|
|
tdsdk.Page.onShow()
|
|
},
|
|
onHide: function(){
|
|
tdsdk.Page.onHide()
|
|
},
|
|
onUnload: function(){
|
|
tdsdk.Page.onUnload()
|
|
event.remove('EventMessage', this)
|
|
}
|
|
})
|