Skip to content
warnging-rule.component.ts 3.83 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {EarlyWarningService} from '../../earlyWarning.service';
import {NzMessageService} from 'ng-zorro-antd';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {warning_type} from '../../early.constants';
wangqinghua's avatar
wangqinghua committed
import {OverAllService} from '../../../overAll/overAll.service';
wangqinghua's avatar
wangqinghua committed

@Component({
    selector: 'smart-warnging-rule',
    templateUrl: './warnging-rule.component.html',
    styles: []
})
export class WarngingRuleComponent implements OnInit {

    @Output() done = new EventEmitter();
    modal = {
        isVisible: false,
        title: '',
        isOkLoading: false
    };
    warningType = warning_type;
    tabNum = 0;
    msgId;
    msgObj;
    newestRemark;
    validateForm: FormGroup;

wangqinghua's avatar
wangqinghua committed
    groupList = [];
    equipmentList = [];

wangqinghua's avatar
wangqinghua committed
    constructor(private earlySer: EarlyWarningService, private message: NzMessageService,
wangqinghua's avatar
wangqinghua committed
                private overAllSer:OverAllService,
wangqinghua's avatar
wangqinghua committed
                private fb: FormBuilder,) {
    }

    ngOnInit() {
        this.initForm();
wangqinghua's avatar
wangqinghua committed
        this.getGroup();
        this.getType();
wangqinghua's avatar
wangqinghua committed
    }

    initForm() {
        this.validateForm = this.fb.group({
            name: [null, [Validators.required]],
wangqinghua's avatar
wangqinghua committed
            type: ['1'], level: ['1'],
wangqinghua's avatar
wangqinghua committed
            cycle: ['1'], content: [null],
            fileId: [null], resourceGroupType: ['1'],
            resourceGroupValue: [null], resourceWarningLevel: ['1'],
wangqinghua's avatar
wangqinghua committed
            resourceDays: [null], resourceSymbol: ['1'],
wangqinghua's avatar
wangqinghua committed
            resourceWarningTims: [null], businessDataType: [null],
wangqinghua's avatar
wangqinghua committed
            businessDays: [null], businessWarningSymbol: ['1'],
            businessWarningValue: [null], businessThresholdSymbol: ['1'],
            businessThresholdValue: [null], jobDataType: ['1'],
            jobUntreatedSymbol: ['1'], jobUntreatedDays: [null],
wangqinghua's avatar
wangqinghua committed
        });
    }

wangqinghua's avatar
wangqinghua committed
    //获取资源分组
    getGroup() {
        this.overAllSer.getEditGroups(0).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.groupList = res.data;
                }
            }
        );
    }

    //获取设备类型
    getType() {
        this.overAllSer.findType().subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.equipmentList = res.data;
                }
            }
        );
    }

wangqinghua's avatar
wangqinghua committed
    //新增
    showAddModal(title) {
        this.modal.isVisible = true;
        this.modal.title = title;
    }

    showEditModal(item, title) {
        this.modal.title = title;
    }

wangqinghua's avatar
wangqinghua committed
    showLookModal(item, title) {
        this.modal.isVisible = true;
wangqinghua's avatar
wangqinghua committed
        this.msgId = item.id;
wangqinghua's avatar
wangqinghua committed
        this.modal.title = title;
wangqinghua's avatar
wangqinghua committed
        this.getDetail();
    }

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

    //确定
    handleOk() {

    }

    //添加批注
    saveNotation() {
wangqinghua's avatar
wangqinghua committed
        for (let i in this.validateForm.controls) {
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        if (this.validateForm.invalid) {
            return false;
        }
wangqinghua's avatar
wangqinghua committed
        this.modal.isOkLoading = true;
        this.earlySer.addWarningRule(this.validateForm.value).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.done.emit();
                    this.message.success('添加规则成功');
                    this.initForm();
                    this.handleCancel();
                }
            }
        );
    }

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

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

}