ทะเบียนประวัติ: ความสามารถพิเศษ API + interface

This commit is contained in:
oat_dev 2024-03-19 10:33:34 +07:00
parent ee6603eaae
commit 7b97178507
3 changed files with 251 additions and 44 deletions

View file

@ -1,14 +1,26 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive } from "vue"; import { ref, reactive, onMounted } from "vue";
import { QForm, useQuasar } from "quasar"; import { QForm, useQuasar } from "quasar";
import dialogHeader from "@/components/DialogHeader.vue"; import dialogHeader from "@/components/DialogHeader.vue";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import type { RequestItemsObject } from "@/modules/04_registryNew/interface/request/SpecialSkill";
import type { ResponseObject } from "@/modules/04_registryNew/interface/response/SpecialSkill";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import { useRoute } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const $q = useQuasar(); const $q = useQuasar();
const mode = ref<string>("table"); const mode = ref<string>("table");
const { dialogConfirm } = mixin; const {
dialogRemove,
dialogConfirm,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "field", name: "field",
@ -57,41 +69,21 @@ const columns = ref<QTableProps["columns"]>([
]); ]);
const historyDialog = ref<boolean>(false); const historyDialog = ref<boolean>(false);
const rows = [
{
field: "กีต้าร์",
detail: "จับคอร์ดได้",
remark: "เล่นดีมาก",
reference: "อ้างอิง",
},
{
field: "ว่ายน้ำ",
detail: "ดำน้ำนาน 5 นาที",
remark: "ว่ายน้ำเก่งมาก",
reference: "อ้างอิง",
},
{
field: "กีฬา",
detail: "จับคอร์ดได้",
remark: "เล่นดีมาก",
reference: "อ้างอิง",
},
{
field: "การเรียน",
detail: "เรียนเก่งมาก",
remark: "ตั้งใจเรียนมาก",
reference: "อ้างอิง",
},
];
const dialog = ref<boolean>(false); const dialog = ref<boolean>(false);
const backgroundColor = "grey-2"; const dialogStatus = ref<string>("create");
const rows = ref<ResponseObject[]>([]);
const historyRows = ref<ResponseObject[]>([]);
const route = useRoute();
const id = ref<string>(route.params.id.toString());
const editId = ref<string>("");
const formFilter = reactive({ const formFilter = reactive({
page: 1, page: 1,
pageSize: 10, pageSize: 10,
keyword: "", keyword: "",
}); });
const specialSkill = reactive({ const specialSkill = reactive<RequestItemsObject>({
field: "", field: "",
detail: "", detail: "",
remark: "", remark: "",
@ -103,12 +95,30 @@ const pagination = ref({
rowsPerPage: formFilter.pageSize, rowsPerPage: formFilter.pageSize,
}); });
const historyFormFilter = reactive({
page: 1,
pageSize: 10,
keyword: "",
});
const historyPagination = ref({
page: historyFormFilter.page,
rowsPerPage: historyFormFilter.pageSize,
});
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"field", "field",
"detail", "detail",
"remark", "remark",
"reference", "reference",
]); ]);
const historyVisibleColumns = ref<string[]>([
"field",
"detail",
"remark",
"reference",
]);
function closeDialog() { function closeDialog() {
dialog.value = false; dialog.value = false;
} }
@ -125,16 +135,127 @@ async function onSubmit() {
dialogConfirm( dialogConfirm(
$q, $q,
async () => { async () => {
dialogStatus.value === "create" ? addData() : editData(editId.value);
closeDialog(); closeDialog();
}, },
"ยืนยันการบันทึกข้อมูล", "ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
); );
} }
function clearForm() {
specialSkill.detail = "";
specialSkill.field = "";
specialSkill.reference = "";
specialSkill.remark = "";
}
async function fetchData(id: string) {
showLoader();
await http
.get(config.API.profileNewAbilityByProfileId(id))
.then(async (res) => {
rows.value = res.data.result;
console.log(rows.value);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function fetchHistoryData(id: string) {
showLoader();
await http
.get(config.API.profileNewAbilityHisByAbilityId(id))
.then(async (res) => {
historyRows.value = res.data.result;
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function addData() {
await http
.post(config.API.profileNewAbility, {
profileId: id.value,
isActive: true,
remark: specialSkill.remark,
field: specialSkill.field,
reference: specialSkill.reference,
detail: specialSkill.detail,
dateStart: null,
dateEnd: null,
})
.then(() => {
fetchData(id.value);
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function editData(idData: string) {
await http
.patch(config.API.profileNewAbilityByAbilityId(idData), {
profileId: id.value,
isActive: true,
remark: specialSkill.remark,
field: specialSkill.field,
reference: specialSkill.reference,
detail: specialSkill.detail,
dateStart: null,
dateEnd: null,
})
.then(() => {
fetchData(id.value);
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
async function deleteData(idData: string) {
await http
.delete(config.API.profileNewAbilityByAbilityId(idData))
.then(() => {
fetchData(id.value);
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
onMounted(async () => {
await fetchData(id.value);
});
</script> </script>
<template> <template>
<q-toolbar style="padding: 0px" class="text-primary"> <q-toolbar style="padding: 0px" class="text-primary">
<q-btn flat round dense icon="add" @click="() => (dialog = true)"> <q-btn
flat
round
dense
icon="add"
@click="() => ((dialogStatus = 'create'), clearForm(), (dialog = true))"
>
<q-tooltip>เพ</q-tooltip> <q-tooltip>เพ</q-tooltip>
</q-btn> </q-btn>
<q-space /> <q-space />
@ -208,6 +329,7 @@ async function onSubmit() {
:columns="columns" :columns="columns"
:rows="rows" :rows="rows"
:paging="true" :paging="true"
:filter="formFilter.keyword"
v-model:pagination="pagination" v-model:pagination="pagination"
:rows-per-page-options="[20, 50, 100]" :rows-per-page-options="[20, 50, 100]"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
@ -222,10 +344,33 @@ async function onSubmit() {
</template> </template>
<template v-slot:body="props" v-if="mode === 'table'"> <template v-slot:body="props" v-if="mode === 'table'">
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id" @click="dialog = true"> <q-td v-for="col in props.cols" :key="col.id">
<div>{{ col.value ? col.value : "-" }}</div> <div>{{ col.value ? col.value : "-" }}</div>
</q-td> </q-td>
<q-td auto-width> <q-td auto-width>
<q-btn
color="edit"
flat
dense
round
class="q-mr-xs"
size="14px"
icon="edit"
clickable
@click="
() => {
dialogStatus = 'edit';
editId = props.row.id;
specialSkill.detail = props.row.detail;
specialSkill.field = props.row.field;
specialSkill.reference = props.row.reference;
specialSkill.remark = props.row.remark;
dialog = true;
}
"
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
<q-btn <q-btn
color="info" color="info"
flat flat
@ -233,10 +378,28 @@ async function onSubmit() {
round round
size="14px" size="14px"
icon="mdi-history" icon="mdi-history"
@click="historyDialog = true" @click="
fetchHistoryData(props.row.id);
historyDialog = true;
"
> >
<q-tooltip>ประวแกไขความสามารถพเศษ</q-tooltip> <q-tooltip>ประวแกไขความสามารถพเศษ</q-tooltip>
</q-btn> </q-btn>
<q-btn
color="red"
flat
dense
round
size="12px"
icon="mdi-delete"
clickable
@click.stop="
dialogRemove($q, async () => await deleteData(props.row.id))
"
v-close-popup
>
<q-tooltip>ลบขอม</q-tooltip>
</q-btn>
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
@ -251,7 +414,17 @@ async function onSubmit() {
round round
color="primary" color="primary"
icon="edit" icon="edit"
@click="dialog = true" @click="
() => {
dialogStatus = 'edit';
editId = props.row.id;
specialSkill.detail = props.row.detail;
specialSkill.field = props.row.field;
specialSkill.reference = props.row.reference;
specialSkill.remark = props.row.remark;
dialog = true;
}
"
> >
<q-tooltip>แกไขขอม</q-tooltip> <q-tooltip>แกไขขอม</q-tooltip>
</q-btn> </q-btn>
@ -261,7 +434,10 @@ async function onSubmit() {
round round
color="blue" color="blue"
icon="mdi-history" icon="mdi-history"
@click="historyDialog = true" @click="
fetchHistoryData(props.row.id);
historyDialog = true;
"
> >
<q-tooltip>ประวแกไขความสามารถพเศษ</q-tooltip> <q-tooltip>ประวแกไขความสามารถพเศษ</q-tooltip>
</q-btn> </q-btn>
@ -352,7 +528,6 @@ async function onSubmit() {
<q-dialog v-model="historyDialog" class="dialog" persistent> <q-dialog v-model="historyDialog" class="dialog" persistent>
<q-card style="min-width: 70%" class="bg-white"> <q-card style="min-width: 70%" class="bg-white">
console.log("🚀 ~ bg-white:", bg-white)
<q-form @submit.prevent greedy @validation-success="validateForm"> <q-form @submit.prevent greedy @validation-success="validateForm">
<q-card-section class="flex justify-between" style="padding: 0"> <q-card-section class="flex justify-between" style="padding: 0">
<dialog-header <dialog-header
@ -368,7 +543,7 @@ async function onSubmit() {
dense dense
outlined outlined
bg-color="white" bg-color="white"
v-model="formFilter.keyword" v-model="historyFormFilter.keyword"
label="ค้นหา" label="ค้นหา"
class="q-mr-sm" class="q-mr-sm"
> >
@ -378,7 +553,7 @@ async function onSubmit() {
</q-input> </q-input>
<q-select <q-select
v-model="visibleColumns" v-model="historyVisibleColumns"
multiple multiple
outlined outlined
dense dense
@ -396,15 +571,17 @@ async function onSubmit() {
<d-table <d-table
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="rows" :rows="historyRows"
row-key="name" row-key="name"
flat flat
bordered bordered
:paging="true" :paging="true"
dense dense
:filter="historyFormFilter.keyword"
v-model:pagination="historyPagination"
:rows-per-page-options="[20, 50, 100]" :rows-per-page-options="[20, 50, 100]"
class="custom-header-table" class="custom-header-table"
:visible-columns="visibleColumns" :visible-columns="historyVisibleColumns"
> >
<template v-slot:header="props"> <template v-slot:header="props">
<q-tr :props="props"> <q-tr :props="props">
@ -414,13 +591,12 @@ async function onSubmit() {
<q-th auto-width /> <q-th auto-width />
</q-tr> </q-tr>
</template> </template>
<template v-slot:body="props"> <template v-slot:body="props" v-if="mode === 'table'">
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props" class="cursor-pointer">
<q-td v-for="col in props.cols" :key="col.id"> <q-td v-for="col in props.cols" :key="col.id">
<div> <div>{{ col.value ? col.value : "-" }}</div>
{{ col.value }}
</div>
</q-td> </q-td>
<q-td auto-width> </q-td>
</q-tr> </q-tr>
</template> </template>
</d-table> </d-table>

View file

@ -0,0 +1,10 @@
interface RequestItemsObject {
field: string;
detail: string;
remark: string;
reference: string;
}
export type { RequestItemsObject };

View file

@ -0,0 +1,21 @@
//ข้อมูล
interface ResponseObject {
createdAt: Date
createdFullName: string
createdUserId: string
dateStart: Date | null
dateEnd: Date | null
detail: string
field: string
id: string
isActive: boolean
lastUpdateFullName: string
lastUpdateUserId: string
lastUpdatedAt: Date
profileId: string
reference: string
remark: string
}
export type { ResponseObject };