hrms-user/src/modules/10_registry/04_Achievement/03_Insignia.vue

615 lines
17 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { useQuasar, type QTableProps } from "quasar";
2024-09-10 15:10:18 +07:00
import { ref, onMounted } from "vue";
import http from "@/plugins/http";
import config from "@/app.config";
2024-09-10 15:10:18 +07:00
import { useCounterMixin } from "@/stores/mixin";
import type { InsigniaFormType } from "@/modules/10_registry/interface/index/Main";
//history dialog
import DialogHistory from "@/modules/10_registry/Dialog/DialogHistory.vue";
2024-06-26 14:35:19 +07:00
const idByRow = ref<string>("");
2024-09-10 15:10:18 +07:00
const rows = ref<InsigniaFormType[]>([]);
const filter = ref<string>("");
2024-09-10 15:10:18 +07:00
const rowsHistory = ref<InsigniaFormType[]>([]);
const $q = useQuasar();
2024-09-10 15:10:18 +07:00
const mode = ref<boolean>($q.screen.gt.xs);
const mixin = useCounterMixin();
const { showLoader, hideLoader, messageError, date2Thai } = mixin;
const modalHistory = ref<boolean>(false);
/** ตัวแปรข้อมูล */
const visibleColumns = ref<String[]>([
"insignia",
"insigniaType",
"year",
"no",
"issue",
"volumeNo",
"volume",
"section",
"page",
"receiveDate",
"dateAnnounce",
"refCommandNo",
"refCommandDate",
"note",
]);
const columns = ref<QTableProps["columns"]>([
{
name: "year",
align: "left",
label: "ปีที่ยื่นขอ",
sortable: true,
field: "year",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => v + 543,
},
{
name: "receiveDate",
align: "left",
label: "วันที่ได้รับ",
sortable: true,
field: "receiveDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "insignia",
align: "left",
label: "ชื่อเครื่องราชฯ",
sortable: true,
field: "insigniaId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "insigniaType",
align: "left",
label: "ลำดับชั้น",
sortable: true,
field: (v) => v.insignia.insigniaType.name,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "no",
align: "left",
label: "ลำดับที่",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "issue",
align: "left",
label: "ราชกิจจาฯ ฉบับที่",
sortable: true,
field: "issue",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "volumeNo",
align: "left",
label: "เล่มที่",
sortable: true,
field: "volumeNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "volume",
align: "left",
label: "เล่ม",
sortable: true,
field: "volume",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "section",
align: "left",
label: "ตอน",
sortable: true,
field: "section",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "page",
align: "left",
label: "หน้า",
sortable: true,
field: "page",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "dateAnnounce",
align: "left",
label: "วันที่ประกาศในราชกิจจาฯ",
sortable: true,
field: "dateAnnounce",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "refCommandNo",
align: "left",
label: "เลขที่คำสั่ง",
sortable: true,
field: "refCommandNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "refCommandDate",
align: "left",
label: "เอกสารอ้างอิง (ลงวันที่)",
sortable: true,
field: "refCommandDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "note",
align: "left",
label: "หมายเหตุ",
sortable: true,
field: "note",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
const visibleColumnsHistory = ref<string[]>([
"insignia",
"insigniaType",
"year",
"no",
"issue",
"volumeNo",
"volume",
"section",
"page",
"receiveDate",
"dateAnnounce",
"refCommandNo",
"refCommandDate",
"lastUpdateFullName",
"lastUpdatedAt",
]);
const columnsHistory = ref<QTableProps["columns"]>([
{
name: "year",
align: "left",
label: "ปีที่ยื่นขอ",
sortable: true,
field: "year",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => v + 543,
},
{
name: "receiveDate",
align: "left",
label: "ลงวันที่",
sortable: true,
field: "receiveDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "insignia",
align: "left",
label: "ชื่อเครื่องราชฯ",
sortable: true,
field: "insigniaId",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "insigniaType",
align: "left",
label: "ลำดับชั้น",
sortable: true,
field: (v) => v.insignia.insigniaType.name,
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "no",
align: "left",
label: "ลำดับที่",
sortable: true,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "issue",
align: "left",
label: "ราชกิจจาฯ ฉบับที่",
sortable: true,
field: "issue",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "volumeNo",
align: "left",
label: "เล่มที่",
sortable: true,
field: "volumeNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "volume",
align: "left",
label: "เล่ม",
sortable: true,
field: "volume",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "section",
align: "left",
label: "ตอน",
sortable: true,
field: "section",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "page",
align: "left",
label: "หน้า",
sortable: true,
field: "page",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "dateAnnounce",
align: "left",
label: "วันที่ประกาศในราชกิจจาฯ",
sortable: true,
field: "dateAnnounce",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "refCommandNo",
align: "left",
label: "เลขที่คำสั่ง",
sortable: true,
field: "refCommandNo",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "refCommandDate",
align: "left",
label: "เอกสารอ้างอิง (ลงวันที่)",
sortable: true,
field: "refCommandDate",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdateFullName",
align: "left",
label: "ผู้ดำเนินการ",
sortable: true,
field: "lastUpdateFullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdatedAt",
align: "left",
label: "วันที่แก้ไข",
sortable: true,
field: "lastUpdatedAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
format: (v) => date2Thai(v),
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
2024-06-26 14:35:19 +07:00
function onHistory(id: string) {
modalHistory.value = true;
2024-06-26 14:35:19 +07:00
idByRow.value = id;
}
/** get data */
function getData() {
showLoader();
http
.get(config.API.dataUserCertificate("insignia"))
.then((res) => {
const data = res.data.result;
rows.value = data;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
/** get history */
function getHistory() {
showLoader();
http
2024-06-26 14:35:19 +07:00
.get(config.API.dataUserCertificateHistory("insignia", idByRow.value))
.then((res) => {
const data = res.data.result;
rowsHistory.value = data;
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
onMounted(async () => {
await getData();
});
</script>
<template>
<!-- v-if="mode" -->
<div class="col-12">
<q-toolbar class="q-px-none q-mt-md">
<span class="text-blue-6 text-weight-bold text-body1"
>เครองราชอสรยาภรณ</span
>
<q-space />
<q-input
v-if="mode"
class="inputgreen"
outlined
dense
v-model="filter"
label="ค้นหา"
style="max-width: 200px"
>
<template v-slot:append>
<q-icon
v-if="filter !== ''"
name="clear"
class="cursor-pointer"
@click="filter = ''"
/>
<q-icon
v-else
name="search"
class="cursor-pointer"
@click="filter = ''"
/>
</template>
</q-input>
<q-select
v-if="mode"
class="q-ml-sm"
dense
multiple
outlined
emit-value
map-options
options-cover
options-dense
option-value="name"
style="min-width: 150px"
v-model="visibleColumns"
:options="columns"
:display-value="$q.lang.table.columns"
/>
</q-toolbar>
<div v-if="rows.length != 0">
<d-table
flat
dense
bordered
virtual-scroll
:rows="rows"
:columns="columns"
:grid="!mode"
:filter="filter"
:rows-per-page-options="[10, 25, 50, 100]"
:visible-columns="visibleColumns"
:virtual-scroll-sticky-size-start="48"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width />
</q-tr>
</template>
<template v-if="mode" v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td v-for="(col, index) in props.cols" :key="col.name">
<div v-if="col.name == 'insignia'">
{{ props.row.insignia ? `${props.row.insignia.name} ` : "-"
}}{{
props.row.insignia.shortName
? `(${props.row.insignia.shortName})`
: ""
}}
</div>
<div v-else>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="info"
flat
dense
round
size="14px"
icon="mdi-history"
@click="onHistory(props.row.id)"
>
<q-tooltip>ประวแกไขเครองราชอสรยาภรณ</q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
<template v-else v-slot:item="props">
<div class="q-mb-xs col-xs-12 col-sm-6 col-md-4 col-lg-3">
<q-card bordered flat>
<q-list dense class="q-mt-lg relative-position">
<q-btn
icon="mdi-history"
color="info"
flat
dense
round
size="14px"
class="absolute_button"
@click="onHistory(props.row.id)"
>
<q-tooltip>ประวแกไขเครองราชอสรยาภรณ</q-tooltip>
</q-btn>
<q-item v-for="col in props.cols" :key="col.name">
<q-item-section class="fix_top">
<q-item-label class="text-grey-6 text-weight-medium">{{
col.label
}}</q-item-label>
</q-item-section>
<q-item-section v-if="col.name == 'insignia'" class="fix_top">
<q-item-label class="text-dark text-weight-medium"
>{{
props.row.insignia
? `${props.row.insignia.name} `
: "-"
}}{{
props.row.insignia.shortName
? `(${props.row.insignia.shortName})`
: ""
}}</q-item-label
>
</q-item-section>
<q-item-section v-else class="fix_top">
<q-item-label class="text-dark text-weight-medium">{{
col.value ? col.value : "-"
}}</q-item-label>
</q-item-section>
</q-item>
</q-list>
</q-card>
</div>
</template>
</d-table>
</div>
<div v-else>
<div class="col-12">
<q-card
2024-06-26 14:35:19 +07:00
class="full-width row flex-center q-pa-sm rounded-borders text-weight-medium"
bordered
>
ไมพบขอม
</q-card>
</div>
</div>
</div>
<DialogHistory
v-model:modal="modalHistory"
:title="'ประวัติแก้ไขเครื่องราชอิสริยาภรณ์'"
:getData="getHistory"
:rows="rowsHistory"
:visibleColumns="visibleColumnsHistory"
:columns="columnsHistory"
:type="'insignia'"
/>
</template>
<style scoped>
.absolute_button {
position: absolute;
right: 5px;
top: -20px;
}
.fix_top {
justify-content: start !important;
}
</style>