Refactoring code module 02_organization

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-11 17:00:27 +07:00
parent 63b9aafbaf
commit 0f5d772e53
24 changed files with 805 additions and 1033 deletions

View file

@ -1,8 +1,11 @@
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/**
* importType
@ -17,12 +20,6 @@ import type {
/** importComponents*/
import DialogHeader from "@/components/DialogHeader.vue";
/**
* importStore
*/
import { useCounterMixin } from "@/stores/mixin";
import { useOrganizational } from "@/modules/02_organization/store/organizational";
/**
* use
*/
@ -45,6 +42,7 @@ const props = defineProps({
},
});
//
const typeOp = ref<DataOption[]>([
{
id: "NEW",
@ -64,10 +62,7 @@ const typeOp = ref<DataOption[]>([
},
]);
const orgRevisionNameRef = ref<Object | null>(null);
const typeRef = ref<Object | null>(null);
const orgRevisionIdRef = ref<Object | null>(null);
//
const formData = reactive<FormDataNewStructure>({
orgRevisionId: "",
orgRevisionName: "",
@ -75,42 +70,14 @@ const formData = reactive<FormDataNewStructure>({
});
/**
* maping ref เขาตวแปรเพอเตรยมตรวจสอบ
*/
const objectRef: FormNewStructureRef = {
orgRevisionName: orgRevisionNameRef,
type: typeRef,
orgRevisionId: orgRevisionIdRef,
};
/**
* งกนตรวจสอบความถกตองของขอมลในฟอร
*/
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();
}
}
/**
* งช นท
* งกนยนยนการบนทกการกสรางโครงสราง
*/
function onSubmit() {
dialogConfirm(
$q,
() => {
async () => {
showLoader();
http
await http
.post(config.API.createOrganization, formData)
.then(async (res) => {
await props.fetchActive();
@ -119,14 +86,13 @@ function onSubmit() {
store.draftId = res.data.result.id;
store.statusView = "list";
success($q, "บันทึกข้อมูลสำเร็จ");
close();
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
modal.value = false;
hideLoader();
close();
});
},
"ยืนยันการเพิ่มโครงสร้าง",
@ -137,7 +103,7 @@ function onSubmit() {
}
/**
* popup
* popup และกำหนดฟอรมเพมโครงสรางเป Default
*/
function close() {
modal.value = false;
@ -147,7 +113,7 @@ function close() {
}
/**
* เรยกขอม
* งกเรยกขอมประวโครงสราง
*/
function fetchOrgRevision() {
showLoader();
@ -159,7 +125,7 @@ function fetchOrgRevision() {
);
if (data) {
const currentStr = await data.find(
(x: any) => x.orgRevisionIsCurrent === true
(x: HistoryType) => x.orgRevisionIsCurrent === true
);
formData.orgRevisionId = currentStr ? currentStr.orgRevisionId : null;
}
@ -172,6 +138,11 @@ function fetchOrgRevision() {
});
}
/**
* การเปลยนแปลง modal เมอเป true
*
* type ไมเปนการสรางใหมใหเรยกขอมลประวโครงสราง
*/
watch(
() => modal.value,
() => {
@ -184,7 +155,7 @@ watch(
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 50vw">
<form @submit.prevent="validateForm">
<q-form greedy @submit.prevent @validation-success="onSubmit">
<DialogHeader :tittle="`เพิ่มโครงสร้าง`" :close="close" />
<q-separator />
@ -227,7 +198,7 @@ watch(
<q-card-actions align="right" class="bg-white text-teal">
<q-btn type="submit" :label="`บันทึก`" color="public" />
</q-card-actions>
</form>
</q-form>
</q-card>
</q-dialog>
</template>