department-register.component.ts 1.58 KB
Newer Older
1 2 3
import { Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu1Service } from 'src/app/shared/services/bu1.service';
4 5 6 7 8 9

@Component({
  selector: 'app-department-register',
  templateUrl: './department-register.component.html',
  styleUrls: ['./department-register.component.scss']
})
10 11 12 13 14 15 16 17 18
export class DepartmentRegisterComponent implements OnInit {
  currentPage = 1
  page = Array.from({ length: 1 }, (_, i) => i + 1);
  bu1List: Bu1Model[] = []
  bu1: Bu1Model = new MyBu1Model({})
  search = ""
  constructor(private bu1Service: Bu1Service) { }
  ngOnInit(): void {
    this.getBu1List()
Nattana Chaiyamat committed
19
  }
20 21 22 23 24
  getBu1List() {
    this.bu1Service.getList().subscribe(response => {
      this.bu1List = response
      this.searchChange()
    })
Nattana Chaiyamat committed
25
  }
26 27 28 29 30 31 32 33
  searchChange() {
    this.currentPage = 1
    this.page = Array.from({ length: Math.ceil(this.bu1ListFilter().length / 10) }, (_, i) => i + 1);
  }
  bu1ListFilter() {
    return this.bu1List.filter(x => x.bu1id.toLowerCase().includes(this.search) ||
      x.tdesc.toLowerCase().includes(this.search) ||
      x.edesc.toLowerCase().includes(this.search))
Nattana Chaiyamat committed
34
  }
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
  selectBu1(bu1: Bu1Model) {
    this.bu1 = new MyBu1Model(bu1)
  }
  addBu1() {
    // this.bu1Service.post(this.bu1).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu1List()
    //   }
    // })
  }
  deleteBu1(bu1: Bu1Model) {
    // this.bu1Service.delete(new MyBu1Model(bu1)).subscribe((response:any) => {
    //   if (response.success) {
    //     this.getBu1List()
    //   }
    // })
  }

Nattana Chaiyamat committed
53

54
}