2024-01-26 12:07:49 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, reactive, watch } from "vue";
|
|
|
|
|
import { useQuasar } from "quasar";
|
2024-01-26 15:20:11 +07:00
|
|
|
import http from "@/plugins/http";
|
|
|
|
|
import config from "@/app.config";
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* importType
|
|
|
|
|
*/
|
2024-01-26 12:07:49 +07:00
|
|
|
import type {
|
|
|
|
|
FormDataNewStructure,
|
|
|
|
|
FormNewStructureRef,
|
|
|
|
|
DataOption,
|
2024-01-29 11:19:48 +07:00
|
|
|
HistoryType,
|
2024-08-01 12:12:28 +07:00
|
|
|
} from "@/modules/02_organization/interface/index/Main";
|
2024-01-26 12:07:49 +07:00
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/** importComponents*/
|
|
|
|
|
import DialogHeader from "@/components/DialogHeader.vue";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* importStore
|
|
|
|
|
*/
|
2024-01-26 15:20:11 +07:00
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2024-08-01 12:12:28 +07:00
|
|
|
import { useOrganizational } from "@/modules/02_organization/store/organizational";
|
2024-01-26 15:20:11 +07:00
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* use
|
|
|
|
|
*/
|
2024-01-26 12:07:49 +07:00
|
|
|
const $q = useQuasar();
|
2024-01-26 15:20:11 +07:00
|
|
|
const store = useOrganizational();
|
|
|
|
|
const { dialogConfirm, showLoader, success, hideLoader, messageError } =
|
|
|
|
|
useCounterMixin();
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* props
|
|
|
|
|
*/
|
2024-01-26 15:20:11 +07:00
|
|
|
const modal = defineModel<boolean>("newStructure", { required: true });
|
|
|
|
|
const status = defineModel<boolean>("status", { required: true });
|
2024-01-29 11:19:48 +07:00
|
|
|
const type = defineModel<string>("type", { default: "NEW" });
|
2024-01-29 13:14:13 +07:00
|
|
|
const props = defineProps({
|
|
|
|
|
fetchActive: {
|
|
|
|
|
type: Function,
|
|
|
|
|
require: true,
|
2024-03-05 14:13:46 +07:00
|
|
|
default: () => "fetchActive function",
|
2024-01-29 13:14:13 +07:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-26 12:07:49 +07:00
|
|
|
const typeOp = ref<DataOption[]>([
|
|
|
|
|
{
|
|
|
|
|
id: "NEW",
|
|
|
|
|
name: "สร้างใหม่",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "ORG",
|
|
|
|
|
name: "ทำสำเนาเฉพาะโครงสร้าง",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "ORG_POSITION",
|
|
|
|
|
name: "ทำสำเนาโครงสร้างและตำแหน่ง",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "ORG_POSITION_PERSON",
|
|
|
|
|
name: "ทำสำเนาโครงสร้าง ตำแหน่ง และคนครอง",
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const orgRevisionNameRef = ref<Object | null>(null);
|
|
|
|
|
const typeRef = ref<Object | null>(null);
|
2024-01-29 11:19:48 +07:00
|
|
|
const orgRevisionIdRef = ref<Object | null>(null);
|
2024-01-26 12:07:49 +07:00
|
|
|
|
|
|
|
|
const formData = reactive<FormDataNewStructure>({
|
2024-01-29 11:19:48 +07:00
|
|
|
orgRevisionId: "",
|
2024-01-26 12:07:49 +07:00
|
|
|
orgRevisionName: "",
|
2024-01-29 11:19:48 +07:00
|
|
|
typeDraft: "",
|
2024-01-26 12:07:49 +07:00
|
|
|
});
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* maping ref เข้าตัวแปรเพื่อเตรียมตรวจสอบ
|
|
|
|
|
*/
|
2024-01-26 12:07:49 +07:00
|
|
|
const objectRef: FormNewStructureRef = {
|
|
|
|
|
orgRevisionName: orgRevisionNameRef,
|
|
|
|
|
type: typeRef,
|
2024-01-29 11:19:48 +07:00
|
|
|
orgRevisionId: orgRevisionIdRef,
|
2024-01-26 12:07:49 +07:00
|
|
|
};
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังก์ชั่นตรวจสอบความถูกต้องของข้อมูลในฟอร์ม
|
|
|
|
|
*/
|
2024-01-26 12:07:49 +07:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังชั่น บันทึก
|
|
|
|
|
*/
|
2024-01-26 12:07:49 +07:00
|
|
|
function onSubmit() {
|
2024-02-02 14:50:19 +07:00
|
|
|
dialogConfirm(
|
|
|
|
|
$q,
|
|
|
|
|
() => {
|
|
|
|
|
showLoader();
|
|
|
|
|
http
|
|
|
|
|
.post(config.API.createOrganization, formData)
|
2024-08-16 10:26:09 +07:00
|
|
|
.then(async (res) => {
|
|
|
|
|
await props.fetchActive();
|
2024-02-02 14:50:19 +07:00
|
|
|
status.value = true;
|
|
|
|
|
store.typeOrganizational = "draft";
|
|
|
|
|
store.draftId = res.data.result.id;
|
2024-02-15 10:44:56 +07:00
|
|
|
store.statusView = "list";
|
2024-02-02 14:50:19 +07:00
|
|
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
2024-08-16 10:26:09 +07:00
|
|
|
.finally(() => {
|
|
|
|
|
modal.value = false;
|
|
|
|
|
hideLoader();
|
|
|
|
|
close();
|
2024-02-02 14:50:19 +07:00
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
"ยืนยันการเพิ่มโครงสร้าง",
|
|
|
|
|
store.draftId
|
|
|
|
|
? "คุณมีแบบร่างอยู่หากคุณกดยืนยันระบบจะทำการลบแบบร่างเดิมและสร้างแบบร่างใหม่ ต้องการยืนยันการเพิ่มโครงสร้างนี้ใช่หรือไม่?"
|
|
|
|
|
: "ต้องการยืนยันการเพิ่มโครงสร้างนี้ใช่หรือไม่?"
|
|
|
|
|
);
|
2024-01-26 12:07:49 +07:00
|
|
|
}
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* ฟังชั่น ปิด popup
|
|
|
|
|
*/
|
2024-01-26 12:07:49 +07:00
|
|
|
function close() {
|
|
|
|
|
modal.value = false;
|
2024-01-29 11:19:48 +07:00
|
|
|
formData.orgRevisionId = "";
|
|
|
|
|
formData.orgRevisionName = "";
|
|
|
|
|
formData.typeDraft = "";
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-25 11:06:43 +07:00
|
|
|
/**
|
|
|
|
|
* เรียกข้อมูล
|
|
|
|
|
*/
|
|
|
|
|
function fetchOrgRevision() {
|
2024-01-29 11:19:48 +07:00
|
|
|
showLoader();
|
2024-07-25 11:06:43 +07:00
|
|
|
http
|
2024-01-29 11:19:48 +07:00
|
|
|
.get(config.API.organizationHistoryNew)
|
2024-02-06 17:21:46 +07:00
|
|
|
.then(async (res) => {
|
2024-01-29 11:19:48 +07:00
|
|
|
const data = res.data.result.filter(
|
|
|
|
|
(e: HistoryType) => e.orgRevisionIsDraft === false
|
|
|
|
|
);
|
|
|
|
|
if (data) {
|
2024-02-06 17:21:46 +07:00
|
|
|
const currentStr = await data.find(
|
|
|
|
|
(x: any) => x.orgRevisionIsCurrent === true
|
|
|
|
|
);
|
|
|
|
|
formData.orgRevisionId = currentStr ? currentStr.orgRevisionId : null;
|
2024-01-29 11:19:48 +07:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
messageError($q, err);
|
|
|
|
|
})
|
|
|
|
|
.finally(() => {
|
|
|
|
|
hideLoader();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-26 15:20:11 +07:00
|
|
|
watch(
|
|
|
|
|
() => modal.value,
|
|
|
|
|
() => {
|
2024-01-29 11:19:48 +07:00
|
|
|
modal.value && (formData.typeDraft = type.value);
|
|
|
|
|
modal.value && type.value !== "NEW" && fetchOrgRevision();
|
2024-01-26 15:20:11 +07:00
|
|
|
}
|
|
|
|
|
);
|
2024-01-26 12:07:49 +07:00
|
|
|
</script>
|
|
|
|
|
<template>
|
|
|
|
|
<template>
|
|
|
|
|
<q-dialog v-model="modal" persistent>
|
|
|
|
|
<q-card style="min-width: 50vw">
|
|
|
|
|
<form @submit.prevent="validateForm">
|
2024-01-26 12:11:32 +07:00
|
|
|
<DialogHeader :tittle="`เพิ่มโครงสร้าง`" :close="close" />
|
2024-01-26 12:07:49 +07:00
|
|
|
<q-separator />
|
|
|
|
|
|
|
|
|
|
<q-card-section>
|
|
|
|
|
<div class="row q-col-gutter-sm">
|
|
|
|
|
<div class="col-6">
|
|
|
|
|
<q-input
|
|
|
|
|
v-model="formData.orgRevisionName"
|
|
|
|
|
ref="orgRevisionNameRef"
|
|
|
|
|
dense
|
|
|
|
|
outlined
|
|
|
|
|
for="#orgRevisionName"
|
|
|
|
|
label="ชื่อโครงสร้าง"
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
:rules="[(val) => !!val || `${'กรุณากรอกชื่อโครงสร้าง'}`]"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="col-6">
|
|
|
|
|
<q-select
|
|
|
|
|
for="#type"
|
|
|
|
|
ref="typeRef"
|
2024-01-29 11:19:48 +07:00
|
|
|
readonly
|
2024-01-26 12:07:49 +07:00
|
|
|
dense
|
|
|
|
|
hide-bottom-space
|
|
|
|
|
outlined
|
|
|
|
|
option-label="name"
|
|
|
|
|
option-value="id"
|
|
|
|
|
emit-value
|
|
|
|
|
map-options
|
2024-01-29 11:19:48 +07:00
|
|
|
v-model="formData.typeDraft"
|
2024-01-26 12:07:49 +07:00
|
|
|
:options="typeOp"
|
|
|
|
|
label="ประเภทการโคลน"
|
|
|
|
|
:rules="[(val) => !!val || `${'กรุณาเลือกประเภทการโคลน'}`]"
|
|
|
|
|
lazy-rules
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</q-card-section>
|
|
|
|
|
<q-separator />
|
|
|
|
|
<q-card-actions align="right" class="bg-white text-teal">
|
|
|
|
|
<q-btn type="submit" :label="`บันทึก`" color="public" />
|
|
|
|
|
</q-card-actions>
|
|
|
|
|
</form>
|
|
|
|
|
</q-card>
|
|
|
|
|
</q-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
</template>
|