messageDetail.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import MessageService from '../MessageService.js'
import { formatTimeByDefined } from '../../../utils'
import Yas from '../../../utils/yas';
let yas;
Page({
/**
* 页面的初始数据
*/
data: {
title: '',
messageInfo: {
isLoading: false,
hasMore: true,
currentPage: 1,
messageList: [],
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
yas = new Yas(this);
let title = options.title;
let messgeType = options.type;
this.setData({
title,
});
this.fetchMessageList(messgeType);
yas.pageOpenReport();
},
// 消息列表
fetchMessageList: function (messgeType) {
let that = this;
let messageInfo = that.data.messageInfo;
if (messageInfo.isLoading || !messageInfo.hasMore) {
return;
}
messageInfo.isLoading = true;
that.setData({
messageInfo
})
let params = {
type: messgeType,
page: messageInfo.currentPage,
limit: 20
}
let api = new MessageService();
api.fetchNewMessageList(params)
.then(data => {
if (data) {
let msgList = data.list;
if (msgList) {
const list = msgList.map(item => {
let createTime = formatTimeByDefined(item.createTime, 'Y.M.D h:m:s');
item.createTime = createTime;
return item;
})
messageInfo.messageList = messageInfo.messageList.concat(list);
}
let hasMore = messageInfo.currentPage < data.totalPage;
messageInfo.hasMore = hasMore;
if (hasMore) {
messageInfo.currentPage = messageInfo.currentPage + 1;
}
messageInfo.isLoading = false;
that.setData({
messageInfo,
})
}
})
.catch(error => {
messageInfo.isLoading = false;
})
},
onShow: function () {
}
});