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.
114 lines
3.7 KiB
114 lines
3.7 KiB
// pages/message/index.js
|
|
const request = require('../../utils/request');//导入模块
|
|
const util = require('../../utils/util');
|
|
const float = require('../../utils/floatObj');
|
|
const app = getApp()
|
|
const formate = 'Y-M-D'
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight - 100,
|
|
loading: true,
|
|
finished: false,
|
|
requesting: false,
|
|
messageList: [],
|
|
form: {
|
|
pageSize: 10,
|
|
pageNum: 1
|
|
},
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if (!this.data.firstShow) {
|
|
console.log('message-->onRestart>>>')
|
|
this.fetchMessageList()
|
|
}
|
|
this.setData({ firstShow: true })
|
|
},
|
|
onRefresh: function () {
|
|
this.setData({ ['form.pageNum']: 1, finished: false })
|
|
this.fetchMessageList()
|
|
},
|
|
fetchMessageList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if (this.data.form.pageNum == 1 && this.data.messageList.length == 0) {
|
|
this.setData({ loading: true })
|
|
}
|
|
this.setData({ requesting: true })
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
// /message/h5/message_list 消息列表
|
|
request.get('/message/h5/message_list', this.data.form).then(data => {
|
|
//成功回调
|
|
this.setData({ requesting: false, loading: false })
|
|
wx.hideLoading()
|
|
if (data.data.records) {
|
|
var respList = data.data.records
|
|
var lastTipsTime = ''
|
|
if (this.data.messageList.length > 0) {
|
|
lastTipsTime = util.formatDate(new Date(this.data.messageList.slice(-1).createTime), formate)
|
|
if (lastTipsTime.length > 10) {
|
|
lastTipsTime = lastTipsTime.substring(0, 10)
|
|
}
|
|
}
|
|
for (let i = 0; i < respList.length; i++) {
|
|
if (util.isEmpty(lastTipsTime)) {
|
|
lastTipsTime = util.formatDate(new Date(respList[i].createTime), formate)
|
|
if (lastTipsTime.length > 10) {
|
|
lastTipsTime = lastTipsTime.substring(0, 10)
|
|
}
|
|
respList[i].tipsTime = lastTipsTime
|
|
} else {
|
|
var itemTime = util.formatDate(new Date(respList[i].createTime), formate)
|
|
if (itemTime.length > 10) {
|
|
itemTime = itemTime.substring(0, 10)
|
|
}
|
|
if (lastTipsTime !== itemTime) {
|
|
respList[i].tipsTime = itemTime
|
|
}
|
|
lastTipsTime = itemTime
|
|
}
|
|
}
|
|
if (this.data.form.pageNum > 1) {
|
|
this.setData({ messageList: this.data.messageList.concat(respList) })
|
|
} else {
|
|
this.setData({ total: data.data.total, messageList: respList })
|
|
}
|
|
if (this.data.form.pageNum >= data.data.pages) {
|
|
// 已经是最后一页了,不需要再触发滚动加载了
|
|
this.setData({ finished: true })
|
|
} else {
|
|
var num = this.data.form.pageNum
|
|
this.setData({ ['form.pageNum']: (num + 1), finished: false })
|
|
}
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false, loading: false })
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
});
|
|
},
|
|
lookMessage: function (e) {
|
|
var item = this.data.messageList[e.currentTarget.dataset.index]
|
|
this.readMessage(item.id, e.currentTarget.dataset.index)
|
|
wx.navigateTo({ url: '/pages/order/order-info/index?id=' + item.scene })
|
|
},
|
|
readMessage: function (id, index) {
|
|
// /message/h5/read 设置已读
|
|
request.put('/message/h5/read/' + id).then(data => {
|
|
this.setData({ ['messageList[' + index + '].readStatus']: 1 })
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
})
|