@@ -171,10 +171,6 @@ export default {
components: { TextToast, Wine, ScanToVinmonopolet },
data() {
return {
- red: null,
- blue: null,
- green: null,
- yellow: null,
payed: undefined,
winners: [],
wines: [],
@@ -184,6 +180,12 @@ export default {
showToast: false,
showCamera: false,
editWine: false,
+ lotteryColors: [
+ { value: null, name: "Blå", css: "blue" },
+ { value: null, name: "Rød", css: "red" },
+ { value: null, name: "Grønn", css: "green" },
+ { value: null, name: "Gul", css: "yellow" }
+ ],
price: __PRICE__
};
},
@@ -195,16 +197,6 @@ export default {
beforeDestroy() {
this.setWinnerdataToStorage();
},
- computed: {
- lotteryColorBoxes() {
- return [
- { value: this.blue, name: "Blå", css: "blue" },
- { value: this.red, name: "Rød", css: "red" },
- { value: this.green, name: "Grønn", css: "green" },
- { value: this.yellow, name: "Gul", css: "yellow" }
- ];
- }
- },
methods: {
amIBeingEdited(wine) {
return this.editWine.id == wine.id && this.editWine.name == wine.name;
@@ -285,13 +277,17 @@ export default {
});
},
sendInfo: async function(event) {
+ const colors = {
+ red: this.lotteryColors.filter(c => c.css == "red")[0].value,
+ green: this.lotteryColors.filter(c => c.css == "green")[0].value,
+ blue: this.lotteryColors.filter(c => c.css == "blue")[0].value,
+ yellow: this.lotteryColors.filter(c => c.css == "yellow")[0].value
+ }
+
let sendObject = {
purchase: {
date: new Date(),
- blue: this.blue,
- red: this.red,
- yellow: this.yellow,
- green: this.green
+ ...colors
},
winners: this.winners
};
@@ -314,10 +310,10 @@ export default {
}
sendObject.purchase.bought =
- parseInt(this.blue) +
- parseInt(this.red) +
- parseInt(this.green) +
- parseInt(this.yellow);
+ parseInt(colors.blue) +
+ parseInt(colors.red) +
+ parseInt(colors.green) +
+ parseInt(colors.yellow);
const stolen = sendObject.purchase.bought - parseInt(this.payed) / 10;
if (isNaN(stolen) || stolen == undefined) {
alert("Betalt må registreres");
@@ -374,7 +370,7 @@ export default {
let localColors = localStorage.getItem("colorValues");
if (localColors) {
localColors = localColors.split(",");
- this.lotteryColorBoxes.forEach((color, i) => {
+ this.lotteryColors.forEach((color, i) => {
const localColorValue = Number(localColors[i]);
color.value = localColorValue == 0 ? null : localColorValue;
});
@@ -385,14 +381,14 @@ export default {
localStorage.setItem("winners", JSON.stringify(this.winners));
localStorage.setItem(
"colorValues",
- this.lotteryColorBoxes.map(color => Number(color.value))
+ this.lotteryColors.map(color => Number(color.value))
);
window.removeEventListener("unload", this.setWinnerdataToStorage);
},
resetWinnerDataInStorage() {
this.winners = [];
this.fetchAndAddPrelotteryWines().then(resp => (this.winners = resp));
- this.lotteryColorBoxes.map(color => (color.value = null));
+ this.lotteryColors.map(color => (color.value = null));
window.location.reload();
}
}
diff --git a/src/components/VinlottisPage.vue b/src/components/VinlottisPage.vue
index a8da42e..b608cb3 100644
--- a/src/components/VinlottisPage.vue
+++ b/src/components/VinlottisPage.vue
@@ -52,6 +52,7 @@ import Banner from "@/ui/Banner";
import Wines from "@/ui/Wines";
import Vipps from "@/ui/Vipps";
import Countdown from "@/ui/Countdown";
+import { prelottery } from "@/api";
export default {
components: {
@@ -67,7 +68,6 @@ export default {
data() {
return {
hardStart: false,
- todayExists: false,
pushAllowed: false
};
},
@@ -81,21 +81,17 @@ export default {
!this.pushAllowed ||
localStorage.getItem("push") == null
);
+ },
+ todayExists: () => {
+ return prelottery()
+ .then(wines => wines.length > 0)
+ .catch(() => false)
}
},
mounted() {
this.$on("push-allowed", () => {
this.pushAllowed = true;
});
- fetch("/api/wines/prelottery")
- .then(wines => wines.json())
- .then(wines => {
- if (wines.length > 0) {
- this.todayExists = true;
- } else {
- this.todayExists = false;
- }
- });
if (window.location.hostname == "localhost") {
return;
}
diff --git a/src/components/VirtualLotteryPage.vue b/src/components/VirtualLotteryPage.vue
index 30fc135..257cb4e 100644
--- a/src/components/VirtualLotteryPage.vue
+++ b/src/components/VirtualLotteryPage.vue
@@ -15,6 +15,27 @@
Send vipps med melding "Vinlotteri" for å bli registrert til virtuelt lotteri
Send gjerne melding om fargeønsker også