Commit 4637f0fb by Nattana Chaiyamat

ทะเบียนบริษัท

parent 1bc97f85
......@@ -130,13 +130,16 @@ export class CompanyRegistrationPageComponent {
const data = x.data
const match = data.code.toLowerCase().includes(this.search.toLowerCase()) || data.tdesc.toLowerCase().includes(this.search.toLowerCase()) || data.edesc.toLowerCase().includes(this.search.toLowerCase());
return match;
}).forEach(x => (x.check = x.data.code != '100' ? selectAll : false));
}).forEach(x => x.check = selectAll);
this.dataListCheck();
}
dataListCheck() {
const dataCheck = this.dataListFilter();
this.isDataListCheckedAll = dataCheck.length ? dataCheck.every(x => x.check) : false;
this.numDataListChecked = this.dataList.filter(x => x.check).length;
if (this.dataList.some(x => x.check && x.data.code == '100')) {
this.numDataListChecked = this.numDataListChecked - 1
}
this.isDataListChecked = Boolean(this.numDataListChecked)
}
......
......@@ -18,7 +18,8 @@
<div class="px-1">
<button type="button"
class="ti-btn ti-btn bg-pink-500/10 text-pink-500 hover:text-white hover:bg-pink-500 ring-offset-white focus:ring-pink-500 dark:focus:ring-offset-white/10 h-45px m-0 shadow-md"
data-hs-overlay="#group-competencies-modal-add">
data-hs-overlay="#group-competencies-modal-add"
(click)="fileInput.value = '';selectedFile=null;selectedFileName = 'กรุณาเลือกไฟล์'">
<i class="ti ti-file-plus"></i>
import
</button>
......@@ -125,5 +126,42 @@
<ng-container *ngIf="editTab">
<app-edit-group-competencies [pl]="groupCompetencies"
(sendEdit)="editTab=$event;pathTitleChange()" ></app-edit-group-competencies>
(sendEdit)="editTab=$event;pathTitleChange()"></app-edit-group-competencies>
</ng-container>
<div id="group-competencies-modal-add" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out rounded-md">
<div class="ti-modal-header bg-primary !rounded-none !rounded-t-sm">
<h5 class="text-xxl font-bold text-white">
นำเข้ากลุ่มสมรรถนะ
</h5>
</div>
<div class="ti-modal-body max-h-full overflow-hidden ti-modal-content !rounded-t-none !rounded-b-sm">
<h1 class="mt-2" style="text-align: center;">ไฟล์</h1>
<div class="mt-2 p-2">
<div class="flex rounded-md">
<input #fileInput id="fileInput" type="file" (change)="onFileSelected($event)" hidden>
<input type="text" [value]="selectedFileName" readonly (click)="fileInput.click()"
class="ti-form-input rounded-none ltr:rounded-l-md rtl:rounded-r-md focus:z-10 cursor-pointer">
<button type="button" (click)="fileInput.click()"
class="inline-flex flex-shrink-0 justify-center items-center h-[2.875rem] w-[2.875rem] ltr:rounded-r-md rtl:rounded-l-md border border-transparent font-semibold bg-secondary text-white hover:bg-secondary focus:z-10 focus:outline-none focus:ring-0 focus:ring-secondary transition-all text-sm">
<i class="ti ti-upload"></i>
</button>
</div>
<div class="flex justify-center mt-2rem ">
<h1 class="cursor-pointer justify-center -mb-px inline-flex items-center gap-2 font-weight-500 font-size-12px
text-center text-secondary border-secondary border-b-2 align-items-end" (click)="downloadFile()">
ดาวน์โหลดตัวอย่างไฟล์</h1>
</div>
<div class="flex justify-center mt-2rem mb-1rem space-x-4">
<button type="submit" class="ti-btn ti-btn-secondary"
data-hs-overlay="#group-competencies-modal-add" [class.ti-btn-disabled]="!selectedFile"
(click)="uploadFile()" [disabled]="!selectedFile" [disabled]="!selectedFile">
อัปโหลด
</button>
</div>
</div>
</div>
</div>
</div>
\ No newline at end of file
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core';
import { ToastrService } from 'ngx-toastr';
import { MyPLModel, PLModel } from 'src/app/shared/model/pl.model';
import { FileService } from 'src/app/shared/services/file.service';
import { PLService } from 'src/app/shared/services/pl.service';
export interface DataModel {
code: string
......@@ -27,8 +28,11 @@ export class GroupCompetenciesComponent {
groupCompetencies: PLModel = new MyPLModel({})
dataLoading = false
selectedFile: File | null = null;
selectedFileName: string = 'กรุณาเลือกไฟล์';
constructor(private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService,
private pLService: PLService,
) {
this.pathTitleChange()
......@@ -36,6 +40,55 @@ export class GroupCompetenciesComponent {
ngOnInit(): void {
this.getList()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
}
uploadFile() {
if (!this.selectedFile) {
alert('กรุณาเลือกไฟล์ก่อนอัปโหลด')
return
}
const formData = new FormData();
formData.append('file', this.selectedFile);
this.dataLoading = true
this.fileService.uploadExcel(formData, '').subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
}
})
}
downloadFile() {
const fileName = '.xlsx'
this.fileService.downloadTemplate(fileName).subscribe({
next: response => {
const url = window.URL.createObjectURL(response);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, error: error => {
this.showAlert(error.message, 'error')
}
})
}
getList() {
this.dataLoading = true
this.pLService.getList().subscribe({
......@@ -76,37 +129,12 @@ export class GroupCompetenciesComponent {
});
}
showSuccess() {
this.toastr.success('บันทึกข้อมูลสำเร็จ', 'เเจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
}
showSuccessEdit() {
this.toastr.success('เเก้ไขข้อมูลสำเร็จ', 'เเจ้งเตือน', {
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
}
showSuccessDelete() {
this.toastr.success('ลบข้อมูลสำเร็จ', 'เเจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
}
// ฟังก์ชันสำหรับการเพิ่ม ลบ หรือแก้ไข ข้อมูล
addUser() {
console.log('เพิ่มผู้ใช้งาน');
}
deleteUser() {
console.log('ลบผู้ใช้งาน');
})
}
editUser() {
console.log('แก้ไขผู้ใช้งาน');
}
}
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