diff --git a/src/api/registry/api.profile.ts b/src/api/registry/api.profile.ts index 3e379f4f7..60b262952 100644 --- a/src/api/registry/api.profile.ts +++ b/src/api/registry/api.profile.ts @@ -187,7 +187,8 @@ export default { profileHistory: (type: string) => `${profile}search/history/oc/${type}`, //ระบบ ลูกจ้างชั่คราว - employmentId: (profileId: string) => `${profile}employment/${profileId}` + employmentId: (profileId: string) => `${profile}employment/${profileId}`, + employmentHistoryId: (employmentId: string) => `${profile}employment/history/${employmentId}` diff --git a/src/modules/08_registryEmployee/components/EditEmployee/Employment.vue b/src/modules/08_registryEmployee/components/EditEmployee/Employment.vue index 0df181474..a86f15476 100644 --- a/src/modules/08_registryEmployee/components/EditEmployee/Employment.vue +++ b/src/modules/08_registryEmployee/components/EditEmployee/Employment.vue @@ -10,15 +10,25 @@ import type { QTableProps } from "quasar"; import type { FormEmployment, FormEmploymentRef, + EmploymentList, + Respones, } from "@/modules/08_registryEmployee/interface/response/Main"; const $q = useQuasar(); const route = useRoute(); const maxin = useCounterMixin(); -const { date2Thai, dialogConfirm, success, messageError } = maxin; +const { + date2Thai, + dialogConfirm, + dialogRemove, + success, + messageError, + hideLoader, + showLoader, +} = maxin; const profileId = ref(route.params.id.toString()); -const rows = ref([]); +const rows = ref([]); const columns = ref([ { name: "dateEmployment", @@ -42,17 +52,28 @@ const columns = ref([ const visibleColumns = ref(["dateEmployment", "orderEmployment"]); const filter = ref(); onMounted(async () => { - // await fetchList(); + await fetchList(); }); async function fetchList() { + showLoader(); await http .get(config.API.employmentId(profileId.value)) .then((res) => { - console.log(res); + const data = res.data.result; + const list: EmploymentList[] = data.map((e: Respones) => ({ + id: e.id, + orderEmployment: e.command, + dateEmployment: date2Thai(e.date), + dataISO: e.date, + })); + rows.value = list; }) .catch((err) => { - console.log(err); + messageError($q, err); + }) + .finally(() => { + hideLoader(); }); } @@ -71,12 +92,15 @@ const formDataRef: FormEmploymentRef = { function onClickAdd() { modal.value = true; + actions.value = ""; formData.dateEmployment = null; formData.orderEmployment = ""; } function colsePopup() { modal.value = false; + modalHistory.value = false; } +// validateForm function validateForm() { const hasError = []; for (const key in formDataRef) { @@ -89,39 +113,197 @@ function validateForm() { } } if (hasError.every((result) => result === true)) { - onSubmit(); + console.log(formData); + if (actions.value == "edit") { + onSubmitEdit(); + } else onSubmit(); } else { console.log("ไม่ผ่าน "); } } +// การเพิ่ม function onSubmit() { dialogConfirm( $q, async () => { - console.log(formData); - // await http - // .post(config.API.employmentId(profileId.value), formData) - // .then(async () => { - // await fetchList(); - // success($q, "บันทึกข้อมูลสำเร็จ"); - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(() => { - // colsePopup(); - // }); + const data = { + command: formData.orderEmployment, + date: formData.dateEmployment, + }; + await http + .post(config.API.employmentId(profileId.value), data) + .then(async () => { + await fetchList(); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + colsePopup(); + }); }, "ยืนยันการบันทึกข้อมูล", "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" ); } - +// การลบ +function cilckDelete(id: string) { + dialogRemove( + $q, + async () => { + await http + .delete(config.API.employmentId(id)) + .then(async () => { + await fetchList(); + success($q, "ลบข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }); + }, + "ยืนยันการลบข้อมูล", + "ต้องการยืนยันการลบข้อมูลนี้หรือไม่ ?" + ); +} +// การแก้ไข +const actions = ref(""); +const employmentRowId = ref(""); +function clickEdit(data: any, actionstype: string) { + modal.value = true; + actions.value = actionstype; + employmentRowId.value = data.id; + formData.dateEmployment = data.dataISO; + formData.orderEmployment = data.orderEmployment; +} +function onSubmitEdit() { + dialogConfirm( + $q, + async () => { + const data = { + command: formData.orderEmployment, + date: formData.dateEmployment, + }; + await http + .put(config.API.employmentId(employmentRowId.value), data) + .then(async () => { + await fetchList(); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + colsePopup(); + }); + }, + "ยืนยันการบันทึกข้อมูล", + "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" + ); +} +// ประวัติการแก้ไข +const modalHistory = ref(false); +const rowsHis = ref([]); +const columnsHis = ref([ + { + name: "dateEmployment", + align: "left", + label: "วันที่จ้าง", + sortable: false, + field: "dateEmployment", + headerStyle: "font-size: 14px", + style: "font-size: 14px", + }, + { + name: "orderEmployment", + align: "left", + label: "คำสั่งจ้าง", + sortable: false, + field: "orderEmployment", + headerStyle: "font-size: 14px", + style: "font-size: 14px", + }, + { + name: "createdFullName", + align: "left", + label: "ผู้สร้าง", + sortable: false, + field: "createdFullName", + headerStyle: "font-size: 14px", + style: "font-size: 14px", + }, + { + name: "createdAt", + align: "left", + label: "วันที่สร้าง", + sortable: false, + field: "createdAt", + headerStyle: "font-size: 14px", + style: "font-size: 14px", + }, + { + name: "lastUpdateFullName", + align: "left", + label: "ผู้แก้ไข", + sortable: false, + field: "lastUpdateFullName", + headerStyle: "font-size: 14px", + style: "font-size: 14px", + }, + { + name: "lastUpdatedAt", + align: "left", + label: "วันที่แก้ไข", + sortable: false, + field: "lastUpdatedAt", + headerStyle: "font-size: 14px", + style: "font-size: 14px", + }, +]); +const visibleColumnsHis = ref([ + "dateEmployment", + "orderEmployment", + "createdFullName", + "createdAt", + "lastUpdateFullName", + "lastUpdatedAt", +]); +const filterHis = ref(); +async function openPopupHistory(id: string) { + modalHistory.value = true; + showLoader(); + await http + .get(config.API.employmentHistoryId(id)) + .then((res) => { + const data = res.data.result; + const list: EmploymentList[] = data.map((e: Respones) => ({ + id: e.id, + orderEmployment: e.command, + dateEmployment: date2Thai(e.date), + createdFullName: e.createdFullName, + createdAt: date2Thai(e.createdAt), + lastUpdateFullName: e.lastUpdateFullName, + lastUpdatedAt: date2Thai(e.lastUpdatedAt), + })); + rowsHis.value = list; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} const pagination = ref({ descending: true, page: 1, rowsPerPage: 10, }); +const paginationHis = ref({ + descending: true, + page: 1, + rowsPerPage: 10, +}); @@ -314,6 +531,86 @@ const pagination = ref({ + + + + + + ประวัติข้อมูลการจ้าง + + + + + + + +
+ + + +
+
+ + + + +
+
+
diff --git a/src/modules/08_registryEmployee/interface/response/Main.ts b/src/modules/08_registryEmployee/interface/response/Main.ts index 9cb23c57b..4bd6c3f38 100644 --- a/src/modules/08_registryEmployee/interface/response/Main.ts +++ b/src/modules/08_registryEmployee/interface/response/Main.ts @@ -55,5 +55,24 @@ interface FormEmploymentRef { orderEmployment: Object | null [key: string]: any; }; +interface EmploymentList { + id: string + dateEmployment: Date | null + orderEmployment: string + dataISO: Date | null + createdFullName: string + createdAt: Date + lastUpdateFullName: string + lastUpdatedAt: Date +} +interface Respones { + id: string + date: Date + command: string + createdFullName: string + createdAt: Date + lastUpdateFullName: string + lastUpdatedAt: Date +} -export type { employeePosition, FormEmployment, FormEmploymentRef }; +export type { employeePosition, FormEmployment, FormEmploymentRef, EmploymentList, Respones };