import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {pageSize} from '../../app.constants';
import {OverAllService} from '../../overAll/overAll.service';

@Component({
    selector: 'smart-web-modal',
    templateUrl: './web-modal.component.html',
    styles: []
})
export class WebModalComponent implements OnInit {
    @Output() done = new EventEmitter<string>();
    isVisiable = false;
    isLoading = false;
    dataSet;

    name;
    pageIndex = 1;
    pageSize = pageSize;
    totalNum;

    constructor(private overAllSer: OverAllService) {
    }

    ngOnInit() {
        this.getwebList();
    }

    showModal() {
        this.isVisiable = true;
    }

    //网站列表
    getwebList() {
        this.isLoading = true;
        const data = {
            name: this.name,
            eventPage: this.pageIndex,
            pageRecords: this.pageSize
        };
        this.overAllSer.findWebscenario(data).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.dataSet = res.data.data;
                    this.totalNum = res.data.totalNum;
                }
                this.isLoading = false;
            }
        );
    }

    change($event){
        if($event > 0){
            this.pageIndex = 1;
            this.getwebList();
        }
    }

    set(item) {
        this.done.emit(item);
        this.isVisiable = false;
    }

    handleCancel() {
        this.isVisiable = false;
    }

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