export default { data() { return { } }, methods: { calculateScore(data) { let score = 0; //计算总分 let totalScore = 0; //总分 let doWrongQuestionIds = []; //做错题id(案例题简答不算在内) let doQuestionIds = []; //做过的题目id let lessQuestionNum = 0; //多选题少选 let rightQuestionIds = []; //做对的题目id let totalQuestionNum = 0; //排除主观题的总条数(简单题) data.forEach((item) => { console.log("答案--", item.ans, "选择--", item.ques); totalScore += item.score * (item.type == 4 ? item.jsonStr.length : 1); if ( item.type < 4 || (item.type == 4 && !item.jsonStr.some((e) => e.type == 5)) ) { totalQuestionNum++; } if (item.type == 1 || item.type == 3) { //正确 if (item.ques == item.ans) { item.scoreResult = item.score; score += item.score; rightQuestionIds.push(item.questionId); } else { //错误 item.scoreResult = 0; if (item.ques) { doWrongQuestionIds.push(item.questionId); } } if (item.ques) { doQuestionIds.push(item.questionId); } } else if (item.type == 2) { let isRight = item.ans && item.ans.every((quesItem, quesIndex) => { if (item.ques) { return item.ques[quesIndex] == item.ans[quesIndex]; } else { return false; } }); if (isRight) { score += item.score; item.scoreResult = item.score; rightQuestionIds.push(item.questionId); } else { let hasPart = false; let checkboxScore = 1; //获取单题总分数 item.ques && item.ques.forEach((ques, quesIndex) => { //选错一个全扣 if (item.ques) { if (item.ans.indexOf(item.ques[quesIndex]) == -1) { checkboxScore = 0; } } else { checkboxScore = 0; } }); //没选错 if (checkboxScore) { checkboxScore = 0; item.ans.forEach((ans, quesIndex) => { //漏选扣一部分,对n题给n X partScore 分 if (item.ques) { if (item.ques.indexOf(item.ans[quesIndex]) != -1) { checkboxScore += item.partScore; hasPart = true; } } else { checkboxScore = 0; } }); } if (!hasPart) { //0分 item.scoreResult = 0; if (item.ques) { doWrongQuestionIds.push(item.questionId); } } else { //部分分 lessQuestionNum++; item.scoreResult = checkboxScore; score += checkboxScore; } } if (item.ques && item.ques.length) { doQuestionIds.push(item.questionId); } } else if (item.type == 4) { let len = item.ans.length; let questionScore = 0; if (item.ques && item.ques.length) { item.ques.forEach((ele, idx) => { if ( ele == item.ans[idx] || (item.jsonStr[idx].type == 2 && ele.toString() == item.ans[idx].toString()) ) { len--; questionScore += item.score; } }); score += questionScore; item.scoreResult = questionScore; len == 0 && rightQuestionIds.push(item.questionId); doQuestionIds.push(item.questionId); } } else if (item.type == 5) { if (item.ques && (item.ques.imageList.length || item.ques.text)) { doQuestionIds.push(item.questionId); } } }); return { reportStatus: score >= (data[0].passScore || totalScore * 0.6) ? 1 : 0, lessQuestionNum, performance: score, totalScore, doQuestionNum: doQuestionIds.length, doQuestionIds: doQuestionIds.join(","), rightQuestionIds: rightQuestionIds.join(","), rightQuestionNum: rightQuestionIds.length, rightRate:(rightQuestionIds.length / totalQuestionNum).toFixed(2), historyExamJson: JSON.stringify(data), questionIds: doWrongQuestionIds, totalQuestionNum, }; }, go(path) { this.$router.push({ path, }); }, }, beforeDestroy() { try { this.$msgbox.close(); } catch (err) { } }, }