Moved lotteryColors to data and read from object for color values.

This commit is contained in:
2020-03-20 17:31:54 +01:00
parent d928905a58
commit d1e5d60885

View File

@@ -76,7 +76,7 @@
<h3>Legg til lodd kjøpt</h3> <h3>Legg til lodd kjøpt</h3>
<div class="colors"> <div class="colors">
<div <div
v-for="color in lotteryColorBoxes" v-for="color in lotteryColors"
:class="color.css + ' colors-box'" :class="color.css + ' colors-box'"
:key="color" :key="color"
> >
@@ -184,6 +184,12 @@ export default {
showToast: false, showToast: false,
showCamera: false, showCamera: false,
editWine: 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__ price: __PRICE__
}; };
}, },
@@ -195,16 +201,6 @@ export default {
beforeDestroy() { beforeDestroy() {
this.setWinnerdataToStorage(); 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: { methods: {
amIBeingEdited(wine) { amIBeingEdited(wine) {
return this.editWine.id == wine.id && this.editWine.name == wine.name; return this.editWine.id == wine.id && this.editWine.name == wine.name;
@@ -285,13 +281,17 @@ export default {
}); });
}, },
sendInfo: async function(event) { 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 = { let sendObject = {
purchase: { purchase: {
date: new Date(), date: new Date(),
blue: this.blue, ...colors
red: this.red,
yellow: this.yellow,
green: this.green
}, },
winners: this.winners winners: this.winners
}; };
@@ -374,7 +374,7 @@ export default {
let localColors = localStorage.getItem("colorValues"); let localColors = localStorage.getItem("colorValues");
if (localColors) { if (localColors) {
localColors = localColors.split(","); localColors = localColors.split(",");
this.lotteryColorBoxes.forEach((color, i) => { this.lotteryColors.forEach((color, i) => {
const localColorValue = Number(localColors[i]); const localColorValue = Number(localColors[i]);
color.value = localColorValue == 0 ? null : localColorValue; color.value = localColorValue == 0 ? null : localColorValue;
}); });
@@ -385,14 +385,14 @@ export default {
localStorage.setItem("winners", JSON.stringify(this.winners)); localStorage.setItem("winners", JSON.stringify(this.winners));
localStorage.setItem( localStorage.setItem(
"colorValues", "colorValues",
this.lotteryColorBoxes.map(color => Number(color.value)) this.lotteryColors.map(color => Number(color.value))
); );
window.removeEventListener("unload", this.setWinnerdataToStorage); window.removeEventListener("unload", this.setWinnerdataToStorage);
}, },
resetWinnerDataInStorage() { resetWinnerDataInStorage() {
this.winners = []; this.winners = [];
this.fetchAndAddPrelotteryWines().then(resp => (this.winners = resp)); this.fetchAndAddPrelotteryWines().then(resp => (this.winners = resp));
this.lotteryColorBoxes.map(color => (color.value = null)); this.lotteryColors.map(color => (color.value = null));
window.location.reload(); window.location.reload();
} }
} }