Newer
Older
import { Component, ViewChild } from '@angular/core';
import { NavController, IonicPage, Slides } from 'ionic-angular';
import { ActivityListPage } from '../../activity/activityList/activityList';
import { ActivityStatisticService } from '../../../service/activityStatisticService';
import { MyActivityListPage } from '../../myActivityList/myActivityList';
import { AppService, AppGlobal } from '../../../service/appHttpService';
import { Calendar } from '@ionic-native/calendar';
import { ActivityApplyPage } from '../../activity/activityApply/activityApply'
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
import { ActivityConfirmPage } from '../../activityConfirm/activityConfirm';
import { OutGoingReportPage } from '../../outGoingReport/outGoingReport';
import { OperationListPage } from '../../operation-list/operation-list';
import { AnnouncementPage } from '../../announcement/announcement';
import { Storage } from '@ionic/storage';
import { OutGoingReportEditPage } from '../../outGoingReportEdit/outGoingReportEdit';
import { AnnouncementViewPage } from '../../announcementView/announcementView';
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
@ViewChild(Slides) slides: Slides;
hasNewActivity:number = 0;
hasNewNotice:number = 0;
hasNewPremanager:number = 0;
//待出行
waitgoCount = '0';
//待确认
waitsureCount = '0';
//未读通知
NoticeNotreadCount = '0';
//尚未报备
PremanagerNotdoCount = '0';
//是否显示正在开发中
isWait: boolean = false;
slidersItems: object[] = [];
picture: string = AppGlobal.picture;
operations: Array<string>;
//当前年份
year;
//当前月份
month;
//当前第几周
weekNo;
//当前周日历展示
week: Week[] = [{
id: 0,
title: '日',
date: null,
isToday: false
}, {
id: 1,
title: '一',
date: null,
isToday: false
}, {
id: 2,
title: '二',
date: null,
isToday: false
}, {
id: 3,
title: '三',
date: null,
isToday: false
}, {
id: 4,
title: '四',
date: null,
isToday: false
}, {
id: 5,
title: '五',
date: null,
isToday: false
}, {
id: 6,
title: '六',
date: null,
isToday: false
}]
constructor(public navCtrl: NavController, public activityStatisticService: ActivityStatisticService,
public appService: AppService, public http: Http, private calendar: Calendar, public storage: Storage) {
}
goActivity() {
this.navCtrl.push('ActivityListPage', {
});
}
goAnnouncement() {
this.navCtrl.push("AnnouncementPage");
}
// ngOnInit(): void {
// this.appService.ObserverHttpGet("/wisdomgroup/modules/common/file/getBanner", {}).subscribe((res: Response) => {
// this.slidersItems = res.json();
// console.log(res.json());
// }, error => {
// this.appService.alert('系统错误!');
// })
// }
//页面进入时启动自动播放
// ionViewDidEnter() {
// this.slides.startAutoplay();
// }
//页面离开时停止自动播放
// ionViewDidLeave() {
// this.slides.stopAutoplay();
// }
ionViewDidEnter() {
setTimeout(() => {
if (this.slidersItems.length > 0) {
this.slides.freeMode = true;
this.slides.autoplay = 2000;
this.slides.speed = 500;
this.slides.loop = true;
this.slides.autoplayDisableOnInteraction=false;
this.slides.startAutoplay();
}
}, 1000)
}
ionViewWillEnter() {
//初始化日期
this.initDate();
this.getHasNewActivity();
this.getHasNewNotice();
this.getHasNewPremanager();
//统计待进行和待确认活动数目
this.activityStatisticService.myActivityOrderCount((data) => {
this.waitgoCount = data.waitgoOrder;
this.waitsureCount = data.waitSureOrder;
});
this.appService.ObserverHttpGet("/wisdomgroup/modules/common/file/getBanner", {}).subscribe((res: Response) => {
this.slidersItems = res.json();
}, error => {
this.appService.alert('网络异常!');
})
//初始化统计未读通知
this.activityStatisticService.myNoticeNotreadCount((data) => {
this.NoticeNotreadCount = data;
});
//初始化统计尚未报备
this.activityStatisticService.myNotdoPremanagerCount((data) => {
this.PremanagerNotdoCount = data;
});
//初始化操作记录
this.initMineOperationInfo();
}
goMyActivity() {
this.navCtrl.push("MyActivityListPage");
}
goMyNotice() {
this.navCtrl.push("AnnouncementPage");
}
wait() {
this.isWait = true;
}
cancleWait() {
this.isWait = false;
}
go(item) {
if (item.type == 1) {
this.getActivity(item.id);
} else if (item.type == 2) {
this.getPremanager(item.id);
} else if (item.type == 3) {
this.navCtrl.push("AnnouncementViewPage", {
id: item.id
});
}
}
//获取活动ById
getActivity(id) {
this.appService.ObserverHttpPost("/wisdomgroup/modules/activity/appFindById", { id: id })
.toPromise()
.then(res => {
let activity = res.json();
if (activity.orderList.length == 0) {
this.goApply(activity);
} else {
this.goDetail(activity);
}
})
.catch(error => {
});
}
//获取公告
// getNotice(id) {
// this.appService.ObserverHttpPost("/wisdomgroup/modules/notice/getNoticeById", { id: id })
// .toPromise()
// .then(res => {
// let notice = res.json();
// })
// .catch(error => {
// });
// }
//获取报备
getPremanager(id) {
this.appService.ObserverHttpPost("/wisdomgroup/modules/premanager/findById", { id: id })
.toPromise()
.then(res => {
let premanager = res.json();
this.storage.set("premanager", premanager);
this.navCtrl.push("OutGoingReportEditPage");
})
.catch(error => {
});
}
//查看详情
goDetail(item) {
let orderid = item.orderList[0]["orderid"];
this.findMyOrderByOrderId(orderid, result => {
let order = result;
this.navCtrl.push("ActivityConfirmPage", { lookOrderDetails: order });
});
}
//报名按钮
goApply(item) { //活动状态:1:待发布(不可报名),2:发布中(可报名)3:已完成(报名截止)
if (item.activityState == 2) {
let flag = false;
this.isExitOrderWithActivity(item, result => {
flag = result;
if (flag) {
this.appService.toast("您已经报名该活动,请在我的活动中查看!");
} else {
this.navCtrl.push("ActivityApplyPage", { item: item });
}
});
} else {
if (item.activityState == 1) {
this.appService.toast("报名暂未开通!");
} else {
this.appService.toast("活动已完成!");
}
}
}
findMyOrderByOrderId(orderid, callback?) {
let order = this.appService.ObserverHttpPost("/wisdomgroup/modules/order/findMyOrderByOrderId", { "orderid": orderid })
.subscribe((res: Response) => {
let data = res.json();
callback(data == null ? "[]" : data);
}, error => {
this.appService.alert('网络异常!');
}
);
}
isExitOrderWithActivity(activity, callback?): any {
this.appService.ObserverHttpPost("/wisdomgroup/modules/order/isExitOrderWithActivity", activity)
.toPromise()
.then(res => {
var data = res.json();
callback(data == null ? "[]" : data);
})
.catch(error => {
});
}
//获取当前是第几周
getWeekOfYear() {
var today = new Date();
var firstDay = new Date(today.getFullYear(), 0, 1);
var dayOfWeek = firstDay.getDay();
var spendDay = 1;
if (dayOfWeek != 0) {
spendDay = 7 - dayOfWeek + 1;
}
firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
var d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
var result = Math.ceil(d / 7);
return result + 1;
};
//初始化日历
initDate() {
this.weekNo = this.getWeekOfYear();
var date = new Date();
this.year = date.getFullYear();
this.month = date.getMonth() + 1;
//初始化周
var day = date.getDay();
var today = date.getDate();
for (let item of this.week) {
var count = item.id - day;
var now = new Date();
now.setTime(date.getTime() + count * 24 * 60 * 60 * 1000);
item.date = now.getDate();
if (count == 0) {
item.isToday = true;
}
}
}
//创建日历
myCalendar() {
this.calendar.createCalendar('日历').then(
(msg) => { console.log(msg); },
(err) => { console.log(err); }
);
this.calendar.openCalendar(new Date()).then(
(msg) => { console.log(msg); },
(err) => { console.log(err); }
);
}
///操作记录
initMineOperationInfo() {
let order = this.appService.ObserverHttpPost("/wisdomgroup/opertion/searchOperationInfo", { "P_pageNumber": 0, "P_pageSize": 3 })
.subscribe((res: Response) => {
let data = res.json();
this.operations = data.list;
console.log(JSON.stringify(this.operations));
this.operations.forEach(element => {
let timegap = Date.parse(new Date().toString()) - Date.parse(element["opertionTime"].toString());
let timegapvalue = this.timeshift(timegap);
element["timegapvalue"] = timegapvalue;
//显示25字
let content = element["opertionContent"];
if (content.length > 25) {
element["opertionContent"] = content.substr(0, 25) + "...";
}
});
}, error => {
this.appService.alert('网络异常!');
}
);
}
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;
}
goOperationListPage() {
this.navCtrl.push("OperationListPage");
}
//外出报备跳转
goOutGoingReportAboutAll() {
this.navCtrl.push("OutGoingReportPage", {
type: 1
});
}
//尚未报备跳转
goOutGoingReportAboutNot() {
this.navCtrl.push("OutGoingReportPage", {
type: 2
});
}
//获取是否有新的活动
getHasNewActivity(){
this.appService.ObserverHttpGet("/wisdomgroup/modules/activity/hasNewActivity", null)
.subscribe((res: Response) => {
let data = res.json();
console.log(data);
this.hasNewActivity = data;
}, error => {
this.appService.alert('网络异常!');
}
);
}
//获取是否有新的公告
getHasNewNotice(){
this.appService.ObserverHttpGet("/wisdomgroup/modules/notice/hasNewNotice", null)
.subscribe((res: Response) => {
let data = res.json();
console.log(data);
this.hasNewNotice = data;
}, error => {
this.appService.alert('网络异常!');
}
);
}
//获取是否有新的报备
getHasNewPremanager(){
this.appService.ObserverHttpGet("/wisdomgroup/modules/premanager/hasNewPremanager", null)
.subscribe((res: Response) => {
let data = res.json();
console.log(data);
this.hasNewPremanager = data;
}, error => {
this.appService.alert('网络异常!');
}
);
}
}
//定义星期实体
export class Week {
id: number;
title: string;
date: number;
isToday: boolean = false;
}