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.
178 lines
4.8 KiB
178 lines
4.8 KiB
// pages/bidding/index/index.js
|
|
import { getMyList, getReplyList, getViewedList, deleteMoment } from "../../../api/moment"
|
|
const util = require('../../../utils/util')
|
|
const event = require('../../../utils/event.js')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
tabList: [ '我发布的', '我评论的', '最近浏览' ],
|
|
tabIndex: 0,
|
|
top: 0,
|
|
messageList: [],
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize:15
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({ height: app.globalData.fragmentHeight - 90, CustomBar: app.globalData.CustomBar })
|
|
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: [],
|
|
tabIndex: this.data.tabIndex,
|
|
['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 })
|
|
}
|
|
if(this.data.tabIndex == 0){
|
|
getMyList(this.data.form).then(result => {
|
|
this.doResult(result)
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
} else if(this.data.tabIndex == 1){
|
|
getReplyList(this.data.form).then(result => {
|
|
this.doResult(result)
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
} else if(this.data.tabIndex == 2){
|
|
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 })
|
|
}
|
|
},
|
|
onTabChange: function ({detail}) {
|
|
if (this.data.tabIndex == Number(detail.index)) {
|
|
return
|
|
}
|
|
this.data.tabIndex = Number(detail.index)
|
|
this.onRefreshList()
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
},
|
|
showMenu: function(e){
|
|
var that = this
|
|
var item = this.data.messageList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.showActionSheet({
|
|
itemList: ['编辑', '删除'],
|
|
success(res){
|
|
if (res.tapIndex === 0){
|
|
that.editMoment(item)
|
|
}else if (res.tapIndex === 1){
|
|
that.deleteMoment(item)
|
|
}
|
|
}
|
|
})
|
|
},
|
|
editMoment: function(item){
|
|
wx.navigateTo({ url: '/pages/article/publish/index?id=' + item.id })
|
|
},
|
|
deleteMoment: function(item){
|
|
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) {
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
deleteMoment({id: item.id}).then(result => {
|
|
wx.hideLoading()
|
|
util.showToast('删除成功')
|
|
that.onRefreshList()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
}]
|
|
})
|
|
}
|
|
})
|