ทะเบียนประวัติ: ประวัติส่วนตัว (GET history)

This commit is contained in:
puriphatt 2024-03-25 07:56:07 +07:00
parent dccc41ac47
commit 6868e209d7

View file

@ -12,7 +12,6 @@ import HistoryTable from "@/components/TableHistory.vue";
import DialogHeader from "@/components/DialogHeader.vue";
import type { RequestObject } from "@/modules/04_registryNew/interface/request/Profile";
import type { ResponseObject } from "@/modules/04_registryNew/interface/response/Profile";
import type { RequestItemsHistoryObject } from "@/modules/04_registryNew/interface/request/Information";
const $q = useQuasar();
const route = useRoute();
@ -24,8 +23,7 @@ const {
hideLoader,
date2Thai,
messageError,
convertDate,
dateToISO,
dialogConfirm,
} = mixin;
const { calculateAge, getGender, getRelationship, getReligion, getBloodGroup } =
store;
@ -34,9 +32,8 @@ const profileId = ref<string>(
);
const modal = ref<boolean>(false);
const myForm = ref<any>();
const informaData = ref<ResponseObject>();
const rowsHistory = ref<RequestItemsHistoryObject[]>([]);
const rowsHistory = ref<ResponseObject[]>([]);
const tittleHistory = ref<string>("ประวัติแก้ไขข้อมูลส่วนตัว");
const filterHistory = ref<string>("");
const modalHistory = ref<boolean>(false);
@ -44,7 +41,7 @@ const modalHistory = ref<boolean>(false);
const id = ref<string>("");
const age = ref<string>("");
//
const nationality = ref<string>("")
const nationality = ref<string>("");
const formData = reactive<RequestObject>({
citizenId: "",
prefix: "",
@ -139,6 +136,7 @@ const columnsHistory = ref<QTableColumn[]>([
field: "birthDate",
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" }),
},
@ -147,7 +145,7 @@ const columnsHistory = ref<QTableColumn[]>([
align: "left",
label: "เพศ",
sortable: true,
field: "gender",
field: (v) => (v.gender ? v.gender.name : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
@ -158,7 +156,7 @@ const columnsHistory = ref<QTableColumn[]>([
align: "left",
label: "สถานภาพ",
sortable: true,
field: "relationship",
field: (v) => (v.relationship ? v.relationship.name : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
@ -169,7 +167,7 @@ const columnsHistory = ref<QTableColumn[]>([
align: "left",
label: "หมู่เลือด",
sortable: true,
field: "bloodGroup",
field: (v) => (v.bloodGroup ? v.bloodGroup.name : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
@ -187,11 +185,11 @@ const columnsHistory = ref<QTableColumn[]>([
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "race",
name: "ethnicity",
align: "left",
label: "เชื้อชาติ",
sortable: true,
field: "race",
field: "ethnicity",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
@ -202,7 +200,7 @@ const columnsHistory = ref<QTableColumn[]>([
align: "left",
label: "ศาสนา",
sortable: true,
field: "religion",
field: (v) => (v.religion ? v.religion.name : "-"),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
@ -219,28 +217,6 @@ const columnsHistory = ref<QTableColumn[]>([
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "employeeType",
align: "left",
label: "ประเภทการจ้าง",
sortable: true,
field: "employeeType",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "employeeClass",
align: "left",
label: "ประเภทลูกจ้าง",
sortable: true,
field: "employeeClass",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "createdFullName",
align: "left",
@ -260,6 +236,7 @@ const columnsHistory = ref<QTableColumn[]>([
field: "createdAt",
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" }),
},
@ -275,11 +252,9 @@ const visibleColumnsHistory = ref<String[]>([
"relationship",
"bloodGroup",
"nationality",
"race",
"ethnicity",
"religion",
"phone",
"employeeType",
"employeeClass",
"createdFullName",
"createdAt",
]);
@ -291,6 +266,7 @@ async function getData() {
.then((res) => {
informaData.value = res.data.result;
if (informaData.value) {
id.value = informaData.value.id;
age.value = calculateAge(informaData.value.birthDate);
}
})
@ -302,6 +278,24 @@ async function getData() {
});
}
async function editData() {
showLoader();
await http
.put(config.API.profileNewProfileById(id.value), {
...formData,
})
.then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ");
getData(), (modal.value = false);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}
function onClickOpenDialog() {
if (!informaData.value) return;
modal.value = true;
@ -322,15 +316,24 @@ function onClickOpenDialog() {
formData.phone = informaData.value.phone;
}
async function editData() {
showLoader();
function onSubmit() {
dialogConfirm(
$q,
async () => {
editData();
modal.value = false;
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
async function clickHistory() {
modalHistory.value = true;
await http
.put(config.API.profileNewProfileById(id.value), {
...formData,
})
.get(config.API.profileNewProfileHisById(id.value))
.then((res) => {
success($q, "บันทึกข้อมูลสำเร็จ");
getData(), (modal.value = false);
rowsHistory.value = res.data.result;
})
.catch((e) => {
messageError($q, e);
@ -349,11 +352,6 @@ watch(
}
);
function onSubmit() {
editData();
modal.value = false;
}
onMounted(async () => {
await getData();
store.genderOp.length === 0 ? await getGender() : "";
@ -374,7 +372,7 @@ onMounted(async () => {
>
<q-tooltip>แกไขขอม</q-tooltip>
</q-btn>
<q-btn flat round icon="mdi-history" color="info">
<q-btn flat round icon="mdi-history" color="info" @click="clickHistory">
<q-tooltip>ประวอมลสวนต</q-tooltip>
</q-btn>
</div>
@ -384,7 +382,7 @@ onMounted(async () => {
<div v-if="informaData" :class="$q.screen.gt.xs ? 'row' : 'column'">
<!-- column 1 -->
<div class="col-md-7 col-12 row">
<div class="col-md-4 col-5 text-grey-6 text-weight-medium">
<div class="col-5 text-grey-6 text-weight-medium">
<div
v-for="label in Object.keys(dataLabel).slice(0, 6)"
class="q-py-xs"
@ -393,7 +391,7 @@ onMounted(async () => {
</div>
</div>
<!-- data -->
<div class="col-md-8 col-7">
<div class="col-7">
<div class="q-py-xs">
{{ informaData.citizenId }}
</div>
@ -419,7 +417,7 @@ onMounted(async () => {
<!-- column 2 -->
<div class="col-md-5 col-12 row">
<div class="col-md-4 col-5 col text-grey-6 text-weight-medium">
<div class="col-5 col text-grey-6 text-weight-medium">
<div
v-for="label in Object.keys(dataLabel).slice(6, 11)"
class="q-py-xs"
@ -428,7 +426,7 @@ onMounted(async () => {
</div>
</div>
<!-- data -->
<div class="col-md-8 col-7">
<div class="col-7">
<div class="q-py-xs">
{{ informaData.nationality ? informaData.nationality : "-" }}
</div>
@ -489,6 +487,7 @@ onMounted(async () => {
map-options
hide-bottom-space
input-debounce="0"
new-value-mode="add-unique"
v-model="formData.prefix"
class="inputgreen"
:options="store.prefixOp"
@ -716,14 +715,8 @@ onMounted(async () => {
<template #columns="props">
<q-tr :props="props">
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div
v-if="col.name == 'birthDate' || col.name == 'createdAt'"
class="table_ellipsis"
>
{{ date2Thai(col.value) }}
</div>
<div v-else class="table_ellipsis">
{{ col.value }}
<div class="table_ellipsis">
{{ col.value ? col.value : "-" }}
</div>
</q-td>
</q-tr>