Commit 2a30be7c by Nattana Chaiyamat

syncfution ทะเบียนส่วน

parent 307b800b
...@@ -149,22 +149,21 @@ export class DepartmentRegisterComponent implements OnInit { ...@@ -149,22 +149,21 @@ export class DepartmentRegisterComponent implements OnInit {
reverseButtons: true, reverseButtons: true,
}).then((result) => { }).then((result) => {
if (result.isConfirmed) { if (result.isConfirmed) {
console.log(" 🐒 result:", result) this.bu1.loading = true
// this.bu1.loading = true this.bu1Service.post(this.bu1.select).subscribe({
// this.bu1Service.post(this.bu1.select).subscribe({ next: response => {
// next: response => { if (response.success) {
// if (response.success) { this.showAlert(response.message, 'success')
// this.showAlert(response.message, 'success') this.getBu1List()
// this.getBu1List() } else {
// } else { this.showAlert(response.message, 'error')
// this.showAlert(response.message, 'error') this.bu1.loading = false
// this.bu1.loading = false }
// } }, error: error => {
// }, error: error => { this.showAlert(error.message, 'error')
// this.showAlert(error.message, 'error') this.bu1.loading = false
// this.bu1.loading = false }
// } })
// })
} }
}) })
} }
...@@ -183,24 +182,23 @@ export class DepartmentRegisterComponent implements OnInit { ...@@ -183,24 +182,23 @@ export class DepartmentRegisterComponent implements OnInit {
reverseButtons: true, reverseButtons: true,
}).then((result) => { }).then((result) => {
if (result.isConfirmed) { if (result.isConfirmed) {
console.log(" 🐒 result:", result) this.bu1.loading = true
// this.bu1.loading = true const selectedKeys = Array.from(this.selectedItems.data.keys());
// const selectedKeys = Array.from(this.selectedItems.data.keys()); const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x))
// const body = this.bu1.dataList.filter(x => selectedKeys.includes(x.bu1id) && this.selectedItems.data.get(x.bu1id)).map(x => new MyBu1Model(x)) this.bu1Service.delete(body).subscribe({
// this.bu1Service.delete(body).subscribe({ next: response => {
// next: response => { if (response.success) {
// if (response.success) { this.showAlert(response.message, 'success')
// this.showAlert(response.message, 'success') this.getBu1List()
// this.getBu1List() } else {
// } else { this.showAlert(response.message, 'error')
// this.showAlert(response.message, 'error') this.bu1.loading = false
// this.bu1.loading = false }
// } }, error: error => {
// }, error: error => { this.showAlert(error.message, 'error')
// this.showAlert(error.message, 'error') this.bu1.loading = false
// this.bu1.loading = false }
// } })
// })
} }
}); });
} }
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model'; import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model'; import { Bu3Model, MyBu3Model } from 'src/app/shared/model/bu3.model';
...@@ -17,25 +18,10 @@ interface table { ...@@ -17,25 +18,10 @@ interface table {
styleUrls: ['./section-registration.component.scss'] styleUrls: ['./section-registration.component.scss']
}) })
export class SectionRegistrationComponent implements OnInit { export class SectionRegistrationComponent implements OnInit {
bu3List: { check: boolean, data: Bu3Model }[] = [] bu3: { loading: boolean, select: Bu3Model, dataList: Bu3Model[] } = { loading: false, select: new MyBu3Model(), dataList: [] }
bu3ListLoading = false
bu3: Bu3Model = new MyBu3Model()
bu3Table: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
selectedFile: File | null = null; selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
bu3Modal: table = {
currentPage: 1,
page: Array.from({ length: 1 }, (_, i) => i + 1),
search: "",
pageSize: 10
}
bu2List: Bu2Model[] = [] bu2List: Bu2Model[] = []
bu2: Bu2Model = new MyBu2Model() bu2: Bu2Model = new MyBu2Model()
bu2Modal: table = { bu2Modal: table = {
...@@ -46,9 +32,30 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -46,9 +32,30 @@ export class SectionRegistrationComponent implements OnInit {
} }
currentModal: 'add' | 'edit' | 'delete' = "add" currentModal: 'add' | 'edit' | 'delete' = "add"
numDataListChecked = 0
isDataListChecked = false columns: ColumnModel[] = [{
isDataListCheckedAll = false field: "bu3id",
headerText: "รหัสฝ่าย",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "รายละเอียดฝ่าย(ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "รายละเอียดฝ่าย(อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['bu3id', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
constructor(private bu3Service: Bu3Service, constructor(private bu3Service: Bu3Service,
private bu2Service: Bu2Service, private bu2Service: Bu2Service,
private toastr: ToastrService, private toastr: ToastrService,
...@@ -73,7 +80,7 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -73,7 +80,7 @@ export class SectionRegistrationComponent implements OnInit {
} }
const formData = new FormData(); const formData = new FormData();
formData.append('file', this.selectedFile); formData.append('file', this.selectedFile);
this.bu3ListLoading = true this.bu3.loading = true
this.fileService.uploadExcel(formData, 'mbu3').subscribe({ this.fileService.uploadExcel(formData, 'mbu3').subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -81,11 +88,11 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -81,11 +88,11 @@ export class SectionRegistrationComponent implements OnInit {
this.getBu3List() this.getBu3List()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu3ListLoading = false this.bu3.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu3ListLoading = false this.bu3.loading = false
} }
}) })
} }
...@@ -110,80 +117,62 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -110,80 +117,62 @@ export class SectionRegistrationComponent implements OnInit {
} }
getBu3List() { getBu3List() {
this.bu3ListLoading = true this.bu3.loading = true
this.bu3Service.getList().subscribe({ this.bu3Service.getList().subscribe({
next: response => { next: response => {
this.bu3List = response.map(x => ({ check: false, data: new MyBu3Model(x) })) this.bu3.dataList = response.map(x => {
this.bu3ListLoading = false this.selectedItems.data.set(x.bu3id, false)
this.onBu3TableSearchChange() return new MyBu3Model(x)
this.isDataListCheckedAll = false })
this.dataListCheckAll() this.selectedItems.key = 'bu3id'
this.selectedItems.count = 0
this.bu3.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
this.bu3ListLoading = false this.bu3.loading = false
this.cdr.detectChanges() this.cdr.detectChanges()
} }
}) })
} }
onBu3TableSearchChange() {
this.bu3Table.currentPage = 1
this.bu3Table.page = Array.from({ length: Math.ceil(this.filterBu3Table().length / 10) }, (_, i) => i + 1);
this.dataListCheck()
}
filterBu3Table() {
return this.bu3List.filter(x => {
const data = x.data
return data.bu3id.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu3Table.search.toLowerCase())
})
}
selectBu3(bu3?: Bu3Model) { selectBu3(bu3?: Bu3Model) {
this.bu3 = new MyBu3Model(bu3) if (bu3) {
this.bu3.select = new MyBu3Model(bu3)
} else if (this.currentModal == 'add') {
this.bu3.select = new MyBu3Model()
} else if (this.currentModal == 'edit') {
this.bu3.select = new MyBu3Model({ bu3id: this.bu3.select.bu3id })
}
this.selectBu2() this.selectBu2()
if (this.bu3.parent) { if (this.bu3.select.parent) {
this.bu2Service.getById(this.bu3.parent).subscribe(response => { this.bu2Service.getById(this.bu3.select.parent).subscribe(response => {
this.bu2 = new MyBu2Model(response) this.bu2 = new MyBu2Model(response)
this.cdr.detectChanges() this.cdr.detectChanges()
}) })
} }
} }
// bu3idChange() {
// const bu3 = this.bu3List.find(x => x.bu3id == this.bu3.bu3id)
// this.selectBu3(bu3 || new MyBu3Model({ bu3id: this.bu3.bu3id }))
// }
onBu3ModalSearchChange() {
this.bu3Modal.currentPage = 1
this.bu3Modal.page = Array.from({ length: Math.ceil(this.filterBu3Modal().length / 10) }, (_, i) => i + 1);
}
filterBu3Modal() {
return this.bu3List.filter(x => {
const data = x.data
return data.bu3id.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.tdesc.toLowerCase().includes(this.bu3Table.search.toLowerCase()) ||
data.edesc.toLowerCase().includes(this.bu3Table.search.toLowerCase())
})
}
addBu3() { addBu3() {
this.bu3ListLoading = true this.bu3.loading = true
this.bu3Service.post({ ...this.bu3, parent: this.bu2.bu2id }).subscribe({ this.bu3Service.post({ ...this.bu3.select, parent: this.bu2.bu2id }).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.getBu3List() this.getBu3List()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu3ListLoading = false this.bu3.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu3ListLoading = false this.bu3.loading = false
} }
}) })
} }
deleteBu3() { deleteBu3() {
this.bu3ListLoading = true this.bu3.loading = true
const body = this.bu3List.filter(x => x.check).map(x => new MyBu3Model(x.data)) const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).map(x => new MyBu3Model(x))
this.bu3Service.delete(body).subscribe({ this.bu3Service.delete(body).subscribe({
next: response => { next: response => {
if (response.success) { if (response.success) {
...@@ -191,11 +180,11 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -191,11 +180,11 @@ export class SectionRegistrationComponent implements OnInit {
this.getBu3List() this.getBu3List()
} else { } else {
this.showAlert(response.message, 'error') this.showAlert(response.message, 'error')
this.bu3ListLoading = false this.bu3.loading = false
} }
}, error: error => { }, error: error => {
this.showAlert(error.message, 'error') this.showAlert(error.message, 'error')
this.bu3ListLoading = false this.bu3.loading = false
} }
}) })
} }
...@@ -230,21 +219,20 @@ export class SectionRegistrationComponent implements OnInit { ...@@ -230,21 +219,20 @@ export class SectionRegistrationComponent implements OnInit {
}) })
} }
dataListCheckAll() { checkPrimary() {
const selectAll = this.isDataListCheckedAll; return this.bu3.dataList.find(x => x.bu3id == this.bu3.select.bu3id)
this.filterBu3Table().forEach(x => x.check = selectAll);
this.dataListCheck();
} }
dataListCheck() {
const dataCheck = this.filterBu3Table(); numSelectItem() {
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false; const selectedKeys = Array.from(this.selectedItems.data.keys());
this.numDataListChecked = this.bu3List.filter(x => x.check).length const num = this.bu3.dataList.filter(x => selectedKeys.includes(x.bu3id) && this.selectedItems.data.get(x.bu3id)).length
this.isDataListChecked = Boolean(this.numDataListChecked) return num
} }
checkPrimary() { onSelectItemChange(arg: any) {
return this.bu3List.find(x => x.data.bu3id == this.bu3.bu3id) this.selectedItems = arg
} }
} }
export const environment = { export const environment = {
production: true, production: true,
firebase: { baseUrl: window.location.origin + '/api',
apiKey: '********************************', }
authDomain: '********************************',
projectId: '********************************',
storageBucket: '********************************',
messagingSenderId: '********************************',
appId: '********************************',
measurementId: '********************************',
},
};
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