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.
84 lines
2.3 KiB
84 lines
2.3 KiB
// pages/stock/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const event = require('../../../utils/event.js')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.safeFragmentHeight - 190,
|
|
firstShow: false,
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
form: {
|
|
categoryId: 1,
|
|
pageNum: 1
|
|
}
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if (!this.data.firstShow) {
|
|
this.setData({ height: app.globalData.safeFragmentHeight - 190, kg: app.globalData.kg })
|
|
this.onRefreshList()
|
|
}
|
|
this.data.firstShow = true
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 571) {
|
|
// 帖子发布刷新
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
//*************************************************momentList************************************************//
|
|
onRefreshList: function () {
|
|
this.setData({
|
|
momentList: [],
|
|
['form.pageNum']: 1,
|
|
finished: false
|
|
})
|
|
this.fetchMomentList()
|
|
},
|
|
fetchMomentList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.data.requesting = true
|
|
request.get('/information-center/article/get/Article-list/', this.data.form).then(result => {
|
|
//成功回调
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `momentList[${this.data.momentList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form.pageNum']: (num + 1),
|
|
finished,
|
|
requesting: false
|
|
})
|
|
} else {
|
|
this.setData({ finished: true, requesting: false })
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false })
|
|
})
|
|
}
|
|
}
|
|
})
|