纸通宝小程序
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.
 

98 lines
2.7 KiB

// pages/stock/index.js
import { getPreferList } from "../../api/moment"
const event = require('../../../utils/event.js')
const app = getApp()
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
/**
* 页面的初始数据
*/
data: {
height: app.globalData.safeFragmentHeight - 90,
userInfo: null,
momentList: [],
requesting: false,
finished: false,
form: {
categoryId: 3,
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 - 90, userInfo: app.globalData.userInfo })
}
if (this.data.momentList.length <= 0) {
this.onRefreshList()
}
this.data.firstShow = true
},
onEvent: function (message) {
if (message.what == 573) {
// 帖子发布刷新
this.onRefreshList()
} else if(message.what == 200 || message.what == 888){
// Vip的变化
this.setData({ userInfo: app.globalData.userInfo })
this.onRefreshList()
}
},
//*************************************************momentList************************************************//
onRefreshList: function () {
if(!app.globalData.userInfo || !app.globalData.userInfo.isVIP){
this.setData({ requesting: false })
return
}
if (this.data.requesting) {
return
}
this.setData({ momentList: [], ['form.pageNum']: 1, finished: false })
this.fetchMomentList()
},
fetchMomentList: function(){
if (this.data.requesting || this.data.finished) {
return
}
this.data.requesting = true
getPreferList(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({ requesting: false })
}
}).catch(err => {
this.setData({ requesting: false })
})
},
toVip: function(){
if(!app.globalData.userInfo){
wx.navigateTo({ url: '/pages/login/index' })
return
}
wx.navigateTo({ url: '/pages/ztbvip/index' })
}
}
})