PullUpLoadMore.ets
2.25 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
import promptAction from '@ohos.promptAction';
import PageModel from '../viewmodel/PageModel';
import { RefreshConstants as Const } from './RefreshConstants';
import PageViewModel from '../viewmodel/PageViewModel';
import { PageDTO } from '../repository/bean/PageDTO';
import { CompDTO } from '../repository/bean/CompDTO';
import { DateTimeUtils } from 'wdKit';
export function touchMoveLoadMore(model: PageModel, event: TouchEvent) {
// list size +1
if (model.endIndex === model.compList.size() || model.endIndex === model.compList.size() + 1) {
model.offsetY = event.touches[0].y - model.downY;
if (Math.abs(model.offsetY) > vp2px(model.pullUpLoadHeight) / 2) {
model.isCanLoadMore = true;
model.isVisiblePullUpLoad = true;
model.offsetY = -vp2px(model.pullUpLoadHeight) + model.offsetY * Const.Y_OFF_SET_COEFFICIENT;
}
}
}
export function touchUpLoadMore(model: PageModel) {
let self: PageModel = model;
animateTo({
duration: Const.ANIMATION_DURATION,
}, () => {
self.offsetY = 0;
})
if ((self.isCanLoadMore === true) && (self.hasMore === true)) {
self.isLoading = true;
setTimeout(() => {
closeLoadMore(model);
PageViewModel.getPageData(self)
.then((data: PageDTO) => {
if (data == null || data.compList == null || data.compList.length == 0) {
self.hasMore = false;
} else {
if (data.compList.length == self.pageSize) {
self.currentPage++;
self.hasMore = true;
} else {
self.hasMore = false;
}
let sizeBefore = self.compList.size();
self.compList.push(...data.compList)
PageViewModel.getInteractData(data.compList).then((data: CompDTO[]) => {
// 刷新,替换所有数据
self.compList.updateItems(sizeBefore, data)
self.timestamp = DateTimeUtils.getCurrentTimeMillis().toString()
})
}
}).catch((err: string | Resource) => {
promptAction.showToast({ message: err });
})
}, Const.DELAY_TIME);
} else {
closeLoadMore(self);
}
}
export function closeLoadMore(model: PageModel) {
model.isCanLoadMore = false;
model.isLoading = false;
model.isVisiblePullUpLoad = false;
}