Newer
Older
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { AppService } from '../../service/appHttpService';
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { Response } from '@angular/http';
@IonicPage()
@Component({
selector: 'page-operation-list',
templateUrl: 'operation-list.html',
})
export class OperationListPage {
//默认第一页数据
operations:Array<string>;
pageNumber = 0;
pageSize = 10;
hasmore = true;
//操作记录总数
totalNum = 0;
//加载页数据
pageOperations:Array<string> = [];
//临时页数据
tempOperations:Array<string> = [];
constructor(
public navCtrl: NavController,
public navParams: NavParams,
public appService: AppService,
) {
this.initMineOperationInfo(0);
}
ionViewDidLoad() {
console.log('ionViewDidLoad OperationListPage');
//this.initMineOperationInfo();
}
///操作记录 (首页)
initMineOperationInfo(pageNumber):Array<string>{
this.appService.ObserverHttpPost("/wisdomgroup/opertion/searchOperationInfo", { "P_pageNumber": pageNumber*this.pageSize ,"P_pageSize":this.pageSize})
.subscribe((res: Response) => {
let data = res.json();
this.operations = data.list;
this.totalNum = data.total;
this.operations.forEach(element => {
let timegap = Date.parse(new Date().toString()) - Date.parse(element["opertionTime"].toString());
let timegapvalue = this.timeshift(timegap);
element["timegapvalue"] = timegapvalue;
});
//数据不足一页的时候隐藏 ion-infinate-scroll
if (this.operations.length < this.pageSize) {
this.hasmore = false;
}
//数据第一页即为最后一页时
if(this.operations.length == this.totalNum){
this.hasmore = false;
}
}, error => {
this.appService.alert('网络异常!');
}
);
return this.operations;
}
timeshift(timegap:number):string{
let result:string;
let nd = 1000*24*60*60;//一天的毫秒数
let nh = 1000*60*60;//一小时的毫秒数
let nm = 1000*60;//一分钟的毫秒数
let ns = 1000;//一秒钟的毫秒数
let day = Math.round(timegap/nd);//计算差多少天
let hour = Math.round(timegap%nd/nh);//计算差多少小时
let min = Math.round(timegap%nd%nh/nm);//计算差多少分钟
let sec = Math.round(timegap%nd%nh%nm/ns);//计算差多少秒//输出结果
console.log("时间相差:"+day+"天"+hour+"小时"+min+"分钟"+sec+"秒。");
if(day>0){
result = day+"天前";
}else if(hour>0){
result = hour+"小时前";
}else if(min>0){
result = min+"分钟前";
}else{
result = sec+"几秒前";
}
//result = day+"天"+hour+"小时"+min+"分钟"+sec+"秒"+"前";
return result;
}
//操作记录(下拉产生的数据)
doInfinite(infiniteScroll){
this.scrollPage(result=>{
this.tempOperations = result.list;
this.totalNum = result.total;
if(this.tempOperations.length>0){
//计算间隔时间
this.tempOperations.forEach(element => {
let timegap = Date.parse(new Date().toString()) - Date.parse(element["opertionTime"].toString());
let timegapvalue = this.timeshift(timegap);
element["timegapvalue"] = timegapvalue;
});
this.pageOperations = this.pageOperations.concat(this.tempOperations);
console.log("scroll:"+JSON.stringify(this.pageOperations));
infiniteScroll.complete(); //当数据请求完成调用
}
//数据少于一页时 隐藏 ion-infinate-scroll
if (this.tempOperations.length < this.pageSize) {
this.hasmore = false;
infiniteScroll.enable(false);
}
//最后一页数据时 隐藏 ion-infinate-scroll
if(this.pageOperations.length+this.operations.length == this.totalNum){
this.hasmore = false;
infiniteScroll.enable(false);
}
});
}
scrollPage(callback?):Array<string>{
this.appService.ObserverHttpPost("/wisdomgroup/opertion/searchOperationInfo", { "P_pageNumber": ++this.pageNumber*this.pageSize ,"P_pageSize":this.pageSize})
.subscribe((res: Response) => {
let data = res.json();
callback(data == null ? "[]" : data);
}, error => {
this.appService.alert('网络异常!');
}
);
return this.tempOperations;
}
goBack(){
this.navCtrl.popToRoot();
}
}