diff --git a/src/api/api.message.ts b/src/api/api.message.ts index be5d2c6..d7622a5 100644 --- a/src/api/api.message.ts +++ b/src/api/api.message.ts @@ -4,7 +4,8 @@ const message = `${env.API_URI}/message`; const reply = `${env.API_URI}/placement/noti`; export default { - msgNotificate: `${message}/my-notifications`, - msgInbox: `${message}/my-inboxes`, - replyMessage: (id: string) => `${reply}/${id}`, + msgNotificate: `${message}/my-notifications`, + msgInbox: `${message}/my-inboxes`, + msgId: (id: string) => `${message}/my-notifications/${id}`, + replyMessage: (id: string) => `${reply}/${id}`, }; diff --git a/src/views/MainLayout.vue b/src/views/MainLayout.vue index 8cab35c..46cab97 100644 --- a/src/views/MainLayout.vue +++ b/src/views/MainLayout.vue @@ -13,7 +13,14 @@ const router = useRouter(); const $q = useQuasar(); const mixin = useCounterMixin(); -const { date2Thai } = mixin; +const { + date2Thai, + dialogRemove, + showLoader, + hideLoader, + messageError, + success, +} = mixin; const fullname = ref(""); const notiList = ref([]); @@ -26,31 +33,53 @@ const link = ref(""); * เรียกฟังก์ชันทั้งหมดตอนเรียกใช้ไฟล์นี้ */ onMounted(async () => { - await fetchlistNotification(1); + await fetchlistNotification(1, "NOMAL"); if (keycloak.tokenParsed != null) { fullname.value = keycloak.tokenParsed.name; } }); -const fetchlistNotification = async (index: number) => { +const fetchlistNotification = async (index: number, type: string) => { await http .get(config.API.msgNotificate + `?page=${index}&pageSize=${20}`) .then((res: any) => { const data = res.data.result.data; - totalInbox.value = res.data.result.total; + let list: any[] = []; - data.map((e: any) => { - list.push({ - id: e.id, - sender: - e.createdFullName == "" || e.createdFullName == null - ? "เจ้าหน้าที่"[0] - : e.createdFullName[0], - body: e.body ?? "", - timereceive: date2Thai(e.createdAt), + if (type === "DEL") { + totalInbox.value = res.data.result.total; + console.log(notiList.value.length); + + if (notiList.value.length === 14) { + notiList.value = []; + data.map((e: any) => { + list.push({ + id: e.id, + sender: + e.createdFullName == "" || e.createdFullName == null + ? "เจ้าหน้าที่"[0] + : e.createdFullName[0], + body: e.body ?? "", + timereceive: date2Thai(e.createdAt), + }); + }); + notiList.value.push(...list); + } + } else { + data.map((e: any) => { + list.push({ + id: e.id, + sender: + e.createdFullName == "" || e.createdFullName == null + ? "เจ้าหน้าที่"[0] + : e.createdFullName[0], + body: e.body ?? "", + timereceive: date2Thai(e.createdAt), + }); }); - }); - notiList.value.push(...list); + notiList.value.push(...list); + totalInbox.value = res.data.result.total; + } }) .catch((err) => { console.log(err); @@ -73,11 +102,32 @@ const doLogout = () => { }); }; +const clickDelete = async (id: string, index: number) => { + dialogRemove($q, async () => { + showLoader(); + await http + .delete(config.API.msgId(id)) + .then(() => { + notiList.value.splice(index, 1); + success($q, "ลบข้อมูลสำเร็จ"); + }) + .catch((e) => { + messageError($q, e); + }) + .finally(async () => { + fetchlistNotification(1, "DEL"); + hideLoader(); + }); + }); +}; + const totalInbox = ref(0); +const page = ref(1); function onLoad(index: any, done: any) { + page.value = index + 1; if (notiList.value.length < totalInbox.value) { setTimeout(() => { - fetchlistNotification(index + 1); + fetchlistNotification(page.value, "NOMAL"); done(); }, 2000); } @@ -159,24 +209,24 @@ function onLoad(index: any, done: any) { floating >{{ totalInbox }} - +
การแจ้งเตือน
- + /> -->
- +
-