api bu2

parent c24c76a6
import { Component, EventEmitter, Input, Output } from '@angular/core';
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';
@Component({
selector: 'app-department-list',
templateUrl: './department-list.component.html',
styleUrls: ['./department-list.component.scss']
})
export class DepartmentListComponent {
modalOptions: {
[nameModal: string]: { // ชื่อตรวจสอบการเปิดปิด
isModalOpen: boolean; // เปิด/ปิด
modalSize: string; // ขนาดของ Modal (s,m,l,vw10-vw100 )
backdropClose: boolean; // (คลิก Backdrop แล้ว true ปิด false ไม่ปิด )
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()
}
} = {
"add": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
},
"edit": {
isModalOpen: false,
modalSize: 'm',
backdropClose: true,
getBu2List() {
this.bu2Service.getList().subscribe(response => {
console.log("31313 : ",response)
this.bu2List = response
this.searchChange()
})
}
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.bu2ListFilter().length / 10) }, (_, i) => i + 1);
}
openModal(name: string, size: string, closeOnBackdrop?: boolean) {
this.modalOptions[name].modalSize = size;
this.modalOptions[name].backdropClose = closeOnBackdrop || false;
this.modalOptions[name].isModalOpen = true;
document.body.style.overflow = 'hidden'; // ล็อก Scroll
bu2ListFilter() {
return this.bu2List.filter(x => x.bu2id.toLowerCase().includes(this.search) ||
x.tdesc.toLowerCase().includes(this.search) ||
x.edesc.toLowerCase().includes(this.search))
}
closeModal(name: string) {
this.modalOptions[name].isModalOpen = false;
// ตรวจสอบว่ามี Modal อื่นเปิดอยู่หรือไม่
if (!this.isAnyModalOpen()) {
document.body.style.overflow = ''; // คืนค่าการ Scroll เฉพาะเมื่อ Modal ทั้งหมดปิดแล้ว
selectBu2(bu2: Bu2Model) {
this.bu1Service.getById(bu2.parent).subscribe(response =>{
this.bu1 = response
console.log(this.bu1)
})
this.bu2 = new MyBu2Model(bu2)
}
addBu2() {
// this.bu2Service.post(this.bu2).subscribe((response:any) => {
// if (response.success) {
// this.getBu2List()
// }
// })
}
isAnyModalOpen(): boolean {
// Logic ตรวจสอบว่า Modal อื่นยังเปิดอยู่หรือไม่
return Object.values(this.modalOptions).some(modal => modal.isModalOpen); // หากไม่มี Modal อื่นเปิด
deleteBu2(bu2: Bu2Model) {
// this.bu2Service.delete(new MyBu2Model(bu2)).subscribe((response:any) => {
// if (response.success) {
// this.getBu2List()
// }
// })
}
}
......
......@@ -41,6 +41,7 @@ import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { Bu1Service } from 'src/app/shared/services/bu1.service';
import { HttpRequestInterceptor } from 'src/app/shared/services/http-request.interceptor';
import { FormsModule } from '@angular/forms';
import { Bu2Service } from 'src/app/shared/services/bu2.service';
@NgModule({
declarations: [
......@@ -88,7 +89,7 @@ import { FormsModule } from '@angular/forms';
HttpClientModule,
FormsModule
],
providers: [Bu1Service, {
providers: [Bu1Service,Bu2Service, {
provide: HTTP_INTERCEPTORS,
useClass: HttpRequestInterceptor,
multi: true,
......
export interface Bu2Model {
bu2id: string;
tdesc: string;
edesc: string;
parent: string;
companyId: string;
}
export class MyBu2Model implements Bu2Model {
bu2id: string;
tdesc: string;
edesc: string;
parent: string;
companyId: string;
constructor(data: Partial<Bu2Model>) {
this.bu2id = data.bu2id || ""
this.tdesc = data.tdesc || ""
this.edesc = data.edesc || ""
this.parent = data.parent || ""
this.companyId = data.companyId || ""
}
}
......@@ -14,6 +14,9 @@ export class Bu1Service {
getList(): Observable<Bu1Model[]> {
return this.http.get<Bu1Model[]>(this.urlApi + "/lists")
}
getById(bu1id:string): Observable<Bu1Model> {
return this.http.get<Bu1Model>(this.urlApi + "/"+bu1id)
}
// post(body: Bu1Model) {
// return this.http.post(this.urlApi, body)
// }
......
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { Bu2Model } from '../model/bu2.model';
@Injectable({
providedIn: 'root'
})
export class Bu2Service {
api = "/bu2"
urlApi = environment.baseUrl + this.api
constructor(private http: HttpClient) {
}
getList(): Observable<Bu2Model[]> {
return this.http.get<Bu2Model[]>(this.urlApi + "/lists")
}
// post(body: Bu1Model) {
// return this.http.post(this.urlApi, body)
// }
// delete(body: Bu1Model) {
// const options = {
// headers: new HttpHeaders({
// "Content-Type": "application/json",
// }),
// body: body
// };
// return this.http.delete(this.urlApi, options)
// }
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment