diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue index db03e7a44..f44966864 100644 --- a/src/views/Dashboard.vue +++ b/src/views/Dashboard.vue @@ -29,43 +29,45 @@ const inboxList = ref([]); const data = ref([]); onMounted(async () => { - await getData(); + await getData(1); }); -const getData = async () => { - showLoader(); - await http - .get(config.API.msgInbox) - .then((res: any) => { - const data = res.data.result; +const getData = async (index: number) => { + index === 1 && showLoader(); + index != 0 && + (await http + .get(config.API.msgInbox + `?page=${index}&pageSize=${10}`) + .then((res: any) => { + const data = res.data.result.data; + totalInbox.value = res.data.result.total; - let list: DataInbox[] = []; - data.map((e: ResponseInbox) => { - list.push({ - no: e.id ?? "", - sender: - e.createdFullName == "" || e.createdFullName == null - ? "เจ้าหน้าที่" - : e.createdFullName, - subject: e.subject ?? "", - timereceive: new Date(e.receiveDate), - body: e.body ?? "", - payload: e.payload, - ratingModel: 0, + let list: DataInbox[] = []; + data.map((e: ResponseInbox) => { + list.push({ + no: e.id ?? "", + sender: + e.createdFullName == "" || e.createdFullName == null + ? "เจ้าหน้าที่" + : e.createdFullName, + subject: e.subject ?? "", + timereceive: new Date(e.receiveDate), + body: e.body ?? "", + payload: e.payload, + ratingModel: 0, + }); }); - }); - inboxList.value = list; + inboxList.value.push(...list); - if (inboxList.value.length > 0) { - selectInbox(inboxList.value[0].no); - } - }) - .catch((e) => { - messageError($q, e); - }) - .finally(() => { - hideLoader(); - }); + if (inboxList.value.length > 0) { + selectInbox(inboxList.value[0].no); + } + }) + .catch((e) => { + messageError($q, e); + }) + .finally(() => { + hideLoader(); + })); }; const selectInbox = (id: string) => { @@ -88,7 +90,7 @@ const removeData = async (id: string) => { messageError($q, e); }) .finally(() => { - getData(); + // getData(); hideLoader(); }); }; @@ -105,6 +107,18 @@ function dialogRepleOpen() { function modalReplyClose() { modalReply.value = false; } + +const scrollTargetRef = ref(null); +const totalInbox = ref(0); +function onLoad(index: number, done: any) { + const num = index === 1 ? 0 : index++; + if (inboxList.value.length < totalInbox.value) { + setTimeout(() => { + getData(num); + done(); + }, 2000); + } +} @@ -128,7 +142,68 @@ function modalReplyClose() {
กล่องข้อความ
- + + + + + {{ + date2Thai(contact.timereceive) + }} + {{ + contact.sender + }} + {{ + contact.subject + }} + + + + + + + + + + + + - - + --> @@ -248,7 +315,7 @@ function modalReplyClose() { > ตอบกลับข้อความ - + ([ }, ]); -const getDataNotification = async () => { +const getDataNotification = async (index: number) => { // showLoader(); await http - .get(config.API.msgNotificate) + .get(config.API.msgNotificate + `?page=${index}&pageSize=${20}`) .then((res: any) => { - const response = res.data.result; + const response = res.data.result.data; + totalInbox.value = res.data.result.total; let list: notiType[] = []; response.map((e: any) => { list.push({ @@ -101,7 +102,7 @@ const getDataNotification = async () => { timereceive: new Date(e.receiveDate), }); }); - notiList.value = list; + notiList.value.push(...list); }) .catch((e) => { // messageError($q, e); @@ -218,7 +219,7 @@ onMounted(async () => { await fetchroleUser(keycloak.tokenParsed.role); } - await getDataNotification(); + await getDataNotification(1); myEventHandler(null, false); window.addEventListener("resize", (e: any) => { myEventHandler(e, true); @@ -421,7 +422,7 @@ const deleteData = async (id: string) => { messageError($q, e); }) .finally(async () => { - getDataNotification(); + getDataNotification(1); hideLoader(); }); }; @@ -429,6 +430,16 @@ const deleteData = async (id: string) => { const clickDelete = (id: string) => { dialogRemove($q, () => deleteData(id)); }; + +const totalInbox = ref(0); +function onLoad(index: any, done: any) { + if (notiList.value.length < totalInbox.value) { + setTimeout(() => { + getDataNotification(index + 1); + done(); + }, 2000); + } +} @@ -485,41 +496,58 @@ const clickDelete = (id: string) => { color="negative" text-color="white" floating - >{{ notiList.length }}{{ totalInbox }}
การแจ้งเตือน
- - - - - {{ - n.sender - }} - - - - {{ - n.body - }} - {{ - date2Thai(n.timereceive) - }} - - - - - + + + + + + {{ + n.sender + }} + + + + {{ + n.body + }} + {{ date2Thai(n.timereceive) }} + + + + + + +