API เรียกคืนเครื่องราชฯ

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-05-07 17:18:06 +07:00
parent 0ff6ad85f0
commit 27da100141
7 changed files with 421 additions and 163 deletions

View file

@ -1,20 +1,29 @@
<script setup lang="ts">
import { ref, watch, onMounted } from "vue";
import { ref, watch } from "vue";
import { storeToRefs } from "pinia";
import { QForm, useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import { useBrrowDataStore } from "@/modules/07_insignia/storeBrrow";
import { useInsigniaReclaimStore } from "@/modules/07_insignia/storeReclaim";
import http from "@/plugins/http";
import config from "@/app.config";
/** impotrType */
import type { PropType } from "vue";
import type { QTableColumn } from "quasar";
import type {
DataReclaim,
DataNoteList,
DataRound,
} from "@/modules/07_insignia/interface/response/Reclaim";
/** impotrComponents */
import DialogHeader from "@/components/DialogHeader.vue";
const $q = useQuasar();
const brrowDataStore = useBrrowDataStore();
const { roundData } = storeToRefs(useInsigniaReclaimStore());
const mixin = useCounterMixin();
const {
date2Thai,
@ -24,19 +33,27 @@ const {
showLoader,
hideLoader,
onSearchDataTable,
convertDateToAPI,
} = mixin;
/** props*/
const modal = defineModel<boolean>("modal", { required: true });
const isEdit = defineModel<boolean>("isEdit", { required: true });
const insigniaReclaimId = defineModel<string>("insigniaReclaimId", {
required: true,
default: "",
});
const props = defineProps({});
const props = defineProps({
fetchData: { type: Function, required: true },
insigniaReclaimData: {
type: Object as PropType<DataReclaim>,
},
});
const rows = ref<any[]>([]);
const rowsMain = ref<any[]>([]);
const rows = ref<DataNoteList[]>([]);
const rowsMain = ref<DataNoteList[]>([]);
const keyword = ref<string>("");
const selected = ref<any[]>([]);
const selected = ref<DataNoteList[]>([]);
const columns = ref<QTableColumn[]>([
{
name: "noNumber",
@ -113,64 +130,6 @@ const columns = ref<QTableColumn[]>([
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
// {
// name: "date",
// align: "left",
// label: "",
// field: "date",
// sortable: true,
// format(val, row) {
// return date2Thai(val);
// },
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
// {
// name: "volumeNo",
// align: "left",
// label: "",
// field: "volumeNo",
// sortable: true,
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
// {
// name: "section",
// align: "left",
// label: "",
// field: "section",
// sortable: true,
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
// {
// name: "page",
// align: "left",
// label: "",
// field: "page",
// sortable: true,
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
// {
// name: "no",
// align: "left",
// label: "",
// field: "no",
// sortable: true,
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
// {
// name: "number",
// align: "left",
// label: "",
// field: "number",
// sortable: true,
// headerStyle: "font-size: 14px",
// style: "font-size: 14px",
// },
]);
const visibleColumns = ref<string[]>([
"noNumber",
@ -180,34 +139,28 @@ const visibleColumns = ref<string[]>([
"position",
"requestInsignia",
"dateReceive",
// "date",
// "volumeNo",
// "section",
// "page",
// "no",
// "number",
]);
const roundNo = ref<string | undefined>(""); //
const insigniaNoteId = ref<string | undefined>(""); //
const insigniaNoteProfileId = ref<string>("");
const cardid = ref<string>(""); //
const fullName = ref<string>(""); //-
const insigniaType = ref<string>(""); //
const receivedate = ref<Date | null>(); //
const receivedate = ref<Date | null>(null); //
const reason = ref<string>(""); //
const filterSelectRound = ref<any>();
/** function เคลียร์ข้อมูลในฟอร์ม*/
function clearData() {}
const filterSelectRound = ref<DataRound[]>([]);
/** function เรียกข้อมูลรายชื่อที่ได้รับเครื่องราช*/
async function fecthListPerson() {
if (roundNo.value !== "" && roundNo.value !== null) {
rows.value = [];
rowsMain.value = [];
if (insigniaNoteId.value !== "" && insigniaNoteId.value !== null) {
let data = {
// insigniaTypeId: props.typeId,
insigniaNoteId: roundNo.value,
insigniaNoteId: insigniaNoteId.value,
insigniaId: "",
};
showLoader();
await http
.post(config.API.noteSearchList(), data)
.then((res) => {
@ -216,20 +169,54 @@ async function fecthListPerson() {
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
}
}
/**
* function นทกการเพมขอม
*/
/** function บันทึกการเพิ่มข้อมูล*/
async function onSubmit() {
dialogConfirm($q, async () => {});
dialogConfirm($q, async () => {
showLoader();
const pathAPI = !isEdit.value
? config.API.insigniaReclaim
: config.API.insigniaReclaim + `/${insigniaReclaimId.value}`;
const method = !isEdit.value ? "post" : "put";
await http[method](pathAPI, {
insigniaNoteProfileId: !isEdit.value
? insigniaNoteProfileId.value
: undefined,
reclaimDate: receivedate.value,
reclaimNote: reason.value,
})
.then(async () => {
await props.fetchData?.();
closeDialog();
success($q, "บันทึกข้อมูลสำเร็จ");
})
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
});
}
/** function closePopup*/
function closeDialog() {
modal.value = false;
selected.value = [];
fullName.value = "";
cardid.value = "";
insigniaType.value = "";
receivedate.value = null;
reason.value = "";
keyword.value = "";
}
function serchDataTable() {
@ -240,8 +227,39 @@ function serchDataTable() {
);
}
watch(selected, () => {
if (modal.value) {
const data = selected.value[0];
insigniaNoteProfileId.value = data ? data.id : "";
fullName.value = data ? data.fullName : "";
cardid.value = data ? data.citizenId : "";
insigniaType.value = data
? `${data.requestInsignia} (${data.requestInsigniaShortName})`
: "";
}
});
/** function callback เช็ค props ถ้าเปิด dialog ให้ดึงรายการข้อมูล*/
watch(modal, () => {});
watch(modal, (val) => {
if (val) {
filterSelectRound.value = roundData.value?.filter((e) => e.id !== "all");
insigniaNoteId.value = filterSelectRound.value[0].id;
if (isEdit.value) {
const data = props.insigniaReclaimData;
console.log(props.insigniaReclaimData);
fullName.value = data ? data?.fullName : "";
cardid.value = data ? data.citizenId : "";
insigniaType.value = data
? `${data.requestInsignia} (${data.requestInsigniaShortName})`
: "";
receivedate.value = data ? data.reclaimDate : null;
reason.value = data ? data.reclaimReason : "";
} else {
fecthListPerson();
}
}
});
</script>
<template>
@ -346,10 +364,10 @@ watch(modal, () => {});
<q-separator vertical />
<div class="q-pa-md col">
<div class="row q-col-gutter-sm">
<div class="col-12">
<div class="col-12" v-if="!isEdit">
<q-select
:class="!isEdit ? 'inputgreen' : ''"
v-model="roundNo"
v-model="insigniaNoteId"
:readonly="isEdit"
dense
outlined
@ -456,6 +474,7 @@ watch(modal, () => {});
</div>
<div class="col-12">
<q-input
class="inputgreen"
v-model="reason"
dense
outlined
@ -473,7 +492,12 @@ watch(modal, () => {});
<q-separator />
<q-card-actions align="right">
<q-btn label="บันทึก" type="submit" color="public">
<q-btn
label="บันทึก"
type="submit"
color="public"
:disable="selected.length === 0 && !isEdit"
>
<q-tooltip>นท</q-tooltip>
</q-btn>
</q-card-actions>