import {Component, EventEmitter, Input, OnInit, Output, ViewChild} from '@angular/core';
import {SendLogComponent} from '../../../alarm/modal/send-log/send-log.component';
import {pageSize} from '../../../app.constants';
import {AlarmService} from '../../../alarm/alarm.service';
import {NzMessageService} from 'ng-zorro-antd';
import {ProjectService} from '../../project.service';

@Component({
    selector: 'smart-track-info',
    templateUrl: './track-info.component.html',
    styles: []
})
export class TrackInfoComponent implements OnInit {
    @Input() maintainType;
    @ViewChild('sendLog') sendLog: SendLogComponent;
    @Output() total = new EventEmitter<any>();

    warnList = [];

    page = {
        pageNum: 1,
        pageCount: pageSize,
        totalNum: 0,
        loading: false,
    };

    constructor(public alarmSer: AlarmService, public message: NzMessageService,
                private projectSer:ProjectService) {
    }

    ngOnInit() {
        this.getList();
    }

    outGet() {
        this.page.pageNum = 1;
        this.getList();
    }

    getList() {
        this.page.loading = true;
        const data = {
            pageNum: this.page.pageNum,
            pageCount: this.page.pageCount,
            obj: {
                maintainType: this.maintainType
            }
        };
        this.projectSer.selectMaintainProjectTrackMsg(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    if (res.data) {
                        this.warnList = res.data.data;
                        this.page.totalNum = res.data.totalNum;
                    }
                }
                this.page.loading = false;
            }
        );
    }

    change(e) {
        this.page.pageNum = e;
        this.getList();
    }

    showLog(data) {
        this.sendLog.showModal(data);
    }
}
