gs-jjsp-web/bns/js/studyExam/dayExamDetail.js

114 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let form, layer;
let idx = -1; // 默认选中题目的下标
let dataList = []; // 题目数组
let dataObj = {};
function setParams(params) {
dataObj = JSON.parse(params);
layui.use(['form', 'layer'], function () {
form = layui.form;
layer = layui.layer;
getDayExamRecordDetail();
})
}
// 初始化题目数据
function initDayExamData(data) {
dataList.splice(0, dataList.length);
if (data && data.length > 0) {
// 加载题目
renderQuestion(data);
}
}
function renderQuestion(data) {
let html = '';
$.each(data, function (index, q) {
html += '<div class="topic-box">'
// 题目
html += '<div class="question-title" id="question-title">' + (`${index + 1}题(<span style="color:#2196f3">${parseInt(q.topicType) === 1 ? '单选题' : '多选题'}</span><br><br>${q.topic}`) + '</div>'
// 选项
html += '<div class="options" id="options">'
let topicOptionArr = q.topicOption.split('|');
$.each(topicOptionArr, function (index2, item) {
let option = item.split('-')[0];
if (parseInt(q.topicType) === 1) { // 单选题
html += "<div class='option'>" +
setChooseData(q, item) +
"<span style='width:calc(100% - 40px);margin-left:16px;' value='" + option + "'>" + item.replace('-', '.') + "</span>" +
"</div>";
} else { // 多选题
html += "<div class='option'>" +
setChooseData(q, item) +
"<span style='width:calc(100% - 40px);margin-left:16px;' value='" + option + "'>" + item.replace('-', '.') + "</span>" +
"</div>";
}
})
html += '</div>'
// 答案
html += setAnswerData(q);
html += '</div>'
})
$('#topic').html(html);
// 是否答完题目 赋值
function setChooseData(q, item) {
let option = item.split('-')[0];
let topicAnswer = q.topicAnswer, chooseAnswer = q.chooseAnswer, topicType = parseInt(q.topicType);
let html = "", classValue = "", value = "";
if (topicType === 1) { // 单选题
if (topicAnswer === option || chooseAnswer === topicAnswer === option) { // 选择正确
classValue = "circle correct layout", value = "✔";
} else if (topicAnswer !== option && option === chooseAnswer) { // 选择错误
classValue = "circle error layout", value = "×";
} else {
classValue = "circle";
}
html += "<span class='" + classValue + "'>" + value + "</span>";
} else if (topicType === 2) { // 多选题
if (topicAnswer.indexOf(option) > -1 || (chooseAnswer.indexOf(option) > -1 && topicAnswer.indexOf(option) > -1)) { // 选择正确
classValue = "square correct layout", value = "✔";
} else if ((topicAnswer.indexOf(option) > -1 && chooseAnswer.indexOf(option) === -1)
|| (topicAnswer.indexOf(option) === -1 && chooseAnswer.indexOf(option) > -1)) { // 选择错误
classValue = "square error layout", value = "×";
} else {
classValue = "square";
}
html += "<span class='" + classValue + "'>" + value + "</span>";
}
return html;
}
}
// 答案赋值
function setAnswerData(q) {
let html = "<div class='answer-box layout'>" +
"<div class='answer layout'>" +
"<p>正确答案</p>" +
"<p>" + q.topicAnswer + "</p>" +
"</div>" +
"<div class='answer layout'>" +
"<p>我的答案</p>" +
"<p>" + q.chooseAnswer + "</p>" +
"</div>" +
"</div>";
return html;
}
// 获取分配的考试题目
function getDayExamRecordDetail() {
let url = dataUrl + "proteam/sys/exam/getDayExamRecordDetail";
let params = { id: dataObj.id }
let loadingMsg = layer.msg('题目加载中,请稍候...', { icon: 16, scrollbar: false, time: 0 });
ajaxRequest2(url, "POST", params, true, function (result) {
layer.close(loadingMsg); // 关闭提示层
if (result.code === 200) {
initDayExamData(result.data);
} else {
layer.msg(result.msg, { icon: 2 })
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
}, null, token);
}