hrms-mgt/src/modules/18_command/views/detail.vue

233 lines
8.3 KiB
Vue
Raw Normal View History

2024-09-09 17:26:30 +07:00
<script setup lang="ts">
import { onMounted, ref, watch, reactive, onBeforeMount } from "vue";
2024-09-23 17:00:32 +07:00
import { useQuasar } from "quasar";
2024-09-10 18:03:01 +07:00
2024-09-23 17:00:32 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-10 18:03:01 +07:00
import { useRouter, useRoute } from "vue-router";
import { useCommandDetail } from "@/modules/18_command/store/DetailStore";
2024-09-23 17:00:32 +07:00
import { useCounterMixin } from "@/stores/mixin";
2024-09-10 18:03:01 +07:00
import type { ItemTabs } from "@/modules/18_command/interface/index/Main";
2024-09-23 17:00:32 +07:00
import type { FormDataDetail } from "@/modules/18_command/interface/request/Main";
import Main from "@/modules/18_command/components/Step/0_Main.vue"; //ประมวลผลคำสั่ง
2024-09-10 18:03:01 +07:00
import Detail from "@/modules/18_command/components/Step/1_Detail.vue"; //รายละเอียดคำสั่ง
import ListPersons from "@/modules/18_command/components/Step/2_ListPersons.vue"; //รายชื่อผู้ออกคำสั่ง
import ReceivedCopy from "@/modules/18_command/components/Step/3_ReceivedCopy.vue"; //รายชื่อผู้ได้รับสำเนาคำสั่ง
2024-09-10 18:03:01 +07:00
import Attached from "@/modules/18_command/components/Step/4_Attached.vue"; //คำสั่งและบัญชีแนบท้าบ
2024-09-23 17:00:32 +07:00
const $q = useQuasar();
const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin();
2024-09-10 18:03:01 +07:00
const router = useRouter();
const route = useRoute();
2024-09-23 17:00:32 +07:00
const commandId = ref<string>(route.params.id.toString()); //ID คำสั่ง
2024-09-10 18:03:01 +07:00
const store = useCommandDetail();
const isAttachment = ref<boolean>(true);
2024-09-10 18:03:01 +07:00
const childDetailRef = ref<InstanceType<typeof Detail> | null>(null); //ref components รายละเอียดคำสั่ง
const childListPersonsRef = ref<InstanceType<typeof ListPersons> | null>(null); //ref components รายชื่อผู้ออกคำสั่ง
const childReceivedCopyRef = ref<InstanceType<typeof ReceivedCopy> | null>(
null
); //ref components รายชื่อผู้ได้รับสำเนาคำสั่ง
const childAttachedRef = ref<InstanceType<typeof Attached> | null>(null); //ref components คำสั่งและบัญชีแนบท้าบ
2024-09-24 10:50:42 +07:00
const tabs = ref<string>("Main"); //Tab
const readonly = ref<boolean>(route.name === "commandViewDetailPage"); //อ่านได้อย่างเดียว
const isChangeData = ref<boolean>(false); //การเปลี่ยนแปลงของข้อมูล
//รายการ Tab ละเอียดคำสั่ง
const tabsManu = ref<ItemTabs[]>([
{ label: "ประมวลผลคำสั่ง", name: "Main" },
2024-09-10 18:03:01 +07:00
{ label: "รายละเอียดคำสั่ง", name: "Detail" },
{
label: "รายชื่อผู้ได้รับคำสั่ง",
name: "ListPersons",
},
{
label: "รายชื่อผู้ได้รับสำเนาคำสั่ง",
name: "ReceivedCopy",
},
{ label: "พรีวิวคำสั่ง", name: "Attached" },
2024-09-10 18:03:01 +07:00
]);
2024-09-09 17:26:30 +07:00
2024-09-24 10:50:42 +07:00
let formCommandList = reactive<FormDataDetail>({
2024-09-23 17:00:32 +07:00
id: "",
status: "",
commandTypeName: "",
commandNo: "",
commandYear: null,
detailHeader: "",
detailBody: "",
detailFooter: "",
issue: null,
commandAffectDate: null, //วันที่ลงนาม
commandExcecuteDate: null, //วันที่คำสั่งมีผล
commandSysId: "", // ประเภท คำสั่ง
});
/**
* งกนเชคการเปลนรแปลงของขอม
*
* ามการเปลนยแปลง กำหนด 'isChangeData' เป true
*/
function onCheckChangeData() {
isChangeData.value = true;
}
2024-09-23 17:00:32 +07:00
/**
* งกนดงขอมลรายละเอยดคำส
*
* กำหนดขอมลทไดบมาใหบตวแปร `formData`
*/
async function fetchDataCommandList() {
showLoader();
await http
.get(config.API.commandAction(commandId.value, "tab1"))
.then(async (res) => {
const data = await res.data.result;
2024-09-24 10:50:42 +07:00
formCommandList = data;
store.dataCommand = data;
//รอ API ส่งมา isAttachment.value = data.isAttachment ;
isAttachment.value = true; // จำลอง
isChangeData.value = false; //จำลอง
2024-09-23 17:00:32 +07:00
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* การเปลยนแปลงของ tabs เมอมการเปลยนแปลง
*
* เชคการเปลยนแปลงของขอม าการเปลยนแปลงของขอมลจะบนทกขอม
*/
watch(tabs, (newValue, oldValue) => {
//เช็คการเปลี่ยนแปลงของข้อมูล
if (isChangeData.value) {
const refMap: { [key: string]: any } = {
Detail: childDetailRef,
ListPersons: childListPersonsRef,
ReceivedCopy: childReceivedCopyRef,
Attached: childAttachedRef,
};
refMap[oldValue]?.value?.onSubmit();
}
});
/**
* ทำงานเม Components กเรยกใชงาน
*
* กำหนดค `store.readonly` เม route.name เป "commandViewDetailPage" จะอานขอมลไดอยางเดยว
*/
2024-09-23 17:00:32 +07:00
onMounted(async () => {
store.readonly = route.name === "commandViewDetailPage";
2024-09-23 17:00:32 +07:00
await fetchDataCommandList();
});
2024-09-09 17:26:30 +07:00
</script>
2024-09-10 18:03:01 +07:00
<template>
<div class="toptitle col-12 row items-center">
<q-btn
icon="mdi-arrow-left"
unelevated
round
dense
flat
color="primary"
class="q-mr-sm"
@click="router.go(-1)"
/>
{{
route.name === "commandEditDetailPage"
? "แก้ไขรายละเอียดคำสั่ง"
: "รายละเอียดคำสั่ง"
}}
</div>
<q-card class="q-mt-sm">
<q-card-section style="padding: 0px">
<q-separator />
<q-tabs
v-model="tabs"
inline-label
align="left"
indicator-color="primary"
active-color="primary bg-teal-1"
>
<q-tab
v-for="(tab, index) in tabsManu"
:key="index"
:name="tab.name"
:label="tab.label"
/>
</q-tabs>
<q-separator />
<q-tab-panels v-model="tabs" animated>
<q-tab-panel style="padding: 0px" name="Main">
<q-card>
<Main
ref="childDetailRef"
v-model:is-change-data="isChangeData"
:on-check-change-data="onCheckChangeData"
/>
</q-card>
</q-tab-panel>
<q-tab-panel style="padding: 0px" name="Detail">
<q-card>
<Detail
ref="childDetailRef"
v-model:is-change-data="isChangeData"
:on-check-change-data="onCheckChangeData"
2024-09-23 17:00:32 +07:00
:fetch-data-command-list="fetchDataCommandList"
:form-command-list="formCommandList"
/>
</q-card>
</q-tab-panel>
2024-09-25 10:41:05 +07:00
<q-tab-panel
class="bg-grey-2"
style="padding: 0px;"
name="ListPersons"
>
<ListPersons
ref="childListPersonsRef"
v-model:is-change-data="isChangeData"
:on-check-change-data="onCheckChangeData"
:fetch-data-command-list="fetchDataCommandList"
:command-sys-id="formCommandList?.commandSysId as string"
/>
</q-tab-panel>
<q-tab-panel style="padding: 0px" name="ReceivedCopy">
<q-card>
<ReceivedCopy
ref="childReceivedCopyRef"
v-model:is-change-data="isChangeData"
:on-check-change-data="onCheckChangeData"
/>
</q-card>
</q-tab-panel>
<q-tab-panel style="padding: 0px" name="Attached">
2024-09-10 18:03:01 +07:00
<q-card>
<Attached
ref="childAttachedRef"
v-model:is-change-data="isChangeData"
:on-check-change-data="onCheckChangeData"
v-model:is-attachment="isAttachment"
/>
2024-09-10 18:03:01 +07:00
</q-card>
</q-tab-panel>
</q-tab-panels>
</q-card-section>
</q-card>
</template>
2024-09-09 17:26:30 +07:00
<style scoped></style>