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.
147 lines
3.7 KiB
147 lines
3.7 KiB
// pages/moment/host-detail/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event.js')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
safeBottom: app.globalData.safeBottom,
|
|
height: app.globalData.fragmentHeight,
|
|
id: null,
|
|
hostDetail: null,
|
|
momentList: [],
|
|
top: 0,
|
|
requesting: false,
|
|
finished: false,
|
|
form: {
|
|
pageNum: 1
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({height: app.globalData.fragmentHeight})
|
|
if(options.id){
|
|
this.data.id = options.id
|
|
event.on('EventMessage', this, this.onEvent)
|
|
this.fetchMomentList()
|
|
}
|
|
},
|
|
onShow: function(){
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
mask: true
|
|
})
|
|
request.get('/information-center/paper-bar/get/' + this.data.id).then(result => {
|
|
//成功回调
|
|
this.setData({ hostDetail: result.data })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 501) {
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
onRefreshList: function () {
|
|
this.setData({
|
|
momentList: [],
|
|
['form.pageNum']: 1,
|
|
finished: false
|
|
})
|
|
this.fetchMomentList()
|
|
},
|
|
fetchMomentList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.setData({ requesting: true })
|
|
request.get('/information-center/get/post-list/in/' + this.data.id, 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
|
|
if(num == 1){
|
|
this.setData({
|
|
momentList: [],
|
|
requesting: false,
|
|
[nowList]: respList,
|
|
['form.pageNum']: (num + 1),
|
|
finished
|
|
})
|
|
} else {
|
|
this.setData({
|
|
[nowList]: respList,
|
|
requesting: false,
|
|
['form.pageNum']: (num + 1),
|
|
finished
|
|
})
|
|
}
|
|
} else {
|
|
this.setData({ finished: true, requesting: false })
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false })
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
addMoment: function () {
|
|
if(!this.data.hostDetail.join){
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
var that = this
|
|
this.wuxDialog.open({
|
|
resetOnClose: true,
|
|
title: '温馨提示',
|
|
content: '您还没有加入该纸吧,无法发帖,现在就加入纸吧?',
|
|
buttons: [{
|
|
text: '取消'
|
|
},{
|
|
text: '加入纸吧',
|
|
type: 'primary',
|
|
onTap(e) {
|
|
that.toHostinfo()
|
|
}
|
|
}]
|
|
})
|
|
return
|
|
}
|
|
wx.navigateTo({
|
|
url: '/pages/moment/create/index?barId=' + this.data.id
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面隐藏
|
|
*/
|
|
toHostinfo: function () {
|
|
if(this.data.hostDetail){
|
|
wx.navigateTo({
|
|
url: '/pages/moment/host-info/index?id=' + this.data.hostDetail.id
|
|
})
|
|
}
|
|
},
|
|
lookItem: function(e){
|
|
var item = this.data.momentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.navigateTo({
|
|
url: '/pages/moment/detail/index?type=1&id=' + item.id
|
|
})
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
}
|
|
})
|