From b853b4e7d696d6042e3d26f42b0bd4a00580b3e4 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 8 Feb 2024 18:06:14 +0700 Subject: [PATCH] =?UTF-8?q?API=20=20=E0=B8=84=E0=B8=99=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=AD=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/02_organizational/api.organization.ts | 4 +- .../components/DialogSelectPerson.vue | 266 ++++++++++-------- .../components/tableTree.vue | 33 ++- 3 files changed, 167 insertions(+), 136 deletions(-) diff --git a/src/api/02_organizational/api.organization.ts b/src/api/02_organizational/api.organization.ts index d9f9ba3c3..c5e6cd258 100644 --- a/src/api/02_organizational/api.organization.ts +++ b/src/api/02_organizational/api.organization.ts @@ -37,6 +37,6 @@ export default { /**ครองตำแหน่ง */ orgSearchProfile: `${orgProfile}/search`, - orgProfile: `${orgProfile}`, - orgDeleteProfile: (id: string) => `${orgProfile}/delete/${id}`, + orgProfile: `${orgPos}/profile`, + orgDeleteProfile: (id: string) => `${orgPos}/profile/delete/${id}`, }; diff --git a/src/modules/02_organizationalNew/components/DialogSelectPerson.vue b/src/modules/02_organizationalNew/components/DialogSelectPerson.vue index cc30a5f7d..0972f3be9 100644 --- a/src/modules/02_organizationalNew/components/DialogSelectPerson.vue +++ b/src/modules/02_organizationalNew/components/DialogSelectPerson.vue @@ -10,7 +10,10 @@ import { useCounterMixin } from "@/stores/mixin"; import { useOrganizational } from "@/modules/02_organizationalNew/store/organizational"; import DialogHeader from "@/components/DialogHeader.vue"; import type { Position } from "@/modules/02_organizationalNew/interface/index/organizational"; -import type { DataOption } from "@/modules/02_organizationalNew/interface/index/Main"; +import type { + DataOption, + NewPagination, +} from "@/modules/02_organizationalNew/interface/index/Main"; import type { OptionType, OptionExecutive, @@ -41,13 +44,19 @@ const levelOpsMain = ref([]); const typeOps = ref([]); const levelOps = ref([]); const dataLevel = ref(); -const selected = ref([]); +const selected = ref([]); const isSit = ref(false); const executiveOps = ref([]); const store = useOrganizational(); const $q = useQuasar(); -const { dialogConfirm, showLoader, success, hideLoader, messageError } = - useCounterMixin(); +const { + dialogConfirm, + showLoader, + success, + hideLoader, + messageError, + dialogMessageNotify, +} = useCounterMixin(); const modal = defineModel("modal", { required: true }); // const modal = ref(true); @@ -58,6 +67,10 @@ const props = defineProps({ require: true, }, dataDetailPos: { type: Object, require: true }, + fetchDataTable: { + type: Function, + required: true, + }, }); const row = ref([]); const rowResult = ref([]); @@ -319,20 +332,13 @@ function updateSelectType(val: string) { /** ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม */ function validateForm() { - // const hasError = []; - // for (const key in objectRef) { - // if (Object.prototype.hasOwnProperty.call(objectRef, key)) { - // const property = objectRef[key]; - // if (property.value && typeof property.value.validate === "function") { - // const isValid = property.value.validate(); - // hasError.push(isValid); - // } - // } - // } - // if (hasError.every((result) => result === true)) { - onSubmit(); - // } else { - // } + if (selected.value.length === 0) { + dialogMessageNotify($q, "กรุณาเลือกรายการตำแหน่ง"); + } else if (selectedProfile.value.length === 0) { + dialogMessageNotify($q, "กรุณาเลือกคนครอง"); + } else { + onSubmit(); + } } /** ฟังชั่น บันทึก */ @@ -340,26 +346,32 @@ function onSubmit() { dialogConfirm( $q, () => { - console.log("ตำแหน่ง==>", selected.value); - console.log("ทับที่==>", isSit); - // showLoader(); - // http - // .post(config.API.createOrganization, formData) - // .then((res) => { - // status.value = true; - // store.typeOrganizational = "draft"; - // store.draftId = res.data.result.id; - // success($q, "บันทึกข้อมูลสำเร็จ"); - // // props.fetchActive?.(); - // }) - // .catch((err) => { - // messageError($q, err); - // }) - // .finally(async () => { - // modal.value = await false; - // await close(); - // await hideLoader(); - // }); + // console.log("ตำแหน่ง==>", selected.value[0]?.id); + // console.log("ตำแหน่ง==>", selectedProfile.value[0]?.id); + // console.log("ทับที่==>", isSit.value); + // console.log(props.dataDetailPos); + + const body = { + posMaster: props.dataDetailPos?.id, //*id อัตรากำลัง + position: selected.value[0]?.id, //*id ตำแหน่ง + profileId: selectedProfile.value[0]?.id, //*id profile + isSit: isSit.value, //*นั่งทับที่ไหม + }; + showLoader(); + http + .post(config.API.orgProfile, body) + .then(() => { + props.fetchDataTable?.(store.treeId, store.level, false); + success($q, "บันทึกข้อมูลสำเร็จ"); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(async () => { + modal.value = await false; + close(); + hideLoader(); + }); }, "ยืนยันการเลือกคนครอง", "ต้องการยืนยันการเลือกคนครองตำแหน่งนี้ใช่หรือไม่?" @@ -368,7 +380,9 @@ function onSubmit() { /** เมื่อ enter ให้ทำการ ค้นหาข้อมูล */ const page = ref(1); -const pageSize = ref(20); +const pageSize = ref(10); +const totalPage = ref(0); +const selectedProfile = ref([]); async function searchData() { showLoader(); console.log(formData); @@ -384,6 +398,7 @@ async function searchData() { .post(config.API.orgSearchProfile, reqBody) .then((res) => { console.log(res); + totalPage.value = Math.ceil(res.data.result.total / pageSize.value); const list = res.data.result.data.map((e: any) => ({ id: e.id, citizenId: e.citizenId, @@ -402,25 +417,6 @@ async function searchData() { hideLoader(); }); - // const data = [ - // { - // id: "test1", - // citizenId: "test1", - // name: "test1", - // posTypeName: "test1", - // positionName: "test1", - // posLevelName: "test1", - // }, - // { - // id: "test2", - // citizenId: "test2", - // name: "test2", - // posTypeName: "test2", - // positionName: "test2", - // posLevelName: "test2", - // }, - // ]; - // rowResult.value = data; // props.fetchListDisciplinary?.(); } @@ -429,6 +425,15 @@ function clearPosition() { formData.positionType = ""; formData.positionLevel = ""; } + +watch([() => page.value, () => pageSize.value], () => { + searchData(); +}); + +function updatePagination(newPagination: NewPagination) { + pageSize.value = newPagination.rowsPerPage; + page.value = 1; +}