hrms-mgt/src/modules/12_evaluatePersonal/components/Detail/popupHistory.vue
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 d5f5c722d3 ปรับ table
2024-12-19 14:22:29 +07:00

174 lines
4.6 KiB
Vue

<script setup lang="ts">
import { ref, watch } from "vue";
import { useQuasar } from "quasar";
import http from "@/plugins/http";
import config from "@/app.config";
import type { QTableProps } from "quasar";
/** importComponents */
import HeaderDialog from "@/components/DialogHeader.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
/**use*/
const mixins = useCounterMixin();
const $q = useQuasar();
const { showLoader, hideLoader, date2Thai, messageError } = mixins;
/** รับ props Tab 1 */
const props = defineProps({
id: {
type: String,
require: true,
},
modal: {
type: Boolean,
require: true,
},
close: {
type: Function,
default: () => "",
},
});
const row = ref<any[]>([]); //ข้อมูลรายการประเมิน
const columns = ref<QTableProps["columns"]>([
{
name: "no",
align: "left",
label: "ลำดับ",
sortable: false,
field: "no",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "step",
align: "left",
label: "การแก้ไข",
sortable: true,
field: "step",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "lastUpdateFullName",
align: "left",
label: "ผู้ดำเนินการ",
sortable: true,
field: "lastUpdateFullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "lastUpdatedAt",
align: "left",
label: "วันที่แก้ไข",
sortable: true,
field: "lastUpdatedAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
/**
* ฟังก์ชันเรียกข้อมูลประวัติการประเมิน
* @param id ประเมิน
*/
async function fetchListHistory(id: string) {
showLoader();
const thaiOptions: Intl.DateTimeFormatOptions = {
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
await http
.get(config.API.evaluationHistory(id))
.then((res) => {
const data = res.data.result;
const list = data.map((e: any) => ({
step: e.step,
lastUpdateFullName: e.lastUpdateFullName,
lastUpdatedAt: `${date2Thai(e.lastUpdatedAt)} เวลา ${new Date(
e.lastUpdatedAt
).toLocaleTimeString("th-TH", thaiOptions)} น.`,
}));
row.value = list;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* ดูการเปลี่ยนแปลงของ modal
*
* เมื่อ modal เป็น true เรียก 'fetchListHistory' เพิ่อดึงข้อมูลประวัติการประเมิน
*/
watch(
() => props.modal,
() => {
props.modal && props.id && fetchListHistory(props.id);
}
);
</script>
<template>
<q-dialog v-model="props.modal" persistent>
<q-card style="width: 700px; max-width: 80vw">
<HeaderDialog :tittle="'ประวัติการประเมิน'" :close="props.close" />
<q-separator />
<q-card-section class="q-pt-none">
<div class="col-xs-12 col-sm-12 col-md-12 row q-col-gutter-md">
<div class="col-12 q-mt-sm">
<d-table
ref="table"
flat
bordered
:columns="columns"
:rows="row"
dense
:rows-per-page-options="[10, 25, 50, 100]"
>
<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" v-html="col.label" />
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer">
<q-td
v-for="col in props.cols"
:key="col.name"
:props="props"
>
<div v-if="col.name == 'no'">
{{ props.rowIndex + 1 }}
</div>
<div v-else>
{{ col.value ?? "-" }}
</div>
</q-td>
</q-tr>
</template>
</d-table>
</div>
</div>
</q-card-section>
</q-card>
</q-dialog>
</template>
<style lang="scss" scoped></style>