hrms-admin/src/modules/01_metadata/components/personal/05_BloodGroup.vue

296 lines
8 KiB
Vue
Raw Normal View History

2024-05-29 17:58:57 +07:00
<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useQuasar } from "quasar";
2024-05-29 17:58:57 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
import { useCounterMixin } from "@/stores/mixin";
import { usePersonalDataStore } from "@/modules/01_metadata/stores/personalStore";
import type { QTableProps } from "quasar";
import DialogForm from "@/modules/01_metadata/components/personal/DialogForm.vue"; // เพิ่มข้อมูล,แก้ไขข้อมูล
2024-05-29 17:58:57 +07:00
const $q = useQuasar();
2024-05-29 17:58:57 +07:00
const store = usePersonalDataStore();
2024-12-25 11:48:36 +07:00
const { messageError, showLoader, hideLoader, success, dialogRemove } =
useCounterMixin();
2025-02-26 15:30:25 +07:00
/** Table*/
2024-05-29 17:58:57 +07:00
const columns = [
{
name: "bloodGroup",
align: "left",
label: "กลุ่มเลือด",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "createdAt",
align: "left",
label: "วันที่สร้าง",
sortable: true,
field: "createdAt",
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",
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" }),
},
] as const satisfies QTableProps["columns"];
const visibleColumns = ref<string[]>([
"bloodGroup",
"createdAt",
"lastUpdatedAt",
"lastUpdateFullName",
]);
2025-02-26 15:30:25 +07:00
const pagination = ref({
sortBy: "bloodGroup",
});
2024-05-29 17:58:57 +07:00
const filterKeyword = ref<string>(""); //คำค้นหา
const dialog = ref<boolean>(false); // เพิ่มข้อมูล,แก้ไขข้อมูล
const bloodGroup = ref<string>(""); // กลุ่มเลือด
const editId = ref<string>(""); // id กลุ่มเลือด
const dialogStatus = ref<string>(""); // สถานะ เพิ่มข้อมูล,แก้ไขข้อมูล
const personalName = ref<string>("กลุ่มเลือด"); //label input
/**
* fetch อมลรายการ กลมเลอด
* นทกขอมลลงใน store
*/
2024-05-29 17:58:57 +07:00
async function fetchData() {
showLoader();
await http
.get(config.API.orgBloodGroup)
.then(async (res) => {
await store.save(res.data.result);
2024-05-29 17:58:57 +07:00
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* เพมขอมลรายการกลมเลอด
* แล fetch อมลรายการ กลมเลอด ใหม
*/
2024-05-29 17:58:57 +07:00
async function addData() {
await http
.post(config.API.orgBloodGroup, {
name: bloodGroup.value,
})
.then(async () => {
await fetchData();
2024-05-29 17:58:57 +07:00
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
/**
* แกไขขอมลรายการกลมเลอด
* แล fetch อมลรายการ กลมเลอด ใหม
* @param id รายการกลมเลอด
*/
2024-05-29 17:58:57 +07:00
async function editData(id: string) {
showLoader();
2024-05-29 17:58:57 +07:00
await http
.put(config.API.orgBloodGroupId(id), {
name: bloodGroup.value,
})
.then(async () => {
await fetchData();
2024-05-29 17:58:57 +07:00
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
2024-12-25 11:48:36 +07:00
/**
* ลบขอมลรายการกลมเลอด
* แล fetch อมลรายการ อมลรายการกลมเลอด ใหม
* @param id อมลรายการกลมเลอด
*/
async function onDeleteData(id: string) {
dialogRemove($q, async () => {
showLoader();
await http
.delete(config.API.orgBloodGroupId(id))
.then(async () => {
await fetchData();
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
}
/**
* hook ทำงานเม Components กเรยกใชงาน
* แลวเรยก function fetch อมลรายการกลมเลอด
*/
2024-05-29 17:58:57 +07:00
onMounted(async () => {
await fetchData();
2024-05-29 17:58:57 +07:00
});
</script>
<template>
<q-toolbar style="padding: 0">
<q-btn
flat
round
color="primary"
icon="add"
@click.stop="
() => {
dialogStatus = 'create';
dialog = true;
}
"
>
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-input
dense
outlined
v-model="filterKeyword"
placeholder="ค้นหา"
@keydown.enter.pervent="store.onSearchData(filterKeyword, columns)"
>
<template v-slot:append>
<q-icon name="search" />
</template>
</q-input>
2024-05-29 17:58:57 +07:00
<q-select
v-model="visibleColumns"
multiple
outlined
dense
options-dense
:display-value="$q.lang.table.columns"
emit-value
map-options
:options="columns"
option-value="name"
2024-11-05 16:45:53 +07:00
style="min-width: 140px"
2024-05-29 17:58:57 +07:00
/>
</div>
</q-toolbar>
<d-table
ref="table"
:columns="columns"
:rows="store.row"
row-key="name"
flat
bordered
dense
class="custom-header-table"
:visible-columns="visibleColumns"
2025-02-26 15:30:25 +07:00
v-model:pagination="pagination"
2024-05-29 17:58:57 +07:00
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th auto-width />
2024-05-29 17:58:57 +07:00
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
</q-tr>
</template>
<template v-slot:body="props">
2024-08-20 17:21:12 +07:00
<q-tr :props="props">
2024-05-29 17:58:57 +07:00
<q-td auto-width>
<q-btn
color="edit"
flat
dense
round
icon="edit"
clickable
@click.stop="
() => {
dialogStatus = 'edit';
dialog = true;
bloodGroup = props.row.name;
editId = props.row.id;
}
"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
2024-12-25 11:48:36 +07:00
<q-btn
color="red"
flat
dense
round
icon="delete"
@click.stop.prevent="onDeleteData(props.row.id)"
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
2024-05-29 17:58:57 +07:00
</q-td>
<q-td v-for="col in props.cols" :key="col.id">
<div>
{{ col.value }}
</div>
</q-td>
2024-05-29 17:58:57 +07:00
</q-tr>
</template>
</d-table>
<DialogForm
v-model:dialog="dialog"
v-model:data="bloodGroup"
v-model:personal-name="personalName"
v-model:dialog-status="dialogStatus"
v-model:edit-id="editId"
:add-data="addData"
2024-05-29 17:58:57 +07:00
:fetch-data="fetchData"
:edit-data="editData"
/>
</template>