import {Component, OnInit, EventEmitter, Output} from '@angular/core';
import index from '@angular/cli/lib/cli';
import {OverviewService} from '../../overview.service';
import {NzMessageService} from 'ng-zorro-antd';
import {fakeAsync} from '@angular/core/testing';

@Component({
    selector: 'smart-module-config',
    templateUrl: './module-config.component.html',
    styles: []
})
export class ModuleConfigComponent implements OnInit {
    @Output() done = new EventEmitter();

    modal = {
        isVisible: false,
        title: '',
        list: []
    };

    constructor(private overviewSer: OverviewService,
                private message: NzMessageService) {
    }

    ngOnInit() {

    }

    showModal(title, dataSet) {
        this.modal.isVisible = true;
        this.modal.title = title;
        this.modal.list = dataSet;
    }

    handleCancel() {
        this.modal.isVisible = false;
    }

    handleOk() {
        console.log(this.modal.list);
        this.modal.list.forEach((e, index) => {
            e.status = e.status == false ? 0 : 1;
            e.orders = index;
        });
        this.overviewSer.updateWorkModule(this.modal.list).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.message.success('更新成功');
                    this.modal.isVisible = false;
                    this.done.emit();
                }
            }
        );
        // this.modal.isVisible = false;
    }

}
