diff --git a/src/api/manage/api.insignia.ts b/src/api/manage/api.insignia.ts index cabf1a9a6..1084b38c9 100644 --- a/src/api/manage/api.insignia.ts +++ b/src/api/manage/api.insignia.ts @@ -32,4 +32,7 @@ export default { // listInsigniaHistoryId: (id: string) => `${insignia}history/${id}`, // listInsigniaPublished: `${insignia}history/published`, // listInsigniaPublishedHistory: `${insignia}history/published-history`, + insigniaTypeNew: `${insigniaType}draft`, + insigniaTypeNewId: (id: string) => `${insigniaType}${id}`, + insigniaNewId: (id: string) => `${insignia}${id}`, }; diff --git a/src/modules/01_metadataNew/components/insignia/InsigniaDetail.vue b/src/modules/01_metadataNew/components/insignia/InsigniaDetail.vue index 075bf3125..db71f6c5e 100644 --- a/src/modules/01_metadataNew/components/insignia/InsigniaDetail.vue +++ b/src/modules/01_metadataNew/components/insignia/InsigniaDetail.vue @@ -2,118 +2,45 @@ import { ref, onMounted } from "vue"; import { useRouter, useRoute } from "vue-router"; import InsigniaList from "@/modules/01_metadataNew/components/insignia/InsigniaList.vue"; -const router = useRouter(); -const route = useRoute(); -const nameType = ref(""); import { useCounterMixin } from "@/stores/mixin"; +import http from "@/plugins/http"; +import config from "@/app.config"; +import { useQuasar } from "quasar"; +import { useInsigniaDataStore } from "@/modules/01_metadataNew/stores/InsigniaStore"; import type { DetailResponse, DetailRow, } from "@/modules/01_metadataNew/interface/response/insignia/Insignia"; +const nameType = ref(""); +const router = useRouter(); +const route = useRoute(); +const $q = useQuasar(); +const store = useInsigniaDataStore(); const row = ref(); const mixin = useCounterMixin(); -const { date2Thai } = mixin; +const { date2Thai, messageError, hideLoader, showLoader } = mixin; const id = ref(route.params.id.toString()); -function fetchName(name: string) { - nameType.value = name; +const insigniaTypeId = ref(""); + +async function fetchData(id: string) { + showLoader(); + await http + .get(config.API.insigniaTypeNewId(id)) + .then(async (res) => { + insigniaTypeId.value = res.data.result.name; + store.fetchData(res.data.result.insignias, res.data.result.name); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); } -const data = ref([ - { - id: "1", - level: 1, - shortName: "จ.ม.", - insigniaType: "ชั้นต่ำกว่าสายสะพาย", - insigniaTypeId: "1", - note: "-", - name: "จัตุรถาภรณ์มงกุฎไทย", - createdAt: new Date(), - lastUpdatedAt: new Date(), - lastUpdateFullName: "System Administrator", - isActive: true, - }, - { - id: "2", - level: 1, - shortName: "จ.ช.", - insigniaType: "ชั้นต่ำกว่าสายสะพาย", - insigniaTypeId: "1", - note: "-", - name: "จัตุรถาภรณ์ช้างเผือก", - createdAt: new Date(), - lastUpdatedAt: new Date(), - lastUpdateFullName: "คณะกรรมการ ตรวจรับ", - isActive: false, - }, - { - id: "1", - level: 1, - shortName: "บ.ม.", - insigniaType: "ชั้นสายสะพาย", - insigniaTypeId: "2", - note: "-", - name: "เบญจมาภรณ์มงกุฎไทย", - createdAt: new Date(), - lastUpdatedAt: new Date(), - lastUpdateFullName: "คณะกรรมการ ตรวจรับ", - isActive: true, - }, - { - id: "2", - level: 1, - shortName: "ท.ม.", - insigniaType: "ชั้นสายสะพาย", - insigniaTypeId: "2", - note: "-", - name: "ทวีติยาภรณ์มงกุฎไทย", - createdAt: new Date(), - lastUpdatedAt: new Date(), - lastUpdateFullName: "คณะกรรมการ ตรวจรับ", - isActive: true, - }, - { - id: "1", - level: 1, - shortName: "บ.ช.", - insigniaType: "เหรียญบำเหน็จในราชการ", - insigniaTypeId: "3", - note: "-", - name: "เบญจมาภรณ์ช้างเผือก", - createdAt: new Date(), - lastUpdatedAt: new Date(), - lastUpdateFullName: "สาวิตรี ศรีสมัย", - isActive: true, - }, - { - id: "2", - level: 1, - shortName: "ท.ม.", - insigniaType: "เหรียญบำเหน็จในราชการ", - insigniaTypeId: "3", - note: "-", - name: "ทวีติยาภรณ์มงกุฎไทย", - createdAt: new Date(), - lastUpdatedAt: new Date(), - lastUpdateFullName: "System Administrator", - isActive: true, - }, -]); - -function fetchData() { - const datafilter = data.value.find((e) => e.insigniaTypeId === id.value); - console.log(datafilter); - datafilter && fetchName(datafilter.insigniaType); - const list = data.value.map((e) => ({ - ...e, - createdAt: e.createdAt ? date2Thai(e.createdAt) : "", - lastUpdatedAt: e.lastUpdatedAt ? date2Thai(e.lastUpdatedAt) : "", - })); - row.value = list.filter((e) => e.insigniaTypeId === id.value); -} - -onMounted(() => { - fetchData(); +onMounted(async () => { + fetchData(id.value); }); diff --git a/src/modules/01_metadataNew/components/insignia/InsigniaList.vue b/src/modules/01_metadataNew/components/insignia/InsigniaList.vue index 846725371..a77a1fe19 100644 --- a/src/modules/01_metadataNew/components/insignia/InsigniaList.vue +++ b/src/modules/01_metadataNew/components/insignia/InsigniaList.vue @@ -2,13 +2,23 @@ import { ref, onMounted } from "vue"; import type { QTableProps } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; -import { useRouter } from "vue-router"; +import { useRouter, useRoute } from "vue-router"; +import { useInsigniaDataStore } from "@/modules/01_metadataNew/stores/InsigniaStore"; import dialogHeader from "@/components/DialogHeader.vue"; import { useQuasar } from "quasar"; - +import http from "@/plugins/http"; +import config from "@/app.config"; +const store = useInsigniaDataStore(); const router = useRouter(); const mixin = useCounterMixin(); -const { date2Thai, dialogRemove, dialogConfirm } = mixin; +const { + date2Thai, + dialogRemove, + dialogConfirm, + showLoader, + hideLoader, + messageError, +} = mixin; const $q = useQuasar(); const columns = ref([ { @@ -119,7 +129,8 @@ const columns = ref([ a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }), }, ]); - +const route = useRoute(); +const id = ref(route.params.id.toString()); const filterKeyword = ref(""); const dialog = ref(false); const isActive = ref(false); @@ -130,6 +141,7 @@ const insigniaTypeId = ref(""); const nameRef = ref(null); const shortNameRef = ref(null); const dialogStatus = ref(""); +const editId = ref(""); const visibleColumns = ref([ "level", "name", @@ -142,11 +154,6 @@ const visibleColumns = ref([ "note", ]); -const props = defineProps({ - data: { type: Object }, - nameType: { type: String }, -}); - function closeDialog() { dialog.value = false; } @@ -157,21 +164,78 @@ function validateForm() { onSubmit(); } +async function fetchData(id: string) { + showLoader(); + await http + .get(config.API.insigniaTypeNewId(id)) + .then(async (res) => { + insigniaTypeId.value = res.data.result.name; + store.fetchData(res.data.result.insignias, res.data.result.name); + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); +} +onMounted(async () => { + fetchData(id.value); + console.log(id.value); +}); + async function onSubmit() { if (name.value.length > 0 && shortName.value.length > 0) { dialogConfirm( $q, async () => { - console.log("สำเร็จ"); + dialogStatus.value === "create" ? addData() : editData(editId.value); closeDialog(); name.value = ""; shortName.value = ""; + isActive.value = false; + note.value = ""; }, "ยืนยันการบันทึกข้อมูล", "ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?" ); } } + +async function addData() { + await http.post(config.API.insignia, { + name: name.value, + isActive: isActive.value, + shortName: shortName.value, + note: note.value == "" ? "-" : "", + insigniaTypeId: id.value, + }); + fetchData(id.value); +} + +async function editData(idData: string) { + await http.put(config.API.insigniaNewId(idData), { + name: name.value, + isActive: isActive.value, + shortName: shortName.value, + note: note.value == "" ? "-" : "", + insigniaTypeId: id.value, + }); + fetchData(id.value); +} + +async function deleteData(idData: string) { + await http.delete(config.API.insigniaNewId(idData)); + fetchData(id.value); +} + +import { defineEmits } from "vue"; + +const emit = defineEmits(["nameType"]); + +const nameType = () => { + emit("nameType", insigniaTypeId.value); +};