import {Component, OnInit, ViewChild} from '@angular/core';
import {EventComponent} from '../../work/work-handle/Event/event.component';
import {TransforComponent} from '../../work/modal/transfor/transfor.component';
import {SelectPersonComponent} from '../../modal/select-person/select-person.component';
import {pageSize} from '../../app.constants';
import {WorkService} from '../../work/work.service';
import {NzMessageService} from 'ng-zorro-antd';
import {Router} from '@angular/router';
import {CommonService} from '../../shared/common/common.service';
import {DatePipe} from '@angular/common';
import {ProjectService} from '../project.service';
import {project_status} from '../project.constants';
import {CreateProjectComponent} from '../modal/create-project/create-project.component';

@Component({
    selector: 'app-opr-project',
    templateUrl: './opr-project.component.html',
    styleUrls: ['./opr-project.component.css']
})
export class OprProjectComponent implements OnInit {
    @ViewChild('smartCreateProject') smartCreateProject: CreateProjectComponent;

    timeFormat = 'yyyy';

    statusList = [{label: '全部', value: null},...project_status];

    page = {
        list: [],
        isLoading: false,
        pageCount: pageSize,
        pageNum: 1,
        totalNum: null
    };

    obj = {
        yearly: null,
        officeName: null,
        status: null,
        companyName: null,
        keyword: ''
    };

    constructor(private workSer: WorkService, private message: NzMessageService, private projectSer: ProjectService,
                private router: Router, private commonSer: CommonService, private datePipe: DatePipe) {
    }

    ngOnInit() {
        this.getList();
    }

    //获取列表
    getList() {
        this.page.isLoading = true;
        const obj = {
            obj: this.obj,
            pageNum: this.page.pageNum,
            pageCount: this.page.pageCount
        };
        this.projectSer.selectMaintainProject(obj).subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.page.list = 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.obj.startTime = this.datePipe.transform(this.startTime, 'yyyy-MM-dd HH:mm:ss');
        // this.obj.endTime = this.datePipe.transform(this.endTime, 'yyyy-MM-dd HH:mm:ss');
        this.getList();
    }

    //新增运维项目
    handleOpenModal() {
        this.smartCreateProject.showAddModal('新增运维项目');
    }

    //编辑运维项目
    handleEdit(data){
        this.smartCreateProject.showEditModal(data,'编辑运维项目')
    }

}
