From d5d091ea83561a758b5b60db0ebad581ca451686 Mon Sep 17 00:00:00 2001 From: hiyu Date: Sat, 15 Jun 2024 19:34:27 +0700 Subject: [PATCH] fix: game history --- src/components/lottery/LotteryGame.vue | 98 +++++++++++++++++++------- 1 file changed, 71 insertions(+), 27 deletions(-) diff --git a/src/components/lottery/LotteryGame.vue b/src/components/lottery/LotteryGame.vue index f88ef15..d8cdbeb 100644 --- a/src/components/lottery/LotteryGame.vue +++ b/src/components/lottery/LotteryGame.vue @@ -18,6 +18,8 @@ const id = route.query.id; const amount = ref(""); const isShowOrder = ref(false); const showResult = ref(false); +const gameHistory = ref([]); + const showPopupRs = () => { showResult.value = !showResult.value; }; @@ -60,62 +62,87 @@ io.on("game-info", (data) => { const { name, session, end } = data; Object.assign(gameInfo, { name, session, end }); countDownTime.restart(end); + getGameHistory(); }); const toggleChoice = (idx) => { choices.value[idx].active = !choices.value[idx].active; - if(!choices.value[idx].active) { + if (!choices.value[idx].active) { choices.value[idx].amount = 0; } }; +const getGameHistory = () => { + const params = { page: 1, size: 20 }; + handleRequest(axios.get(API.GAME_HISTORY + "/" + id, { params })).then( + (res) => { + if (res.success) { + gameHistory.value = res.data; + } + } + ); +}; const submit = () => { - const cs = choices.value.filter(e => e.active) - if(cs.length === 0) return; + const cs = choices.value.filter((e) => e.active); + if (cs.length === 0) return; const data = { id, - choices: cs.map(e => { + choices: cs.map((e) => { return { id: e.id, - amount: Number(amount.value) - } - }) - } - handleRequest(axios.post(API.ORDER, data)).then(res => { - if(res.success) { - showFailToast("Bình chọn thành công.") + amount: Number(amount.value), + }; + }), + }; + handleRequest(axios.post(API.ORDER, data)).then((res) => { + if (res.success) { + showFailToast("Bình chọn thành công."); amount.value = 0; - choices.value.forEach((e) => e.active = 0); + choices.value.forEach((e) => (e.active = 0)); } else { - showFailToast(res.message ?? "Lỗi bình chọn") + showFailToast(res.message ?? "Lỗi bình chọn"); } - }) -} + }); +}; const countChoices = computed(() => { return choices.value.filter((e) => e.active).length; }); const totalAmount = computed(() => { return choices.value.reduce((prev, curr) => { - return prev + (curr.active ? amount.value : 0) + return prev + (curr.active ? amount.value : 0); }, 0); }); const choicesText = computed(() => { const cs = choices.value.filter((e) => e.active); - if(cs.length) { - return cs.map(e => e.name).join(",") + if (cs.length) { + return cs.map((e) => e.name).join(","); } - return "Không được chọn" + return "Không được chọn"; }); watch(amount, (value) => { - choices.value.forEach(c => { + choices.value.forEach((c) => { c.amount = value; }); }); +const formatResultText1 = (r) => { + const s = r.split(",").reduce((prev, curr) => { + return prev + (curr >> 0); + }, 0); + + return s > 10 ? "IDOL 1" : "IDOL 2"; +}; +const formatResultText2 = (r) => { + const s = r.split(",").reduce((prev, curr) => { + return prev + (curr >> 0); + }, 0); + return s % 2 ? "IDOL 3" : "IDOL 4"; +}; +