import { Component, OnInit } from '@angular/core';
import {opr_cost_type, project_status} from '../project.constants';
import {pageSize} from '../../app.constants';
import {WorkService} from '../../work/work.service';
import {NzMessageService} from 'ng-zorro-antd';
import {ProjectService} from '../project.service';
import {Router} from '@angular/router';
import {CommonService} from '../../shared/common/common.service';
import {DatePipe} from '@angular/common';

@Component({
  selector: 'app-opr-cost',
  templateUrl: './opr-cost.component.html',
  styleUrls: ['./opr-cost.component.css']
})
export class OprCostComponent implements OnInit {
  timeFormat = 'yyyy';

  statusList = project_status;
  costType = opr_cost_type;

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

  obj = {
    people: '',  //填报人
    name: '',  //费用名称
    type: null,  //费用类型
    startTime: null,  //开始时间
    endTime: null //结束时间
  };

  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.findPageCost(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) {
    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();
  }

}
