Commit 86f746d2 by Nattana Chaiyamat

ข้อมูลทั่วไป

parent 7b2e3831
import { ChangeDetectorRef, Component } from '@angular/core'; import { ChangeDetectorRef, Component } from '@angular/core';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model'; import { Bu1Model, MyBu1Model } from 'src/app/shared/model/bu1.model';
import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model'; import { Bu2Model, MyBu2Model } from 'src/app/shared/model/bu2.model';
...@@ -28,9 +29,6 @@ import { PositionService } from 'src/app/shared/services/position.service'; ...@@ -28,9 +29,6 @@ import { PositionService } from 'src/app/shared/services/position.service';
styleUrls: ['./import-data.component.scss'] styleUrls: ['./import-data.component.scss']
}) })
export class ImportDataComponent { export class ImportDataComponent {
currentPage = 1
page = Array.from({ length: 1 }, (_, i) => i + 1);
pageSize = 10
search = "" search = ""
jobCodeList: JobCodeModel[] = [] jobCodeList: JobCodeModel[] = []
loading = false loading = false
...@@ -39,7 +37,6 @@ export class ImportDataComponent { ...@@ -39,7 +37,6 @@ export class ImportDataComponent {
selectedFileName: string = 'กรุณาเลือกไฟล์'; selectedFileName: string = 'กรุณาเลือกไฟล์';
selectJob: JobCodeModel = new MyJobCodeModel({}) selectJob: JobCodeModel = new MyJobCodeModel({})
modalStatus = ''
positionList: PositionModel[] = [] positionList: PositionModel[] = []
positionId = '' positionId = ''
...@@ -68,6 +65,30 @@ export class ImportDataComponent { ...@@ -68,6 +65,30 @@ export class ImportDataComponent {
supervisorPositionId = '' supervisorPositionId = ''
employeeList: EmployeeModel[] = [] employeeList: EmployeeModel[] = []
checkJobCodeId = false checkJobCodeId = false
currentModal: 'add' | 'edit' | 'delete' = "add"
columns: ColumnModel[] = [{
field: "jobcodeId",
headerText: "ชื่อล็อกอิน",
type: "string",
isPrimaryKey: true,
},
{
field: "tdesc",
headerText: "ชื่อลักษณะงาน (ไทย)",
type: "string"
},
{
field: "edesc",
headerText: "ชื่อลักษณะงาน (อังกฤษ)",
type: "string"
}]
searchSettings = {
fields: ['jobcodeId', 'tdesc', 'edesc'],
operator: 'contains',
ignoreCase: false
}
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
constructor( constructor(
private toastr: ToastrService, private toastr: ToastrService,
private fileService: FileService, private fileService: FileService,
...@@ -112,10 +133,13 @@ export class ImportDataComponent { ...@@ -112,10 +133,13 @@ export class ImportDataComponent {
this.loading = false this.loading = false
this.jobcodeService.getList().subscribe({ this.jobcodeService.getList().subscribe({
next: response => { next: response => {
this.jobCodeList = response.map((x: any) => new MyJobCodeModel(x)) this.jobCodeList = response.map((x: any) => {
this.jobCodeList = this.jobCodeList.sort((a, b) => a.jobcodeId.localeCompare(b.jobcodeId)) this.selectedItems.data.set(x.jobcodeId, false)
return new MyJobCodeModel(x)
})
this.selectedItems.key = 'jobcodeId'
this.selectedItems.count = 0
this.loading = false this.loading = false
this.searchChange()
this.cdr.detectChanges() this.cdr.detectChanges()
}, error: error => { }, error: error => {
this.loading = false this.loading = false
...@@ -141,7 +165,6 @@ export class ImportDataComponent { ...@@ -141,7 +165,6 @@ export class ImportDataComponent {
this.bu5Id = item.bu5.bu5id this.bu5Id = item.bu5.bu5id
this.bu6Id = item.bu6.bu6id this.bu6Id = item.bu6.bu6id
this.bu7Id = item.bu7.bu7id this.bu7Id = item.bu7.bu7id
console.log("🚀 ~ ImportDataComponent ~ edit ~ this.selectJob:", this.selectJob)
} }
add() { add() {
this.selectJob = new MyJobCodeModel({}) this.selectJob = new MyJobCodeModel({})
...@@ -157,10 +180,6 @@ export class ImportDataComponent { ...@@ -157,10 +180,6 @@ export class ImportDataComponent {
this.bu7Id = '' this.bu7Id = ''
} }
searchChange() {
this.currentPage = 1
this.page = Array.from({ length: Math.ceil(this.jobcodeFilter().length / this.pageSize) }, (_, i) => i + 1);
}
clearValue() { clearValue() {
this.selectJob.jobObjective = '' this.selectJob.jobObjective = ''
...@@ -205,7 +224,9 @@ export class ImportDataComponent { ...@@ -205,7 +224,9 @@ export class ImportDataComponent {
}) })
} }
deleteJob() { deleteJob() {
this.jobcodeService.delete(this.selectJob).subscribe((response: any) => { const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.jobCodeList.filter(x => selectedKeys.includes(x.jobcodeId) && this.selectedItems.data.get(x.jobcodeId)).map(x => new MyJobCodeModel(x))
this.jobcodeService.delete(body).subscribe((response: any) => {
if (response.success) { if (response.success) {
this.showAlert(response.message, 'success') this.showAlert(response.message, 'success')
this.selectJob = new MyJobCodeModel({}) this.selectJob = new MyJobCodeModel({})
...@@ -216,13 +237,7 @@ export class ImportDataComponent { ...@@ -216,13 +237,7 @@ export class ImportDataComponent {
this.cdr.detectChanges() this.cdr.detectChanges()
}) })
} }
jobcodeFilter() {
return this.jobCodeList.filter(x =>
x.tdesc.toLowerCase().includes(this.search.toLowerCase()) ||
x.edesc.toLowerCase().includes(this.search.toLowerCase()) ||
x.jobcodeId.toLowerCase().includes(this.search.toLowerCase())
)
}
onFileSelected(event: any) { onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null; this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์" this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
...@@ -444,4 +459,14 @@ export class ImportDataComponent { ...@@ -444,4 +459,14 @@ export class ImportDataComponent {
checkPrimary() { checkPrimary() {
return this.jobCodeList.find(x => x.jobcodeId == this.selectJob.jobcodeId) return this.jobCodeList.find(x => x.jobcodeId == this.selectJob.jobcodeId)
} }
numSelectItem() {
const selectedKeys = Array.from(this.selectedItems.data.keys());
const num = this.jobCodeList.filter(x => selectedKeys.includes(x.jobcodeId) && this.selectedItems.data.get(x.jobcodeId)).length
return num
}
onSelectItemChange(arg: any) {
this.selectedItems = arg
}
} }
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