import {Component, OnInit, ViewChild} from '@angular/core';
import {DataStorageModalComponent} from '../modal/data-storage-modal/data-storage-modal.component';
import {PerforManageService} from '../perfor.manage.service';
import {CommonService} from '../../shared/common/common.service';
import {NzMessageService} from 'ng-zorro-antd';
import {OnlineWorkModalComponent} from '../modal/online-work-modal/online-work-modal.component';

@Component({
    selector: 'smart-online-work',
    templateUrl: './online-work.component.html',
    styles: []
})
export class OnlineWorkComponent implements OnInit {
    @ViewChild('smartOnlineWorkModal') smartOnlineWorkModal: OnlineWorkModalComponent;

    page = {
        isLoading: false,
        pageNum: 1,
        pageCount: 10,
        totalNum: null,
        dataSet: [],
    };
    obj = {
        projectName: '',
        projectYear: ''
    };

    constructor(private perforSer: PerforManageService, public commonSer: CommonService, public message: NzMessageService) {
    }

    ngOnInit() {
        this.getList();
    }

    //获取列表
    getList() {
        this.page.isLoading = true;
        const obj = {
            pageCount: this.page.pageCount,
            pageNum: this.page.pageNum,
            obj: this.obj,
        };
        this.perforSer.selectWorkOnline(obj).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.page.dataSet = res.data.data;
                    this.page.totalNum = res.data.totalNum;
                }
                this.page.isLoading = false;
            }
        );
    }

    //翻页
    change(e) {
        if (e > 0) {
            this.page.pageNum = e;
            this.getList();
        }
    }

    //查询
    search() {
        this.page.pageNum = 1;
        this.getList();
    }

    //删除
    deleteHandle(data) {
        const arr = {
            id: data.id
        };
        this.commonSer.confirmThing('删除', '确定删除该资产', () => {
            this.perforSer.deleteWorkOnline(arr).subscribe(
                (res) => {
                    if (res.errCode == 10000) {
                        this.message.success('删除成功');
                        this.getList();
                    }
                }
            );
        });
    }

    //打开添加modal
    showAddModal() {
        this.smartOnlineWorkModal.showAddModal('新增网上办事');
    }

    //打开编辑modal
    showEditModal(item) {
        this.smartOnlineWorkModal.showEditModal('编辑网上办事', item);
    }

}
