Skip to content
project-modal.component.ts 1.66 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {ProjectService} from '../../project.service';

@Component({
  selector: 'smart-project-modal',
  templateUrl: './project-modal.component.html',
  styles: []
})
export class ProjectModalComponent implements OnInit {

  @Output() done =  new EventEmitter<any>();

  isVisiable = false;
  obj = {
    keyword: ''
  };

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

  inSelect;

  constructor(private projectSer: ProjectService) {
  }

  ngOnInit() {
    this.getList();
  }

wangqinghua's avatar
wangqinghua committed
  showModal(){
    this.isVisiable = true;
  }

wangqinghua's avatar
wangqinghua committed
  getList() {
    this.page.isLoading = true;
    const obj = {
      obj: this.obj,
      pageNum: this.page.pageNum,
      pageCount: this.page.pageCount
    };
wangqinghua's avatar
wangqinghua committed
    this.projectSer.selectMaintainProject(obj).subscribe(
wangqinghua's avatar
wangqinghua committed
        (res) => {
          if (res.errCode == 10000) {
            this.page.list = res.data.data;
            this.page.totalNum = res.data.totalNum;
            this.page.isLoading = false;
          }
        }
    );
  }

  PageDataChange(e) {

  }

  changePage(e) {
    this.page.pageNum = e;
    this.getList();
  }

  selectItem(item, e) {
    if (e) {
      const arr = this.page.list.map(data => {
        return data.itemId;
      });
      const old = this.inSelect;
      if (old) {
        const index = arr.indexOf(old.itemId);
        this.page.list[index].checked = false;
      }
      this.inSelect = item;
    } else {
      this.inSelect = null;
    }
  }

  handleOk(){
    this.isVisiable = false;
    this.done.emit(this.inSelect);
  }

  handleCancel(){
    this.isVisiable = false;
  }

}