import {Component, OnInit, ViewChild} from '@angular/core';
import {AdminOfficeModalComponent} from '../modal/admin-office-modal/admin-office-modal.component';
import {PerforManageService} from '../perfor.manage.service';
import {CommonService} from '../../shared/common/common.service';
import {NzMessageService} from 'ng-zorro-antd';
import {BasicServiceModalComponent} from '../modal/basic-service-modal/basic-service-modal.component';

@Component({
    selector: 'smart-basic-service',
    templateUrl: './basic-service.component.html',
    styles: []
})
export class BasicServiceComponent implements OnInit {
    @ViewChild('smartBasicServiceModal') smartBasicServiceModal: BasicServiceModalComponent;

    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.selectBasicService(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.deleteBasicService(arr).subscribe(
                (res) => {
                    if (res.errCode == 10000) {
                        this.message.success('删除成功');
                        this.getList();
                    }
                }
            );
        });
    }

    //打开添加modal
    showAddModal() {
        this.smartBasicServiceModal.showAddModal('新增基础服务');
    }

    //打开编辑modal
    showEditModal(item) {
        this.smartBasicServiceModal.showEditModal('编辑基础服务', item);
    }
}
