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 += '
' // 题目 html += '
' + (`第${index + 1}题(${parseInt(q.topicType) === 1 ? '单选题' : '多选题'}):

${q.topic}`) + '
' // 选项 html += '
' let topicOptionArr = q.topicOption.split('|'); $.each(topicOptionArr, function (index2, item) { let option = item.split('-')[0]; if (parseInt(q.topicType) === 1) { // 单选题 html += "
" + setChooseData(q, item) + "" + item.replace('-', '.') + "" + "
"; } else { // 多选题 html += "
" + setChooseData(q, item) + "" + item.replace('-', '.') + "" + "
"; } }) html += '
' // 答案 html += setAnswerData(q); html += '
' }) $('#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 += "" + value + ""; } 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 += "" + value + ""; } return html; } } // 答案赋值 function setAnswerData(q) { let html = "
" + "
" + "

正确答案

" + "

" + q.topicAnswer + "

" + "
" + "
" + "

我的答案

" + "

" + q.chooseAnswer + "

" + "
" + "
"; 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); }