fix bug ลา
This commit is contained in:
parent
cf36f1c150
commit
e726510691
3 changed files with 42 additions and 48 deletions
|
|
@ -60,48 +60,34 @@ const formRef: RehabilitationForm = {
|
|||
};
|
||||
|
||||
/** ฟังก์ชั่นตรวจสอบความถูกต้องก่อน บันทึก */
|
||||
function onValidate() {
|
||||
const hasError = [];
|
||||
for (const key in formRef) {
|
||||
if (Object.prototype.hasOwnProperty.call(formRef, key)) {
|
||||
const property = formRef[key];
|
||||
if (property.value && typeof property.value.validate === "function") {
|
||||
const isValid = property.value.validate();
|
||||
hasError.push(isValid);
|
||||
}
|
||||
}
|
||||
async function onValidate() {
|
||||
const formData = new FormData();
|
||||
if (formDataRehabilitation.leaveDocument.length > 0) {
|
||||
formDataRehabilitation.leaveDocument.forEach((file: File) => {
|
||||
formData.append("leaveDocument", file);
|
||||
});
|
||||
}
|
||||
if (hasError.every((result) => result === true)) {
|
||||
const formData = new FormData();
|
||||
|
||||
if (formDataRehabilitation.leaveDocument.length > 0) {
|
||||
formDataRehabilitation.leaveDocument.forEach((file: File) => {
|
||||
formData.append("leaveDocument", file);
|
||||
});
|
||||
// formData.append("leaveDocument", formDataRehabilitation.leaveDocument)
|
||||
}
|
||||
|
||||
if (formDataRehabilitation.leaveDraftDocument) {
|
||||
formData.append(
|
||||
"leaveDraftDocument",
|
||||
formDataRehabilitation.leaveDraftDocument
|
||||
);
|
||||
}
|
||||
|
||||
formData.append("type", formDataRehabilitation.type); //
|
||||
if (formDataRehabilitation.leaveDraftDocument) {
|
||||
formData.append(
|
||||
"leaveStartDate",
|
||||
dateToISO(new Date(formDataRehabilitation.leaveStartDate))
|
||||
); //
|
||||
formData.append(
|
||||
"leaveEndDate",
|
||||
dateToISO(new Date(formDataRehabilitation.leaveEndDate))
|
||||
"leaveDraftDocument",
|
||||
formDataRehabilitation.leaveDraftDocument
|
||||
);
|
||||
formData.append("leaveWrote", formDataRehabilitation.leaveWrote); //
|
||||
formData.append("leaveDetail", formDataRehabilitation.leaveDetail); //
|
||||
formData.append("leaveTotal", formDataRehabilitation.leaveTotal); //
|
||||
props.onSubmit(formData, isLeave.value);
|
||||
}
|
||||
|
||||
formData.append("type", formDataRehabilitation.type); //
|
||||
formData.append(
|
||||
"leaveStartDate",
|
||||
dateToISO(new Date(formDataRehabilitation.leaveStartDate))
|
||||
);
|
||||
formData.append(
|
||||
"leaveEndDate",
|
||||
dateToISO(new Date(formDataRehabilitation.leaveEndDate))
|
||||
);
|
||||
formData.append("leaveWrote", formDataRehabilitation.leaveWrote); //
|
||||
formData.append("leaveDetail", formDataRehabilitation.leaveDetail); //
|
||||
formData.append("leaveTotal", formDataRehabilitation.leaveTotal); //
|
||||
props.onSubmit(formData, isLeave.value);
|
||||
}
|
||||
|
||||
/** ส่วนของการประกาศและเลือกไฟล์เอกสารประกอบ */
|
||||
|
|
@ -118,6 +104,7 @@ const fileUploadDoc = async (files: any) => {
|
|||
*/
|
||||
const isLeave = ref<boolean>(true);
|
||||
async function FetchCheck() {
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.leaveCheck(), {
|
||||
type: dataStore.typeId ?? null,
|
||||
|
|
@ -131,6 +118,9 @@ async function FetchCheck() {
|
|||
})
|
||||
.catch((e: any) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -161,8 +151,6 @@ const leaveDocumentList = ref<any>();
|
|||
const leaveDraftDocument = ref<string>();
|
||||
const statusCheck = ref<string>("");
|
||||
watch(props.data, () => {
|
||||
console.log(props.data);
|
||||
|
||||
if (props.data) {
|
||||
formDataRehabilitation.leaveWrote = props.data.leaveWrote;
|
||||
formDataRehabilitation.leaveStartDate = new Date(props.data.leaveStartDate);
|
||||
|
|
@ -187,6 +175,7 @@ onMounted(() => {
|
|||
leaveDocumentList.value = props.data.leaveDocument;
|
||||
statusCheck.value = props.data.status;
|
||||
leaveId.value = props.data.id;
|
||||
FetchCheck();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
@ -196,7 +185,8 @@ onMounted(() => {
|
|||
<q-icon name="mdi-numeric-3-circle" size="20px" color="primary" />
|
||||
<div class="q-pl-sm text-weight-bold text-dark">กรอกข้อมูล</div>
|
||||
</div>
|
||||
<form @submit.prevent="onValidate">
|
||||
|
||||
<q-form greedy @submit.prevent @validation-success="onValidate">
|
||||
<q-card bordered class="q-pa-md bg-grey-1">
|
||||
<div class="row q-pa-sm q-col-gutter-sm">
|
||||
<q-input
|
||||
|
|
@ -504,5 +494,5 @@ onMounted(() => {
|
|||
>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</q-form>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import type {
|
|||
} from "@/modules/05_leave/interface/response/leave";
|
||||
|
||||
const mixin = useCounterMixin();
|
||||
const { date2Thai, messageError } = mixin;
|
||||
const { date2Thai, messageError, showLoader, hideLoader } = mixin;
|
||||
const $q = useQuasar();
|
||||
const type = ref<string>("00000000-0000-0000-0000-000000000000");
|
||||
const status = ref<string>("ALL");
|
||||
|
|
@ -283,6 +283,7 @@ export const useLeaveStore = defineStore("Leave", () => {
|
|||
|
||||
//ดึงข้อมูล profile จาก API
|
||||
async function fetchProfile() {
|
||||
showLoader();
|
||||
await http
|
||||
.post(config.API.leaveProfile(), { type: typeId.value })
|
||||
.then((res: any) => {
|
||||
|
|
@ -311,6 +312,9 @@ export const useLeaveStore = defineStore("Leave", () => {
|
|||
})
|
||||
.catch((e: any) => {
|
||||
messageError($q, e);
|
||||
})
|
||||
.finally(() => {
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ async function fetchDataDetail(id: string) {
|
|||
formData.dear = data.dear ?? "-";
|
||||
formData.leaveLast = data.leaveLast ?? "-";
|
||||
formData.leaveRange = data.leaveRange;
|
||||
dataStore.fetchProfileOld(data);
|
||||
await dataStore.fetchProfileOld(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
|
|
@ -229,8 +229,8 @@ function onSubmit(formData: FormData, isLeave: boolean = true) {
|
|||
showLoader();
|
||||
await http
|
||||
.put(config.API.leaveUserId(personalId.value), formData)
|
||||
.then(() => {
|
||||
fetchDataDetail(personalId.value);
|
||||
.then(async () => {
|
||||
await fetchDataDetail(personalId.value);
|
||||
success($q, "บันทึกสำเร็จ");
|
||||
})
|
||||
.catch((e: any) => {
|
||||
|
|
@ -284,13 +284,13 @@ async function onClickDelete(id: string, docId: string) {
|
|||
await http
|
||||
.delete(config.API.leaveDocumentId(id, docId))
|
||||
.then(async (res) => {
|
||||
await fetchDataDetail(personalId.value);
|
||||
success($q, "ลบไฟล์สำเร็จ");
|
||||
})
|
||||
.catch((err) => {
|
||||
messageError($q, err);
|
||||
})
|
||||
.finally(() => {
|
||||
fetchDataDetail(personalId.value);
|
||||
hideLoader();
|
||||
});
|
||||
}
|
||||
|
|
@ -298,8 +298,8 @@ async function onClickDelete(id: string, docId: string) {
|
|||
/**เมื่อเริ่มโหลดหน้า
|
||||
* เรียกใช้งาน fetchData เพื่อดึงข้อมูล
|
||||
*/
|
||||
onMounted(() => {
|
||||
fetchDataDetail(personalId.value);
|
||||
onMounted(async () => {
|
||||
await fetchDataDetail(personalId.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue