ทะเบียนประวัติ: ประกาศเกียรติคุณ (refactor)
This commit is contained in:
parent
79f08f7569
commit
0d7f6cdbde
2 changed files with 68 additions and 121 deletions
|
|
@ -10,7 +10,6 @@ import { useCounterMixin } from "@/stores/mixin";
|
||||||
import HistoryTable from "@/components/TableHistory.vue";
|
import HistoryTable from "@/components/TableHistory.vue";
|
||||||
import DialogHeader from "@/components/DialogHeader.vue";
|
import DialogHeader from "@/components/DialogHeader.vue";
|
||||||
import type { RequestItemsObject } from "@/modules/04_registryNew/interface/request/DeclarationHonor";
|
import type { RequestItemsObject } from "@/modules/04_registryNew/interface/request/DeclarationHonor";
|
||||||
import type { FormData } from "@/modules/04_registryNew/interface/request/DeclarationHonor";
|
|
||||||
import type { ResponseObject } from "@/modules/04_registryNew/interface/response/DeclarationHonor";
|
import type { ResponseObject } from "@/modules/04_registryNew/interface/response/DeclarationHonor";
|
||||||
|
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
|
@ -29,20 +28,18 @@ const profileId = ref<string>(
|
||||||
route.params.id ? route.params.id.toString() : ""
|
route.params.id ? route.params.id.toString() : ""
|
||||||
);
|
);
|
||||||
|
|
||||||
const declHonorData = reactive<FormData>({
|
const id = ref<string>("");
|
||||||
id: "",
|
const issueDateYear = ref<number>(0);
|
||||||
isActive: true,
|
const declHonorForm = reactive<RequestItemsObject>({
|
||||||
isDate: "false",
|
isDate: "false",
|
||||||
issuer: "",
|
issuer: "",
|
||||||
detail: "",
|
detail: "",
|
||||||
issueDate: null,
|
issueDate: null,
|
||||||
issueDateYear: 0,
|
|
||||||
refCommandNo: "",
|
refCommandNo: "",
|
||||||
refCommandDate: null,
|
refCommandDate: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const isEdit = ref<boolean>(false);
|
const isEdit = ref<boolean>(false);
|
||||||
const editRow = ref<boolean>(false);
|
|
||||||
const myForm = ref<QForm>();
|
const myForm = ref<QForm>();
|
||||||
const modal = ref<boolean>(false);
|
const modal = ref<boolean>(false);
|
||||||
const modelView = ref<string>("table");
|
const modelView = ref<string>("table");
|
||||||
|
|
@ -234,21 +231,17 @@ async function addEditData(editStatus: boolean = false) {
|
||||||
if (!profileId.value) return;
|
if (!profileId.value) return;
|
||||||
|
|
||||||
const url = editStatus
|
const url = editStatus
|
||||||
? config.API.profileNewHonorById(declHonorData.id)
|
? config.API.profileNewHonorById(id.value)
|
||||||
: config.API.profileNewHonor;
|
: config.API.profileNewHonor;
|
||||||
const method = editStatus ? "patch" : "post";
|
const method = editStatus ? "patch" : "post";
|
||||||
const reqBody: RequestItemsObject = {
|
const reqBody: RequestItemsObject = {
|
||||||
|
...declHonorForm,
|
||||||
profileId: editStatus ? undefined : profileId.value,
|
profileId: editStatus ? undefined : profileId.value,
|
||||||
isActive: declHonorData.isActive,
|
isDate: declHonorForm.isDate === "true" ? true : false,
|
||||||
detail: declHonorData.detail,
|
|
||||||
issueDate:
|
issueDate:
|
||||||
declHonorData.isDate === "true"
|
declHonorForm.isDate === true
|
||||||
? declHonorData.issueDate
|
? declHonorForm.issueDate
|
||||||
: new Date(`${declHonorData.issueDateYear}-01-01`),
|
: new Date(`${issueDateYear.value}-01-01`),
|
||||||
issuer: declHonorData.issuer,
|
|
||||||
refCommandDate: declHonorData.refCommandDate,
|
|
||||||
refCommandNo: declHonorData.refCommandNo,
|
|
||||||
isDate: declHonorData.isDate === "true" ? true : false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -262,57 +255,41 @@ async function addEditData(editStatus: boolean = false) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clickDelete(dataId: string) {
|
// async function clickDelete(dataId: string) {
|
||||||
try {
|
// try {
|
||||||
await http.delete(config.API.profileNewHonorById(dataId));
|
// await http.delete(config.API.profileNewHonorById(dataId));
|
||||||
success($q, "ลบข้อมูลสำเร็จ");
|
// success($q, "ลบข้อมูลสำเร็จ");
|
||||||
await fetchData();
|
// await fetchData();
|
||||||
modal.value = false;
|
// modal.value = false;
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
messageError($q, error);
|
// messageError($q, error);
|
||||||
} finally {
|
// } finally {
|
||||||
hideLoader();
|
// hideLoader();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) {
|
function onClickOpenDialog(editStatus: boolean = false, row?: ResponseObject) {
|
||||||
modal.value = true;
|
modal.value = true;
|
||||||
editRow.value = false;
|
|
||||||
isEdit.value = editStatus;
|
isEdit.value = editStatus;
|
||||||
|
|
||||||
if (editStatus && row) {
|
if (editStatus && row) {
|
||||||
Object.assign(declHonorData, row);
|
id.value = row.id;
|
||||||
declHonorData.isDate = row.isDate.toString();
|
|
||||||
declHonorData.issueDate = row.issueDate;
|
issueDateYear.value = new Date(row.issueDate).getFullYear();
|
||||||
declHonorData.issueDateYear = new Date(row.issueDate).getFullYear();
|
declHonorForm.issuer = row.issuer;
|
||||||
declHonorData.refCommandDate = row.refCommandDate;
|
declHonorForm.detail = row.detail;
|
||||||
|
declHonorForm.issueDate = row.issueDate;
|
||||||
|
declHonorForm.refCommandNo = row.refCommandNo;
|
||||||
|
declHonorForm.refCommandDate = row.refCommandDate;
|
||||||
|
declHonorForm.isDate = row.isDate ? "true" : "false";
|
||||||
} else {
|
} else {
|
||||||
declHonorData.id = "";
|
clearData();
|
||||||
declHonorData.isActive = true;
|
|
||||||
declHonorData.issuer = "";
|
|
||||||
declHonorData.detail = "";
|
|
||||||
declHonorData.issueDate = null;
|
|
||||||
declHonorData.issueDateYear = 0;
|
|
||||||
declHonorData.refCommandNo = "";
|
|
||||||
declHonorData.refCommandDate = null;
|
|
||||||
declHonorData.isDate = "false";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clickClose() {
|
async function clickClose() {
|
||||||
if (editRow.value == true) {
|
clearData();
|
||||||
dialogConfirm(
|
modal.value = false;
|
||||||
$q,
|
|
||||||
async () => {
|
|
||||||
modal.value = false;
|
|
||||||
editRow.value = false;
|
|
||||||
},
|
|
||||||
"ข้อมูลมีการแก้ไข",
|
|
||||||
"ยืนยันที่จะปิดโดยไม่บันทึกใช่หรือไม่?"
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
modal.value = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clickHistory(row: ResponseObject) {
|
async function clickHistory(row: ResponseObject) {
|
||||||
|
|
@ -334,30 +311,37 @@ function onSubmit() {
|
||||||
dialogConfirm(
|
dialogConfirm(
|
||||||
$q,
|
$q,
|
||||||
async () => {
|
async () => {
|
||||||
myForm.value?.validate().then(async (result: boolean) => {
|
addEditData(isEdit.value);
|
||||||
if (result) {
|
modal.value = false;
|
||||||
addEditData(isEdit.value);
|
|
||||||
modal.value = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
"ยืนยันการบันทึกข้อมูล",
|
"ยืนยันการบันทึกข้อมูล",
|
||||||
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
|
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearData() {
|
||||||
|
id.value = "";
|
||||||
|
issueDateYear.value = 0;
|
||||||
|
declHonorForm.issuer = "";
|
||||||
|
declHonorForm.detail = "";
|
||||||
|
declHonorForm.issueDate = null;
|
||||||
|
declHonorForm.refCommandNo = "";
|
||||||
|
declHonorForm.refCommandDate = null;
|
||||||
|
declHonorForm.isDate = "false";
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await fetchData();
|
await fetchData();
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => declHonorData.isDate,
|
() => declHonorForm.isDate,
|
||||||
() => {
|
() => {
|
||||||
if (declHonorData.isDate === "true") {
|
if (declHonorForm.isDate === "true") {
|
||||||
declHonorData.issueDateYear = 0;
|
issueDateYear.value = 0;
|
||||||
}
|
}
|
||||||
if (declHonorData.isDate === "false") {
|
if (declHonorForm.isDate === "false") {
|
||||||
declHonorData.issueDate = null;
|
declHonorForm.issueDate = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -557,14 +541,14 @@ watch(
|
||||||
|
|
||||||
<q-dialog v-model="modal" persistent>
|
<q-dialog v-model="modal" persistent>
|
||||||
<q-card style="width: 600px">
|
<q-card style="width: 600px">
|
||||||
<q-form greedy ref="myForm" @submit="onSubmit">
|
<q-form greedy @submit.prevent @validation-success="onSubmit">
|
||||||
<DialogHeader tittle="ประกาศเกียรติคุณ" :close="clickClose" />
|
<DialogHeader tittle="ประกาศเกียรติคุณ" :close="clickClose" />
|
||||||
<q-separator />
|
<q-separator />
|
||||||
<q-card-section class="q-p-sm">
|
<q-card-section class="q-p-sm">
|
||||||
<div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
|
<div class="row col-12 q-col-gutter-x-xs q-col-gutter-y-xs">
|
||||||
<div class="row col-12 q-gutter-md q-py-sm text-grey-7">
|
<div class="row col-12 q-gutter-md q-py-sm text-grey-7">
|
||||||
<q-radio
|
<q-radio
|
||||||
v-model="declHonorData.isDate"
|
v-model="declHonorForm.isDate as string"
|
||||||
checked-icon="task_alt"
|
checked-icon="task_alt"
|
||||||
unchecked-icon="panorama_fish_eye"
|
unchecked-icon="panorama_fish_eye"
|
||||||
val="false"
|
val="false"
|
||||||
|
|
@ -572,7 +556,7 @@ watch(
|
||||||
dense
|
dense
|
||||||
/>
|
/>
|
||||||
<q-radio
|
<q-radio
|
||||||
v-model="declHonorData.isDate"
|
v-model="declHonorForm.isDate as string"
|
||||||
checked-icon="task_alt"
|
checked-icon="task_alt"
|
||||||
unchecked-icon="panorama_fish_eye"
|
unchecked-icon="panorama_fish_eye"
|
||||||
val="true"
|
val="true"
|
||||||
|
|
@ -584,12 +568,12 @@ watch(
|
||||||
<datepicker
|
<datepicker
|
||||||
autoApply
|
autoApply
|
||||||
year-picker
|
year-picker
|
||||||
v-model="declHonorData.issueDateYear"
|
v-model="issueDateYear"
|
||||||
week-start="0"
|
week-start="0"
|
||||||
menu-class-name="modalfix"
|
menu-class-name="modalfix"
|
||||||
:locale="'th'"
|
:locale="'th'"
|
||||||
:enableTimePicker="false"
|
:enableTimePicker="false"
|
||||||
v-if="declHonorData.isDate === 'false'"
|
v-if="declHonorForm.isDate === 'false'"
|
||||||
>
|
>
|
||||||
<template #year="{ year }">{{ year + 543 }}</template>
|
<template #year="{ year }">{{ year + 543 }}</template>
|
||||||
<template #year-overlay-value="{ value }">{{
|
<template #year-overlay-value="{ value }">{{
|
||||||
|
|
@ -599,21 +583,15 @@ watch(
|
||||||
<q-input
|
<q-input
|
||||||
dense
|
dense
|
||||||
outlined
|
outlined
|
||||||
lazy-rules
|
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
class="inputgreen"
|
class="inputgreen"
|
||||||
:model-value="
|
:model-value="issueDateYear ? issueDateYear + 543 : null"
|
||||||
declHonorData.issueDateYear
|
|
||||||
? declHonorData.issueDateYear + 543
|
|
||||||
: null
|
|
||||||
"
|
|
||||||
:rules="[
|
:rules="[
|
||||||
(val:string) =>
|
(val:string) =>
|
||||||
!!val ||
|
!!val ||
|
||||||
`${'กรุณาเลือกปีที่ได้รับ'}`,
|
`${'กรุณาเลือกปีที่ได้รับ'}`,
|
||||||
]"
|
]"
|
||||||
:label="`${'ปีที่ได้รับ'}`"
|
:label="`${'ปีที่ได้รับ'}`"
|
||||||
@update:modelValue="() => (editRow = true)"
|
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-icon
|
<q-icon
|
||||||
|
|
@ -630,7 +608,7 @@ watch(
|
||||||
borderless
|
borderless
|
||||||
week-start="0"
|
week-start="0"
|
||||||
menu-class-name="modalfix"
|
menu-class-name="modalfix"
|
||||||
v-model="declHonorData.issueDate"
|
v-model="declHonorForm.issueDate"
|
||||||
:locale="'th'"
|
:locale="'th'"
|
||||||
:enableTimePicker="false"
|
:enableTimePicker="false"
|
||||||
v-else
|
v-else
|
||||||
|
|
@ -649,10 +627,9 @@ watch(
|
||||||
for="inputDatereceive"
|
for="inputDatereceive"
|
||||||
ref="dateReceivedRef"
|
ref="dateReceivedRef"
|
||||||
class="inputgreen"
|
class="inputgreen"
|
||||||
:model-value="date2Thai(declHonorData.issueDate as Date)"
|
:model-value="date2Thai(declHonorForm.issueDate as Date)"
|
||||||
:label="`${'วันที่ได้รับ'}`"
|
:label="`${'วันที่ได้รับ'}`"
|
||||||
:rules="[(val) => !!val || `${'กรุณาเลือกวันที่ได้รับ'}`]"
|
:rules="[(val) => !!val || `${'กรุณาเลือกวันที่ได้รับ'}`]"
|
||||||
@update:modelValue="() => (editRow = true)"
|
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-icon
|
<q-icon
|
||||||
|
|
@ -672,9 +649,8 @@ watch(
|
||||||
lazy-rules
|
lazy-rules
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
class="inputgreen"
|
class="inputgreen"
|
||||||
v-model="declHonorData.issuer"
|
v-model="declHonorForm.issuer"
|
||||||
:label="`${'ผู้มีอำนาจลงนาม'}`"
|
:label="`${'ผู้มีอำนาจลงนาม'}`"
|
||||||
@update:modelValue="() => (editRow = true)"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
|
|
@ -684,10 +660,9 @@ watch(
|
||||||
lazy-rules
|
lazy-rules
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
class="inputgreen"
|
class="inputgreen"
|
||||||
v-model="declHonorData.detail"
|
v-model="declHonorForm.detail"
|
||||||
:label="`${'รายละเอียด'}`"
|
:label="`${'รายละเอียด'}`"
|
||||||
:rules="[(val) => !!val || `${'กรุณากรอกรายละเอียด'}`]"
|
:rules="[(val) => !!val || `${'กรุณากรอกรายละเอียด'}`]"
|
||||||
@update:modelValue="() => (editRow = true)"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-6 col-sm-6 col-md-6">
|
<div class="col-xs-6 col-sm-6 col-md-6">
|
||||||
|
|
@ -697,9 +672,8 @@ watch(
|
||||||
lazy-rules
|
lazy-rules
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
class="inputgreen"
|
class="inputgreen"
|
||||||
v-model="declHonorData.refCommandNo"
|
v-model="declHonorForm.refCommandNo"
|
||||||
:label="`${'เลขที่คำสั่ง'}`"
|
:label="`${'เลขที่คำสั่ง'}`"
|
||||||
@update:modelValue="() => (editRow = true)"
|
|
||||||
>
|
>
|
||||||
<template v-slot:append>
|
<template v-slot:append>
|
||||||
<q-icon name="mdi-file" class="cursor-pointer" />
|
<q-icon name="mdi-file" class="cursor-pointer" />
|
||||||
|
|
@ -712,7 +686,7 @@ watch(
|
||||||
borderless
|
borderless
|
||||||
week-start="0"
|
week-start="0"
|
||||||
menu-class-name="modalfix"
|
menu-class-name="modalfix"
|
||||||
v-model="declHonorData.refCommandDate"
|
v-model="declHonorForm.refCommandDate"
|
||||||
:locale="'th'"
|
:locale="'th'"
|
||||||
:enableTimePicker="false"
|
:enableTimePicker="false"
|
||||||
>
|
>
|
||||||
|
|
@ -730,13 +704,12 @@ watch(
|
||||||
hide-bottom-space
|
hide-bottom-space
|
||||||
class="inputgreen"
|
class="inputgreen"
|
||||||
:model-value="
|
:model-value="
|
||||||
declHonorData.refCommandDate == null
|
declHonorForm.refCommandDate == null
|
||||||
? null
|
? null
|
||||||
: date2Thai(declHonorData.refCommandDate)
|
: date2Thai(declHonorForm.refCommandDate)
|
||||||
"
|
"
|
||||||
:label="`${'เอกสารอ้างอิง (ลงวันที่)'}`"
|
:label="`${'เอกสารอ้างอิง (ลงวันที่)'}`"
|
||||||
@clear="declHonorData.refCommandDate = null"
|
@clear="declHonorForm.refCommandDate = null"
|
||||||
@update:modelValue="() => (editRow = true)"
|
|
||||||
>
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<q-icon
|
<q-icon
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,11 @@
|
||||||
interface RequestItemsObject {
|
interface RequestItemsObject {
|
||||||
profileId?: string;
|
profileId?: string;
|
||||||
isActive: boolean;
|
|
||||||
detail: string;
|
detail: string;
|
||||||
issueDate: Date | null;
|
issueDate: Date | null;
|
||||||
issuer: string;
|
issuer: string;
|
||||||
refCommandDate: Date | null;
|
refCommandDate: Date | null;
|
||||||
refCommandNo: string;
|
refCommandNo: string;
|
||||||
isDate: boolean;
|
isDate: boolean | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FormData {
|
export type { RequestItemsObject };
|
||||||
id: string;
|
|
||||||
isActive: boolean;
|
|
||||||
isDate: string | null;
|
|
||||||
issuer: string;
|
|
||||||
detail: string;
|
|
||||||
issueDate: Date | null;
|
|
||||||
issueDateYear: number;
|
|
||||||
refCommandNo: string;
|
|
||||||
refCommandDate: Date | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//columns
|
|
||||||
interface Columns {
|
|
||||||
[index: number]: {
|
|
||||||
name: String;
|
|
||||||
align: String;
|
|
||||||
label: String;
|
|
||||||
sortable: Boolean;
|
|
||||||
field: String;
|
|
||||||
headerStyle: String;
|
|
||||||
style: String;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export type { RequestItemsObject, FormData, Columns };
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue