diff --git a/src/api/11_discipline/api.discipline.ts b/src/api/11_discipline/api.discipline.ts index a51fbc573..0a668bdd8 100644 --- a/src/api/11_discipline/api.discipline.ts +++ b/src/api/11_discipline/api.discipline.ts @@ -50,6 +50,8 @@ export default { investigateApprove: (id: string) => `${investigate}/approve/${id}`, investigateCalendar: () => `${investigate}/calendar`, investigateReport: () => `${investigate}/report`, + investigateEditDuty: (disciplineId: string, id: string) => + `${investigate}/director/${disciplineId}/${id}`, /** ระบบวินัยเรื่องสอบสวน */ disciplineDisciplinary: () => `${discipline}`, @@ -70,6 +72,8 @@ export default { /** รายการสรุปผลการพิจารณาทางวินัย*/ listResult: () => `${disciplineMain}/result`, listResultById: (id: string) => `${disciplineMain}/result/${id}`, + disciplinaryEditDuty: (disciplineId: string, id: string) => + `${discipline}/director/${disciplineId}/${id}`, /** ผู้ถูกพักราชการ */ suspendMain: (page: number, pageSize: number, keyword: string) => diff --git a/src/modules/11_discipline/components/2_InvestigateFacts/Form.vue b/src/modules/11_discipline/components/2_InvestigateFacts/Form.vue index 484c79e24..d13c621ec 100644 --- a/src/modules/11_discipline/components/2_InvestigateFacts/Form.vue +++ b/src/modules/11_discipline/components/2_InvestigateFacts/Form.vue @@ -280,6 +280,7 @@ watch(props.data, async () => { const dataMap = props.data.directors.map((item: any) => ({ id: item.id, + directorId: item.directorId, name: `${item.prefix}${item.firstName} ${item.lastName}`, prefix: item.prefix, firstName: item.firstName, @@ -287,6 +288,7 @@ watch(props.data, async () => { position: item.position, email: item.email, phone: item.phone, + duty: item.duty, })); rows.value = dataMap; @@ -552,30 +554,34 @@ function emitPerson(data: FormData[]) { } const modalEditDirector = ref(false); -function openEditDirector(id: string) { +const editDirectorId = ref(); +const dutyVal = ref(); +function openEditDirector(id: string, duty: string) { + editDirectorId.value = id; modalEditDirector.value = true; + dutyVal.value = duty; } -function closeEditDirector(id: string) { +function closeEditDirector() { modalEditDirector.value = false; } -async function saveDuty(id: string) { - // showLoader(); - // await http - // .put(config.API.reportresult(idPath.value, type.value as string), body) - // .then((res: any) => { - // success($q, `${props.title}สำเร็จ`); - // props.closeModal?.(); - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(async () => { - // props.getData?.(); - // hideLoader(); - // }); -} +const saveDuty = async (id: string, duty: string) => { + showLoader(); + await http + .put(config.API.investigateEditDuty(formData.id, id), { duty: duty }) + .then((res: any) => { + success($q, "บันทึกสำเร็จ"); + closeEditDirector(); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + props.getData?.(); + hideLoader(); + }); +}; onMounted(async () => { mainStore.rowsAdd = []; @@ -1156,7 +1162,12 @@ onMounted(async () => { flat round color="blue" - @click="openEditDirector(props.row.id)" + @click=" + openEditDirector( + props.row.directorId, + props.row.duty + ) + " icon="mdi-pencil-outline" > แก้ไข @@ -1164,7 +1175,9 @@ onMounted(async () => { ({ + idRaw: item.id, id: item.directorId, name: `${item.prefix}${item.firstName} ${item.lastName}`, prefix: item.prefix, @@ -316,6 +323,7 @@ async function fetchDatadetail() { position: item.position, email: item.email, phone: item.phone, + duty: item.duty, })); rows.value = dataMap; @@ -346,23 +354,6 @@ function deletePerson(id: string) { mainStore.rowsAdd = updatedRows; } -async function saveDuty(id: string) { - // showLoader(); - // await http - // .put(config.API.reportresult(idPath.value, type.value as string), body) - // .then((res: any) => { - // success($q, `${props.title}สำเร็จ`); - // props.closeModal?.(); - // }) - // .catch((e) => { - // messageError($q, e); - // }) - // .finally(async () => { - // props.getData?.(); - // hideLoader(); - // }); -} - /** * เช็คข้อมูลจาก props * เมื่อมีข้อมูล @@ -544,14 +535,35 @@ function emitPerson(data: PersonsArray[]) { } const modalEditDirector = ref(false); -function openEditDirector(id: string) { +const editDirectorId = ref(); +const dutyVal = ref(); +function openEditDirector(idVal: string, duty: string) { + editDirectorId.value = idVal; modalEditDirector.value = true; + dutyVal.value = duty; } -function closeEditDirector(id: string) { +function closeEditDirector() { modalEditDirector.value = false; } +const saveDuty = async (id: string, duty: string) => { + showLoader(); + await http + .put(config.API.disciplinaryEditDuty(props.data.id, id), { duty: duty }) + .then((res: any) => { + success($q, "บันทึกสำเร็จ"); + closeEditDirector(); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + props.fetchData(); + hideLoader(); + }); +}; + /** Hook */ onMounted(async () => { mainStore.rowsAdd = []; @@ -1320,7 +1332,9 @@ onMounted(async () => { flat round color="blue" - @click="openEditDirector(props.row.id)" + @click=" + openEditDirector(props.row.idRaw, props.row.duty) + " icon="mdi-pencil-outline" > แก้ไข @@ -1328,7 +1342,9 @@ onMounted(async () => { -import { ref, computed, watchEffect, watch, type PropType } from "vue"; +import { + ref, + computed, + watchEffect, + watch, + type PropType, + onMounted, +} from "vue"; import { QForm, useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; @@ -11,10 +18,15 @@ const { showLoader, success, messageError, dialogConfirm, hideLoader } = mixin; const props = defineProps({ modal: Boolean, + id: String, closePopup: Function, + duty: { + type: String, + default: "", + }, save: { type: Function, - default: "" + default: () => console.log("not function"), }, }); @@ -24,22 +36,27 @@ const myForm = ref(null); /** * ฟังก์ชั่น Save */ - const submit = async () => { +const submit = async () => { if (myForm.value !== null) { myForm.value.validate().then((success) => { if (success) { dialogConfirm( $q, async () => { - await props.save(); + await props.save(props.id, duty.value); + duty.value = ""; }, - "ยืนยันการแก้ไขข้อมูล", - "ต้องการยืนยันการแก้ไขข้อมูลเพื่อลงบัญชีแนบท้ายหรือไม่?" + "ยืนยันการบันทึกข้อมูล", + "ต้องการยืนยันการบันทึกข้อมูลหรือไม่?" ); } }); } }; + +watch(props, () => { + duty.value = props?.duty; +});