Refactoring code module 05_leave

This commit is contained in:
STW_TTTY\stwtt 2024-09-03 17:36:59 +07:00
parent 763ec2fd95
commit 4253226ac3
23 changed files with 383 additions and 532 deletions

View file

@ -1,7 +1,15 @@
<script setup lang="ts">
import { ref, onMounted, reactive, computed } from "vue";
import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useLeaveStore } from "@/modules/05_leave/store";
import type { FormData } from "@/modules/05_leave/interface/index/main";
//import form
import FormPart2 from "@/modules/05_leave/components/FormLeave/Form.vue";
import SickForm from "@/modules/05_leave/components/FormLeave/01_SickForm.vue";
import FormBirth from "@/modules/05_leave/components/FormLeave/03_Birth.vue";
@ -16,23 +24,11 @@ import WorkInternationalForm from "@/modules/05_leave/components/FormLeave/11_Wo
import FollowSpouseForm from "@/modules/05_leave/components/FormLeave/12_FollowSpouseForm.vue";
import RehabilitationForm from "@/modules/05_leave/components/FormLeave/13_RehabilitationForm.vue";
import { useCounterMixin } from "@/stores/mixin";
import { useQuasar } from "quasar";
import { useRoute, useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import { useLeaveStore } from "@/modules/05_leave/store";
const $q = useQuasar();
const route = useRoute();
const router = useRouter();
/**
* วแปรทใช
*/
const personalId = ref<string>(route.params.id as string);
const leaveId = ref<string>("");
const dataStore = useLeaveStore();
const $q = useQuasar();
const mixin = useCounterMixin();
const {
messageError,
@ -41,21 +37,19 @@ const {
dialogConfirm,
success,
date2Thai,
dateToISO,
dialogRemove,
} = mixin;
const titleName = ref<string>("");
/** Form รายละเอียดข้อมูล*/
const formData = reactive<any>({
const formData = reactive<FormData>({
id: "", //Id
leaveTypeName: "", // Name
leaveTypeId: "", //Id
fullname: "", //
dateSendLeave: null, //
status: "", //
leaveDateStart: null, //
leaveDateEnd: null, //
leaveStartDate: null, //
leaveEndDate: null, //
leaveCount: 0, //
leaveWrote: "", //
leaveAddress: "", //
@ -110,6 +104,29 @@ const formData = reactive<any>({
leaveRange: "",
});
const model = computed(() => {
return (
dataStore.options.find((x) => x.id == formData.leaveTypeId)?.code ?? ""
);
});
const modelSpecific = computed(() => {
const code = dataStore.options.find(
(x) => x.id == formData.leaveTypeId
)?.code;
if (code == "LV-006" && formData.ordainDayLocationName != "") {
return "b1";
} else if (code == "LV-006" && formData.ordainDayLocationName == "") {
return "b2";
} else if (code == "LV-008" && formData.studyDayTrainingSubject == "") {
return "s1";
} else if (code == "LV-008" && formData.studyDayTrainingSubject != "") {
return "s2";
} else {
return "";
}
});
/**
* function เรยกขอมลการลา
* @param id การลา
@ -120,9 +137,7 @@ async function fetchDataDetail(id: string) {
.get(config.API.leaveUserId(id), {})
.then(async (res) => {
const data = await res.data.result;
dataStore.typeId = data.leaveTypeId;
titleName.value = data.fullName ?? "-";
formData.id = data.id ?? "-";
formData.leaveTypeName = data.leaveTypeName ?? "-";
@ -193,9 +208,6 @@ async function fetchDataDetail(id: string) {
formData.dear = data.dear ?? "-";
formData.leaveLast = data.leaveLast ?? "-";
formData.leaveRange = data.leaveRange;
// checkLeaveType(formData.leaveTypeId, formData.leaveTypeName)
dataStore.fetchProfileOld(data);
})
.catch((err) => {
@ -206,30 +218,6 @@ async function fetchDataDetail(id: string) {
});
}
/**modal */
const model = computed(() => {
return (
dataStore.options.find((x) => x.id == formData.leaveTypeId)?.code ?? ""
);
});
const modelSpecific = computed(() => {
const code = dataStore.options.find(
(x) => x.id == formData.leaveTypeId
)?.code;
if (code == "LV-006" && formData.ordainDayLocationName != "") {
return "b1";
} else if (code == "LV-006" && formData.ordainDayLocationName == "") {
return "b2";
} else if (code == "LV-008" && formData.studyDayTrainingSubject == "") {
return "s1";
} else if (code == "LV-008" && formData.studyDayTrainingSubject != "") {
return "s2";
} else {
return "";
}
});
/**
* function นทกขอม
* @param formData อมลใน formdata
@ -259,9 +247,8 @@ function onSubmit(formData: FormData, isLeave: boolean = true) {
/**
* funciotn นใบลา
* @param id id ของใบลา
*/
function onConfirm(id: string) {
function onConfirm() {
dialogConfirm(
$q,
async () => {
@ -277,7 +264,6 @@ function onConfirm(id: string) {
})
.finally(() => {
hideLoader();
// fetchDataDetail(personalId.value);
});
},
"ยืนยันการยื่นใบลา",
@ -286,15 +272,15 @@ function onConfirm(id: string) {
}
//
const clickDelete = (id: string, docId: string) => {
function clickDelete(id: string, docId: string) {
dialogRemove($q, () => onClickDelete(id, docId));
};
}
/**
* function ลบรายการ
* @param id
*/
const onClickDelete = async (id: string, docId: string) => {
async function onClickDelete(id: string, docId: string) {
await http
.delete(config.API.leaveDocumentId(id, docId))
.then(async (res) => {
@ -307,7 +293,7 @@ const onClickDelete = async (id: string, docId: string) => {
fetchDataDetail(personalId.value);
hideLoader();
});
};
}
/**
* เรยกใชงาน fetchData เพอดงขอม
@ -407,7 +393,7 @@ onMounted(() => {
<FormPart2
:model="model"
:data="formData"
:leaveTypeId="formData.leaveTypeId"
:leave-type-id="formData.leaveTypeId"
/>
</div>
</div>