finished skipping questions
This commit is contained in:
parent
96abb6559e
commit
41fa4e68a8
3 changed files with 29 additions and 21 deletions
|
@ -16,6 +16,7 @@ export default new Vuex.Store({
|
|||
this.state.currentQuestion = 0
|
||||
},
|
||||
answerQuestion(state, pl) {
|
||||
this.state.skipped[pl.id] = false
|
||||
this.state.answers[pl.id] = pl.answer
|
||||
},
|
||||
setSkipped(state, n) {
|
||||
|
|
|
@ -38,13 +38,13 @@
|
|||
},
|
||||
methods: {
|
||||
nextQuestion() {
|
||||
this.$store.commit("setSkipped", this.$route.params.id)
|
||||
if (this.$route.params.id < this.$store.state.questions.length - 1) {
|
||||
const nextQuestion = parseInt(this.$route.params.id) + 1
|
||||
this.$router.push("/questionnaire/" + nextQuestion)
|
||||
}
|
||||
else {
|
||||
this.$store.commit("setSurveyCompleted")
|
||||
this.$store.commit("setSkipped", this.$route.params.id)
|
||||
router.push('/results')
|
||||
}
|
||||
},
|
||||
|
|
|
@ -29,35 +29,42 @@
|
|||
export default {
|
||||
name: "Results",
|
||||
mounted() {
|
||||
const summed = this.$store.state.answers.map((x, i) => {
|
||||
return x * this.$store.state.questions[i].multiplicator
|
||||
const answersFiltered = this.$store.state.answers.filter((value, index) => {
|
||||
return !this.$store.state.skipped[index]
|
||||
})
|
||||
const questionsFiltered = this.$store.state.questions.filter((value, index) => {
|
||||
return !this.$store.state.skipped[index]
|
||||
})
|
||||
|
||||
const summed = answersFiltered.map((x, i) => {
|
||||
return x * questionsFiltered[i].multiplicator
|
||||
}).reduce(function(acc, current) {
|
||||
return acc + current
|
||||
})
|
||||
|
||||
const sumMult = this.$store.state.questions.reduce(function(acc, current) {
|
||||
const sumMult = questionsFiltered.reduce(function(acc, current) {
|
||||
return acc + current.multiplicator
|
||||
}, 0)
|
||||
|
||||
this.risk = Math.round(summed / sumMult)
|
||||
|
||||
for(let i = 0; i < this.$store.state.answers.length; i ++) {
|
||||
if (this.$store.state.answers[i] < 33) {
|
||||
this.good.push({
|
||||
title: this.$store.state.questions[i].cards.good,
|
||||
description: this.$store.state.questions[i].cards.information
|
||||
})
|
||||
} else if (this.$store.state.answers[i] < 66) {
|
||||
this.warning.push({
|
||||
title: this.$store.state.questions[i].cards.okay,
|
||||
description: this.$store.state.questions[i].cards.information
|
||||
})
|
||||
} else {
|
||||
this.bad.push({
|
||||
title: this.$store.state.questions[i].cards.bad,
|
||||
description: this.$store.state.questions[i].cards.information
|
||||
})
|
||||
}
|
||||
for(let i = 0; i < answersFiltered.length; i ++) {
|
||||
if (answersFiltered[i] < 33) {
|
||||
this.good.push({
|
||||
title: questionsFiltered[i].cards.good,
|
||||
description: questionsFiltered[i].cards.information
|
||||
})
|
||||
} else if (answersFiltered[i] < 66) {
|
||||
this.warning.push({
|
||||
title: questionsFiltered[i].cards.okay,
|
||||
description: questionsFiltered[i].cards.information
|
||||
})
|
||||
} else {
|
||||
this.bad.push({
|
||||
title: questionsFiltered[i].cards.bad,
|
||||
description: questionsFiltered[i].cards.information
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
|
|
Loading…
Reference in a new issue