sub-department-four.component.ts 1.88 KB
Newer Older
Natthaphat Pankiang committed
1 2 3 4 5
import { Component, OnInit } from '@angular/core';
import { Bu6Model, MyBu6Model } from 'src/app/shared/model/bu6.model';
import { Bu7Model, MyBu7Model } from 'src/app/shared/model/bu7.model';
import { Bu6Service } from 'src/app/shared/services/bu6.service';
import { Bu7Service } from 'src/app/shared/services/bu7.service';
6 7 8 9 10 11

@Component({
  selector: 'app-sub-department-four',
  templateUrl: './sub-department-four.component.html',
  styleUrls: ['./sub-department-four.component.scss']
})
Natthaphat Pankiang committed
12 13 14 15 16 17 18 19 20 21 22 23
export class SubDepartmentFourComponent implements OnInit {
  currentPage = 1
  page = Array.from({ length: 1 }, (_, i) => i + 1);
  bu7List: Bu7Model[] = []
  bu7: Bu7Model = new MyBu7Model({})
  bu6: Bu6Model = new MyBu6Model({})
  search = ""
  constructor(private bu7Service: Bu7Service,
    private bu6Service: Bu6Service
  ) { }
  ngOnInit(): void {
    this.getBu7List()
Natthaphat Pankiang committed
24
  }
Natthaphat Pankiang committed
25 26 27 28 29
  getBu7List() {
    this.bu7Service.getList().subscribe(response => {
      this.bu7List = response
      this.searchChange()
    })
Natthaphat Pankiang committed
30
  }
Natthaphat Pankiang committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  searchChange() {
    this.currentPage = 1
    this.page = Array.from({ length: Math.ceil(this.bu7ListFilter().length / 10) }, (_, i) => i + 1);
  }
  bu7ListFilter() {
    return this.bu7List.filter(x => x.bu7id.toLowerCase().includes(this.search) ||
      x.tdesc.toLowerCase().includes(this.search) ||
      x.edesc.toLowerCase().includes(this.search))
  }
  selectBu7(bu7: Bu7Model) {
    this.bu6Service.getById(bu7.parent).subscribe(response =>{
      this.bu6 =  new MyBu6Model(response)
    })
    this.bu7 = new MyBu7Model(bu7)
  }
  addBu7() {
    // this.bu7Service.post(this.bu7).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu7List()
    //   }
    // })
  }
  deleteBu7(bu7: Bu7Model) {
    // this.bu7Service.delete(new MyBu1Model(bu7)).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu7List()
    //   }
    // })
59 60
  }

61
}