department-list.component.ts 1.87 KB
Newer Older
LAPTOP-CV4JFSHE\kantavee committed
1 2 3 4 5 6
import { Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { Bu2Service } from 'src/app/shared/services/bu2.service';

7 8 9 10 11 12

@Component({
  selector: 'app-department-list',
  templateUrl: './department-list.component.html',
  styleUrls: ['./department-list.component.scss']
})
LAPTOP-CV4JFSHE\kantavee committed
13 14 15 16 17 18 19 20 21 22 23 24
export class DepartmentListComponent implements OnInit {
  currentPage = 1
  page = Array.from({ length: 1 }, (_, i) => i + 1);
  bu2List: Bu2Model[] = []
  bu2: Bu2Model = new MyBu2Model({})
  bu1: Bu1Model = new MyBu1Model({})
  search = ""
  constructor(private bu2Service: Bu2Service,
    private bu1Service: Bu1Service
  ) { }
  ngOnInit(): void {
    this.getBu2List()
25
  }
LAPTOP-CV4JFSHE\kantavee committed
26
  getBu2List() {
27
    this.bu2Service.getList().subscribe(response => {
LAPTOP-CV4JFSHE\kantavee committed
28 29 30
      this.bu2List = response
      this.searchChange()
    })
31
  }
LAPTOP-CV4JFSHE\kantavee committed
32 33 34 35 36 37 38 39 40 41
  searchChange() {
    this.currentPage = 1
    this.page = Array.from({ length: Math.ceil(this.bu2ListFilter().length / 10) }, (_, i) => i + 1);
  }
  bu2ListFilter() {
    return this.bu2List.filter(x => x.bu2id.toLowerCase().includes(this.search) ||
      x.tdesc.toLowerCase().includes(this.search) ||
      x.edesc.toLowerCase().includes(this.search))
  }
  selectBu2(bu2: Bu2Model) {
42
    this.bu1Service.getById(bu2.parent).subscribe(response => {
43
      this.bu1 = response
LAPTOP-CV4JFSHE\kantavee committed
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
    })
    this.bu2 = new MyBu2Model(bu2)
  }
  addBu2() {
    // this.bu2Service.post(this.bu2).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu2List()
    //   }
    // })
  }
  deleteBu2(bu2: Bu2Model) {
    // this.bu2Service.delete(new MyBu2Model(bu2)).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu2List()
    //   }
    // })
60 61
  }

62
}
63