import {Component, OnInit, Output, EventEmitter, ViewChild} from '@angular/core';
import {EarlyWarningService} from '../../earlyWarning.service';
import {NzMessageService} from 'ng-zorro-antd';
import {WarningTrackInfoComponent} from '../warning-track-info/warning-track-info.component';

@Component({
    selector: 'smart-notation',
    templateUrl: './notation.component.html',
    styles: []
})
export class NotationComponent implements OnInit {
    @ViewChild('smartWarningTrackInfo') smartWarningTrackInfo:WarningTrackInfoComponent;
    @Output() done = new EventEmitter();
    modal = {
        isVisible: false,
        title: '',
        isOkLoading: false
    };
    tabNum = 0;
    msgId;
    msgObj;
    newestRemark;

    constructor(private earlySer: EarlyWarningService, private message: NzMessageService) {
    }

    ngOnInit() {
    }

    showAddModal(item) {
        this.modal.isVisible = true
        this.msgId = item.id;
        this.getDetail();
    }

    showLookModal(item) {
        this.modal.isVisible = true
        this.msgId = item.id;
        this.getDetail();
    }

    //详情
    getDetail() {
        this.earlySer.findWarningMsg(this.msgId).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.msgObj = res.data;
                }
            }
        );
    }

    //确定
    handleOk() {

    }

    //添加批注
    saveNotation() {
        if (!this.newestRemark) {
            this.message.warning('请输入批注');
            return;
        }
        this.modal.isOkLoading = true;
        const data = {
            newestRemark: this.newestRemark,
            id: this.msgId
        };
        this.earlySer.updateWarningMsg(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.done.emit();
                    this.message.success('添加批注成功');
                    this.handleCancel();
                    this.smartWarningTrackInfo.getList();
                }
            }
        );
    }

    //取消
    handleCancel() {
        this.modal.isOkLoading = false;
        this.modal.isVisible = false;
        this.newestRemark = '';
    }

    //切换tab
    tabsChange(e) {
        this.tabNum = e;
    }

}
