import {Component, ElementRef, OnInit} from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { MessageService } from '../tab-message.service'; import { Constants } from '../../Constant'; import { PublicService } from '../../PublicService'; import sd from 'silly-datetime'; @Component({ selector: 'app-message-list', templateUrl: './message-list.page.html', styleUrls: ['./message-list.page.scss'], }) export class MessageListPage implements OnInit { private msgTypeName; private msgType; private msgList = []; private readonly nowDay; constructor(private readonly route: ActivatedRoute, private readonly elementRef: ElementRef, private readonly publicService: PublicService, private readonly messageService: MessageService) { this.nowDay = sd.format( new Date(), 'YYYY-MM-DD'); } ngOnInit() { const params = this.route.snapshot.queryParams; this.msgTypeName = params.msgTypeName; this.msgType = params.msgType; this.messageService.getMsgListFromType(this.msgTypeName).then(res => { if (res.code === Constants.SUCCESS){ this.msgList = res.data; }else{ this.publicService.presentToast(res.msg); } }, err => { this.publicService.checkNetworkToast(err); }); } readAll(){ this.messageService.changeTypeMsgStatus(this.msgType).then(res => { console.log(res); if (res.code === Constants.SUCCESS){ this.msgList.forEach(item => { item.isRead = 1; }); } }); } clickMsgItem(item){ if (item.isRead === 0 || item.isRead === '0'){ this.messageService.changeMsgStatus(item.msgId).then(res => { if (res.code === Constants.SUCCESS){ item.isRead = 1; } }); } } getTime(createTime){ if (createTime){ const day = createTime.substr(0, 10); const time = createTime.substr(11, 5); if (day === this.nowDay){ return time; }else{ return day; } }else{ return createTime; } } }