import {Component, OnInit} from '@angular/core';
import {BusinessService} from '../../business.service';
import {NzMessageService} from 'ng-zorro-antd';

@Component({
    selector: 'smart-work-report',
    templateUrl: './work-report.component.html',
    styles: [
        ``
    ]
})
export class WorkReportComponent implements OnInit {

    isVisiable = false;
    isLoading = false;
    yearList = [];
    periodList = [{value: 'yearly', label: '每年'}, {value: 'monthly', label: '每月'}, {value: 'weekly', label: '每周'}, {value: 'daily', label: '每日'},];
    dataSet;

    //obj
    serviceid;
    period = 'weekly';
    year = null;

    constructor(private busineSer: BusinessService, private message: NzMessageService) {
        const nowYear = new Date().getFullYear();
        this.year = nowYear;
        for (let i = 2018; i < nowYear + 1; i++) {
            this.yearList.push(i);
        }
    }

    ngOnInit() {

    }

    getList() {
        this.isLoading = true;
        const data = {
            'serviceid': this.serviceid,
            'period': this.period,
            'year': this.year
        };
        this.busineSer.serviceSla(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.dataSet = res.data.sla;
                }
                this.isLoading = false;
            }
        );
    }

    showModal(item) {
        this.serviceid = item.id;
        this.isVisiable = true;
        this.getList();
    }

    handleCancel(){
        this.isVisiable = false;
    }

    handleOk(){
        this.isVisiable = false;
    }
}
