hrms-mgt/src/modules/02_organization/components/DialogHistory.vue

183 lines
4.9 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { ref, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
/**
* importType
*/
import type { QTableProps } from "quasar";
2024-08-01 12:12:28 +07:00
import type { HistoryPostType } from "@/modules/02_organization/interface/index/Main";
2024-01-26 15:20:32 +07:00
/**
* importComponrnts
*/
import DialogHeader from "@/components/DialogHeader.vue";
2024-01-26 15:20:32 +07:00
/**
* use
*/
const $q = useQuasar();
const mixin = useCounterMixin();
const { showLoader, hideLoader, messageError, date2Thai } = mixin;
/**
* props
*/
const modal = defineModel<boolean>("history", { required: true });
const type = defineModel<number>("type", { required: true });
const orgId = defineModel<string>("orgId", { required: true });
/**
* อม Table
*/
const rows = ref<HistoryPostType[]>([]); //ข้อมูลรายการประวัติหน่วยงาน
const columns = ref<QTableProps["columns"]>([
2024-01-26 15:20:32 +07:00
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: (row) => rows.value.indexOf(row) + 1,
2024-01-26 15:20:32 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "orgRevisionName",
align: "left",
label: "ชื่อโครงสร้าง",
sortable: true,
field: "orgRevisionName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "name",
2024-01-26 15:20:32 +07:00
align: "left",
label: "",
2024-01-26 15:20:32 +07:00
sortable: true,
field: "name",
2024-01-26 15:20:32 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
2024-01-26 15:20:32 +07:00
{
name: "lastUpdatedAt",
2024-01-26 15:20:32 +07:00
align: "left",
label: "วันที่แก้ไข",
2024-01-26 15:20:32 +07:00
sortable: true,
field: (v) => date2Thai(v),
2024-01-26 15:20:32 +07:00
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const visibleColumns = ref<string[]>([
"no",
"name",
2024-01-26 15:20:32 +07:00
"orgRevisionName",
"lastUpdatedAt",
2024-01-26 15:20:32 +07:00
]);
/**
* function เรยกขอมลประวหนวยงาน,ประววนราชการ
*/
async function fetchHistory() {
showLoader();
await http
.post(config.API.organizationHistoryPostNew, {
id: orgId.value,
type: type.value,
})
.then(async (res) => {
const data = await res.data.result;
rows.value = data;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
2024-01-26 15:20:32 +07:00
}
/**
* การเปลยนแปลง modal เมอเป true จะเรยกขอมลประวหนวยงาน,ประววนราชการ
*/
2024-01-26 15:20:32 +07:00
watch(
() => modal.value,
2024-01-26 15:20:32 +07:00
() => {
if (modal.value == true) {
fetchHistory();
2024-01-26 15:20:32 +07:00
}
}
);
</script>
<template>
<template>
<q-dialog v-model="modal" persistent>
<q-card style="min-width: 40vw">
<DialogHeader
2024-01-31 17:54:34 +07:00
:tittle="type == 0 ? `ประวัติหน่วยงาน` : `ประวัติส่วนราชการ`"
:close="() => (modal = false)"
/>
2024-01-26 15:20:32 +07:00
<q-separator />
<q-card-section>
<div class="row q-col-gutter-sm">
<div class="col-12">
<d-table
ref="table"
:columns="columns"
:rows="rows"
2024-01-26 15:29:48 +07:00
row-key="orgRevisionId"
2024-01-26 15:20:32 +07:00
flat
bordered
:paging="true"
dense
class="custom-header-table"
:visible-columns="visibleColumns"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th
v-for="col in props.cols"
:key="col.name"
:props="props"
style="color: #000000; font-weight: 500"
>
<span
v-if="col.name === 'name'"
class="text-weight-medium"
>
2024-01-31 17:54:34 +07:00
{{ type === 0 ? "ชื่อหน่วยงาน" : "ส่วนราชการ" }}
</span>
2024-01-26 15:20:32 +07:00
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
2024-01-26 15:20:32 +07:00
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div>
{{ col.value ?? "-" }}
2024-01-26 15:20:32 +07:00
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
2024-01-26 15:20:32 +07:00
</div>
</q-card-section>
</q-card>
</q-dialog>
</template>
</template>