$(function () {
layui.use(['layer', 'form', 'table'], function () {
var layer = layui.layer
, form = layui.form;
form.render('select');
});
let baseIdx = 0;
/**
*模板轮播切换
**/
$('.modules-box .btnItem').click(function () {
let $tplListEl = $('.modules-box .tplList');
let listW = $tplListEl.width();
let curLeft = Math.abs($tplListEl.position().left);
let curTpBoxW = $('.modules-box .tplCut').width();
let baseW = $('.modules-box .tplItem').eq(0).width() + 10;
if ($(this).hasClass('leftBtn')) {
if (baseIdx == 0) {
return
}
baseIdx--
} else if ($(this).hasClass('rightBtn')) {
if (curLeft + curTpBoxW == listW || curLeft + curTpBoxW > listW) {
return
}
baseIdx++
}
$tplListEl.animate({ left: -(baseIdx * baseW) }, 100)
})
/**
*切换答题卡列表
**/
$('body').on('change', 'input[name="cardUse"]', function (e) {
let idx = $('input[name="cardUse"]:checked').closest('tr').index()
cardListData.changeCardFun(cardListData.cardListData[idx].multiplex_id);
})
/**
*预览编辑模板
**/
$('body').on('click', '.menu', function (e) {
e.stopPropagation()
$(this).children('.triangle').css('display', 'flex')
$(this).children('.menuList').css('display', 'flex')
})
$(document).click(function () {
$('.menu').children('.triangle').css('display', 'none')
$('.menu').children('.menuList').css('display', 'none')
})
/**
*创建答题卡模板
**/
$('body').on('click', '#goAnswerSheet', function (e) {
let url = cardListData.useCardTool(cardListData.examGroupId)
if (this.item_collect) {
window.location.href = `${url}/mixSubjects.html?examGroupId=${cardListData.examGroupId}`
} else {
window.location.href = `${url}?isEdit=0&cardType=0&examGroupId=${cardListData.examGroupId}`
}
// window.location.href= '/index.php/online/answersheet?isEdit=0&cardType=0&examGroupId='+cardListData.examGroupId;
})
/**
*编辑模板
**/
$('body').on('click', '.setEditCard', function (e) {
if (cardListData.assist_status == 1 || cardListData.assist_status == 2) {
var that = this;
layer.tips('后台操作员未完成任务,暂不支持编辑!', that, { tips: [3, '#787878'] });
} else {
let idx = $(this).closest('tr').index()
// 非复用&已上传试卷考试,需要弹层提示
if (cardListData.isDownLoad == 0 && cardListData.isThird == 1 && cardListData.isUploadPaper == 1) {
layer.open({
title: '提示',
content: '试卷已上传,如更改试题结构,需重新上传试卷,请确认!',
btn: ['确认', '取消'],
yes: function (index, layero) {
cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 5, cardListData.cardListData[idx].is_copy)
layer.close(index);
}
});
} else {
cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 5, cardListData.cardListData[idx].is_copy)
}
}
})
/**
*下载模板
**/
$('body').on('click', '.setDownloadCard', function (e) {
if (cardListData.assist_status == 1 || cardListData.assist_status == 2) {
var that = this;
layer.tips('后台操作员未完成任务,暂不支持下载!', that, { tips: [3, '#787878'] });
} else {
let idx = $(this).closest('tr').index()
if (cardListData.isDownLoad == 0 && cardListData.isThird == 1) {
// 未被下载过的答题卡首次下载,需要弹层提示
layer.open({
title: '提示',
content: '下载后答题卡结构不能调整,是否下载答题卡?',
btn: ['确认下载', '取消'],
yes: function (index, layero) {
cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 2)
layer.close(index);
}
});
} else {
cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 2)
}
}
})
/**
* 打印
*/
$('body').on('click', '.handlerPrintPdf', function (e) {
let idx = $(this).closest('tr').index()
if (cardListData.assist_status == 1 || cardListData.assist_status == 2) {
var that = this;
layer.tips('后台操作员未完成任务,暂不支持打印!', that, { tips: [3, '#787878'] });
} else {
evaluationClient.BulkPrintPDF(JSON.stringify(cardListData.printParams));
cardListData.downloadCardFun(cardListData.cardListData[idx].multiplex_id);
}
})
/**
*查看模板
**/
$('body').on('click', '.setPreviewCard', function (e) {
let idx = $(this).closest('tr').index()
cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 4)
})
/**
*复用模板:当前存在可编辑模板时不能复用模板
**/
$('body').on('click', '.setReuseCard', function (e) {
let idx = $(this).closest('tr').index()
let defaultName = cardListData.cardListData[idx].name;
let id = cardListData.cardListData[idx].multiplex_id;
// cardListData.cardListData[idx].multiplex_id
let hasEditItem = cardListData.cardListData.filter(v => v.is_download == 0).length > 0;
if (hasEditItem) {
layer.msg('当前有可编辑答题卡,不允许复用!')
return;
}
layer.open({
title: '答题卡名称',
area: ['400px', '250px'],
content: '答题卡名称:'
, btn: ['确定', '取消']
, yes: function (index, layero) {
let curName = $('#newCardName').val().trim();
if (curName == '') {
$('#cardErr').html('请输入答题卡名称!')
} else if (cardListData.cardListData.filter(val => val.name == curName).length > 0) {
$('#cardErr').html('答题卡名称已存在!')
} else {
$('#cardErr').html('')
cardListData.setReuseCard({
multiplexId: id,
name: curName
})
layer.close(index);
}
return false
}
});
})
/**
*隐藏答题卡
**/
$('body').on('click', '.setHideCard', function (e) {
let idx = $(this).closest('tr').index();
let id = cardListData.cardListData[idx].multiplex_id;
if ($(this).closest('tr').find('.card-use').is(':checked')) {
layer.msg('当前应用模板不能隐藏!')
return
}
cardListData.setHideCard(id, cardListData.isHideList == 0 ? 1 : 0);
})
/**
*保存为我的模板
**/
$('body').on('click', '.setSaveTpl', function (e) {
let idx = $(this).closest('tr').index();
cardListData.saveAsMyTpl(idx);
})
/**
*显示隐藏答题卡列表
**/
$('body').on('change', '.show-all', function (e) {
cardListData.isHideList = $(this).is(':checked') ? 1 : 0;
cardListData.getCardList();
})
/**
*使用、预览、删除 模板
**/
$('body').on('click', '.menuList span', function (e) {
let idx = $(this).closest('.tplItem').index();
//存数据
let tplData = JSON.parse(cardListData.tplList[idx].tpl_data);
let tplTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
tplData.examGroupId = tplTestFormData.examGroupId;
// 没有下载答题卡&答题卡列表长度>1时, 拼接multiplexId
let str = '';
if ($('input[data-active="1"]').length > 0) {
let cardIdx = $('input[data-active="1"]').closest('tr').index();
let id = cardListData.cardListData[cardIdx].multiplex_id;
str = '&multiplexId=' + id
}
if ($(e.target).hasClass('use')) {
// 使用:当前存在答题卡列表,传入当前应用的multiplex_id
if ($('.create-card').is(':hidden') && cardListData.isUploadPaper == 1) {
//已创建过答题卡&已创建过试卷,需要弹层提示
layer.open({
title: '提示',
content: '试卷已上传,如更改试题结构,需重新上传试卷,请确认!',
btn: ['确认', '取消'],
yes: function (index, layero) {
let url = cardListData.useCardTool(tplTestFormData.examGroupId);
window.location.href = `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=0&isCopy=0&cardType=0${str}`;
layer.close(index);
// tplData.position.isUseTemp = true;
// localStorage.setItem('savePrintInfo',JSON.stringify(tplData));
// window.location.href= '/index.php/online/answersheet?examGroupId='+tplTestFormData.examGroupId+'&isEdit=0&isCopy=0&cardType=0'+str;
// layer.close(index);
}
});
} else {
let url = cardListData.useCardTool(tplTestFormData.examGroupId);
window.location.href = `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=0&isCopy=0&cardType=0${str}&tplId=${cardListData.tplList[idx].third_tpl_id}`;
// tplData.position.isUseTemp = true;
// localStorage.setItem('savePrintInfo',JSON.stringify(tplData));
// window.location.href= '/index.php/online/answersheet?examGroupId='+tplTestFormData.examGroupId+'&isEdit=0&isCopy=0&cardType=0'+str;
}
} else if ($(e.target).hasClass('preview')) {
// 预览
let url = cardListData.useCardTool(tplTestFormData.examGroupId);
window.location.href = `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=1&isPreview=1&isCopy=0&cardType=0${str}&tplId=${cardListData.tplList[idx].third_tpl_id}`;
// window.location.href= `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=1&isPreview=1&isCopy=0&cardType=0${str}`;
// localStorage.setItem('savePrintInfo',JSON.stringify(tplData));
// window.location.href= '/index.php/online/answersheet?examGroupId='+tplTestFormData.examGroupId+'&isEdit=1&isPreview=1&isCopy=0&cardType=0'+str;
} else if ($(e.target).hasClass('del')) {
// 删除
let _this = $(this);
$.post(cardListData.api.delTpl, { third_tpl_id: cardListData.tplList[idx].third_tpl_id }, function (res) {
var result = JSON.parse(res);
if (result.success === 1) {
_this.closest('.tplItem').remove()
$('#tplLength').text($('.tplItem').length)
if ($('.tplItem').length > 0) {
$('#tplListMsg').hide()
} else {
$('#tplListMsg').show()
}
}
})
}
// cardListData.saveAsMyTpl(idx);
})
// 题目审查
$('body').on('click', '#examine', function (e) {
let position = JSON.parse(cardListData.curCardTplData.position)
let topicListObject = Object.values(position.topicListObject)
const subjectName = { 12: "物理", 13: '化学', 14: '生物', 15: '政治', 16: '历史', 17: '地理' }
// 大题循环
let splitLis = []
for (let index = 0; index < topicListObject.length; index++) {
let json = { name: topicListObject[index].questionTitleVal, groups: {} }
// 找出学科相同组
for (let ind = 0; ind < topicListObject[index].quesNoArr.length; ind++) {
const element = topicListObject[index].quesNoArr[ind];
let subject = element.subject;
if (json.groups[subject] === undefined) {
json.groups[subject] = [element];
} else {
// 判断下一个是不是跟前一个连贯的
if (element.start - 1 == json.groups[subject].slice(-1)[0].end - 0 && json.groups[subject].slice(-1)[0].subject == element.subject) {
json.groups[subject][json.groups[subject].length - 1].end = element.end
} else {
json.groups[subject].push(element);
}
}
}
// // 存储的小题
// let questions = topicListObject[index].questions
// const result = questions.reduce((acc, cur) => {
// const index = acc.findIndex(item => item.name === cur.subject);
// if (index === -1) {
// acc.push({ name: cur.subject, alias: [String(cur.alias)] });
// } else {
// const lastAlias = acc[index].alias[acc[index].alias.length - 1];
// if (lastAlias && lastAlias.split("-")[1] === String(cur.alias - 1)) {
// acc[index].alias[acc[index].alias.length - 1] = `${lastAlias.split("-")[0]}-${cur.alias}`;
// } else {
// acc[index].alias.push(String(cur.alias));
// }
// }
// return acc;
// }, []);
// json.list = result
splitLis.push(json)
}
let html = '
'
for (let index = 0; index < splitLis.length; index++) {
html += `
${splitLis[index].name}
`
let str = '';
const element = splitLis[index];
Object.keys(element.groups).forEach((keys, i) => {
const list = element.groups[keys];
str += `
${subjectName[keys]} `
for (let index = 0; index < list.length; index++) {
if (list[index].start != list[index].end) {
str += (list[index].start + "~" + list[index].end) + (list.length > 1 && index < list.length - 1 ? ',' : '')
} else {
str += list[index].start + (list.length > 1 && index < list.length - 1 ? ',' : '');
}
}
str += `
`
});
html += `
${str}
`
}
html += '
'
//墨绿深蓝风
layer.open({
type: 1,
area: ['500px', '300px'],
title: '学科试题',
skin: 'layui-layer-examine', //样式类名
closeBtn: 1, //不显示关闭按钮
shadeClose: true, //开启遮罩关闭
anim: 2,
content: html
});
})
cardListData.init();
})
function tplNameReplace (num) {
var str = num.value;
var value = str.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g, '');
num.value = value;
}
var locationUrl = window.location.href.substring(0, window.location.href.indexOf('/index.php'));
var baseLocalUrl = locationUrl
let loginStatus = ''
if (!locationUrl.includes('xbas3')) {
baseLocalUrl = 'http://xbas3.testing.xiaoben.com';
loginStatus = '/username/zhangxiuxiu/time/1681456191/sig/1ed6d280e52136f2304dba7a1c10c3c9/sessionid/session_456132ef87c57a8db843b7157feb9eaa'//秀秀
}
// window.baseUrl = 'http://zsyas2.dev.xueping.com/index.php/vue/';
let apiBaseUrl = baseLocalUrl + '/index.php';
window.baseUrl = baseLocalUrl + '/answersheet/';
var cardListData = {
item_collect: false,//是否全学科答题卡
item_collectData: [],//是否全学科答题卡
printParams: {},
examGroupId: '',
isThird: 0,
isHideList: 0,//1显示隐藏列表,0不显示
cardListData: [],//答题卡列表
tplList: [],//模板列表
curCardTplData: {},//当前模板详细信息
isDownLoad: 0,//当前考试是否下载/生成过
isUploadPaper: 0,//当前试卷是否已上传
api: {
getList: baseLocalUrl + '/index.php/third/getTemplateByExamGroupId' + loginStatus,//获取答题卡列表
changeCard: baseLocalUrl + '/index.php/third/changeCard' + loginStatus,
getOnlinePdf: baseLocalUrl + '/index.php/printTools/getOnlinePdf' + loginStatus,
downloadCard: baseLocalUrl + '/index.php/third/downloadStatus' + loginStatus,
// downFileApi:baseLocalUrl+'/third/download'+loginStatus,
reuseCardApi: baseLocalUrl + '/third/multiplex' + loginStatus,
getMyTplList: baseLocalUrl + '/third/tplList' + loginStatus,
hideCard: baseLocalUrl + '/third/hideAnswerCard' + loginStatus,
saveTpl: baseLocalUrl + '/third/saveTemplateByOnline' + loginStatus,
delTpl: baseLocalUrl + '/third/delTpl' + loginStatus,
getCurPosition: baseLocalUrl + '/third/getMultiplex' + loginStatus,
GetOnlineToken: baseLocalUrl + '/print/GetOnlineToken' + loginStatus,
},
init () {
if (this.searchToObject().isThird == 1) {
// 第三方
this.isThird = 1;
this.examGroupId = JSON.parse(localStorage.getItem('testFormData')).examGroupId
} else {
//知心慧学
this.isThird = 0;
this.examGroupId = this.searchToObject().examGroupId
}
this.getCardList();
},
getCardList () {
// 获取答题卡列表
let that = this;
$.ajax({
url: that.api.getList,
method: 'POST',
data: {
examGroupId: this.examGroupId,
isHide: this.isHideList
},
success: function (data) {
that.item_collect = JSON.parse(data).item_collect ? true : false;
if (that.item_collect) {
that.item_collectData = JSON.parse(data).item_collect;
}
if (JSON.parse(data).success === 1) {
// let list = JSON.parse(data).multiplex;
// let carData = JSON.parse(data)
that.cardListData = JSON.parse(data).multiplex || [];
that.isOnlinePrint = JSON.parse(data).isOnlinePrint;
cardListData.assist_status = JSON.parse(data).data && JSON.parse(data).data.assist_status
//当前考试是否被下载过
that.isDownLoad = JSON.parse(data).data && JSON.parse(data).data.is_download;
that.isUploadPaper = JSON.parse(data).data && JSON.parse(data).data.paper_uploaded;
that.getOnlinePdf()
$('#cardListLength').html(that.cardListData.length);
if (that.cardListData.length == 0 && that.isHideList == 0) {
$('.create-card').show();
$('.cardinfo-box,#tplListModule').hide();
} else {
$('.create-card').hide();
$('.cardinfo-box,#tplListModule').show();
}
if ((that.isDownLoad == 0 || !that.isDownLoad) && that.isHideList == 0) {
that.getMyTpl();
$('#myModule').show();
} else {
$('#myModule').hide();
}
let html = '';
that.cardListData.forEach((val, idx) => {
// 创建列表
html += '\
'+ val.name + ' | \
'+ that.timestampToTime(val.update_time) + ' | \
应用 | \
';
if (that.isHideList == 0) {
if (val.is_download == 0) {
html += '编辑'
} else {
html += '查看\
复用'
}
if (val.is_qrcode_online != 1) { // 没有二维码
html += '下载'
if ((typeof evaluationClient != "undefined") && ('BulkPrintPDF' in evaluationClient)) {
html += '打印'
}
}
if (that.isThird == 1) {
html += '保存为我的模板'
}
}
if (val.is_download != 0) {
html += '' + (that.isHideList == 1 ? '显示' : '隐藏') + ''
}
html += ' | \
';
if (val.active == 1) {
that.getCurPositionData(val.multiplex_id, 1)
}
})
$('#cardListTable tbody').html(html)
$('#cardListTable tbody input[data-active="1"]').prop('checked', true)
if (that.isHideList) {
$('.card-use').prop('disabled', true)
}
} else {
if (JSON.parse(data).message) {
layer.msg(JSON.parse(data).message);
}
}
}
})
},
getOnlinePdf () {
let that = this;
$.ajax({
url: this.api.getOnlinePdf,
method: 'POST',
data: {
examGroupId: cardListData.examGroupId
},
success: function (data) {
if (JSON.parse(data).success === 1) {
cardListData.printParams = JSON.parse(data).data
if (!('studentIds' in cardListData.printParams.params)) {
cardListData.printParams.params.studentIds = []
}
}
}
})
},
changeCardFun (id) {
let that = this;
$.ajax({
url: this.api.changeCard,
method: 'POST',
data: {
multiplexId: id
},
success: function (data) {
layer.msg(JSON.parse(data).msg)
that.getCurPositionData(id, 1)
}
})
},
downloadCardFun (id) {
let that = this;
$.ajax({
url: this.api.downloadCard,
method: 'POST',
data: {
multiplexId: id
},
success: function (data) {
that.getCardList()
}
})
},
getCurPositionData (id, type, tplTitle, positionTxt) {
// type:1应用 2下载 3 保存我的模板 4查看 5编辑
// tplTitle 保存模板title||编辑isCopy
// positionTxt 存储position对应txt文件
let that = this;
$.ajax({
url: this.api.getCurPosition,
method: 'POST',
data: {
multiplexId: id
},
success: function (data) {
if (JSON.parse(data).status == 0) {
let positionData = JSON.parse(data).data;
if (type == 1) {
that.curCardTplData = positionData;
that.createCurCard();
} else if (type == 2) {
that.downloadCardFun(id);
location.href = baseLocalUrl + '/third/download?url=' + positionData.online_card_pdf + '&title=' + positionData.name
} else if (type == 3) {
let position = JSON.parse(positionData.position)
total_score = position.totalScore;
total_topics = that.calcTotalScore(position.topicListObject).count;
$.ajax({
url: that.api.saveTpl,
method: 'POST',
data: {
title: tplTitle,
total_score,
total_topics,
tpl_data: positionTxt
},
success: function (saveData) {
if (JSON.parse(saveData).success === 1) {
layer.msg('保存答题卡成功');
that.getMyTpl();
} else {
layer.msg(JSON.parse(saveData).message);
}
}
})
} else if (type == 4) {
let cardType = that.isThird == 0 ? 1 : 0
let url = that.useCardTool(cardListData.examGroupId)
// 无Token信息 跳转本地
if (that.item_collect) {
if(positionData.new_answer_sheet_subject==1){
window.location.href = `${url}/subjects13.html?examGroupId=${cardListData.examGroupId}&isPreview=1&multiplexId=${positionData.multiplex_id}`
}else{
window.location.href = `${url}/mixSubjects.html?examGroupId=${cardListData.examGroupId}&isPreview=1&multiplexId=${positionData.multiplex_id}`
}
} else {
window.location.href = `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&isPreview=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}`
}
// window.location.href= `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&isPreview=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}`
// if(cardListData.isThird == 1){
// localStorage.setItem('savePrintInfo',JSON.stringify(positionData))
// }
// window.location.href= '/index.php/online/answersheet?examGroupId='+cardListData.examGroupId+'&&isEdit=1&isPreview=1&cardType='+cardType+'&multiplexId='+positionData.multiplex_id;
} else if (type == 5) {
let cardType = cardListData.isThird == 0 ? 1 : 0
let url = that.useCardTool(cardListData.examGroupId)
if (that.item_collect) {
if(positionData.new_answer_sheet_subject==1){
window.location.href = `${url}/subjects13.html?examGroupId=${cardListData.examGroupId}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
}else{
window.location.href = `${url}/mixSubjects.html?examGroupId=${cardListData.examGroupId}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
}
} else {
window.location.href = `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
}
// window.location.href= `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
// if(cardListData.isThird == 1){
// localStorage.setItem('savePrintInfo',JSON.stringify(positionData))
// }
// window.location.href= '/index.php/online/answersheet?examGroupId='+cardListData.examGroupId+'&isEdit=1&cardType='+cardType+'&multiplexId='+positionData.multiplex_id+'&isCopy='+tplTitle;
}
}
}
})
},
useCardTool (examGroupId) {
let item_collect = this.item_collect;
let url = 'http://xbcard.testing.xiaoben.com'
if (window.location.href.includes('dev.xiaoben.com')) {
url = 'http://xbcard.dev.xiaoben.com'
} else if (window.location.href.includes('schcur.com')) {
url = 'http://xbcard.schcur.com'
}
// let token='731768365816463360'
$.ajax({
url: cardListData.api.GetOnlineToken,
type: 'POST',
dataType: 'json',
async: false,
success: function (res) {
if (res.status == 1 && res.data != undefined) {
let token = res.data;
$.cookie('cardToken', null, { path: '/', domain: url.substring(url.indexOf('card.') + 4) });
$.cookie("cardToken", token, { path: '/', expires: 1, domain: url.substring(url.indexOf('card.') + 4) });
// if(item_collect){
// window.location.href=`${url}mixSubjects.html?examGroupId=${examGroupId}&cardType=1`;
// } else {
// window.location.href=`${url}?examGroupId=${examGroupId}&cardType=1`;
// }
} else {
if (res.msg != undefined) {
layer.msg(res.msg)
} else {
layer.msg('token读取失败');
}
}
}
});
return url;
},
createCurCard () {
let data = this.curCardTplData;
let collectData = this.item_collectData;
$('.card-name').html(data.name)
$('.card-time').html(this.timestampToTime(data.update_time))
let position = JSON.parse(data.position);
// 版式
$('#cardType').html(this.getCardInfo(position).cardTypeHtml)
// 考号
$('#codeType').html(this.getCardInfo(position).codeTypeHtml)
// 装订线
$('#lineType').html(position.cardSetting.hasBindingLine == 1 ? '有' : '无')
let topicListHtml = '';
// 题目信息
if (this.item_collect) {
let totalScore = 0;
let totalCount = 0;
collectData.forEach((it, ind) => {
totalCount += it.topic_count == '2选1' ? 1 : it.topic_count;
totalScore += it.total_score;
topicListHtml += '\
'
topicListHtml += this.numberConvert(ind + 1) + '、' + it.topic_type_name
topicListHtml += '
\
'+ it.topic_basic_name + '
\
'+ it.topic_count + '题
\
共'+ it.total_score + '分
\
'
})
$('#totalScore').html(totalScore)
$('#totalCount').html(totalCount)
$('#cardTopicInfo').html(topicListHtml)
} else {
for (let topicType in position.topicListObject) {
let curTopicItem = position.topicListObject[topicType];
if (!curTopicItem.isQuestionText) {
topicListHtml += '\
'
if (this.isThird == 1) {
topicListHtml += curTopicItem.questionTitleReadonly
} else {
topicListHtml += curTopicItem.bigTopicNum + '、' + PaperAndTopicConfig.topicTypeObj[curTopicItem.questionCreateTypeId] + '题'
}
topicListHtml += '
\
'+ PaperAndTopicConfig.topicTypeObj[curTopicItem.questionCreateTypeId] + '
\
'+ this.calcQuestionsLen(position.topicListObject, topicType).count + '题
\
共'+ this.calcQuestionsLen(position.topicListObject, topicType).score + '分
\
'
}
};
$('#totalScore').html(this.calcTotalScore(position.topicListObject).score)
$('#totalCount').html(this.calcTotalScore(position.topicListObject).count)
$('#cardTopicInfo').html(topicListHtml)
}
if ('batchSettings' in position.cardSetting && position.cardSetting.batchSettings) {
$('#examine').show()
}
},
getCardInfo (position) {
// 版式、考号
let codeTypeHtml = '';
if (position.useQrCode == 1) {
codeTypeHtml = '系统二维码'
} else {
position.cardSetting.examinationNumberType.forEach((val, idx) => {
if (idx > 0) {
codeTypeHtml += '、';
}
if (val == 1) {
codeTypeHtml += '填涂考号'
} else {
codeTypeHtml += '条形码'
}
});
}
let cardTypeHtml = '';
cardTypeHtml += position.paper;
cardTypeHtml += position.cardSetting.direction == 2 ? '-竖版-' : '-横版-';
cardTypeHtml += utilsJs.sectionToChinese(position.cardSetting.column) + '栏'
return {
codeTypeHtml,
cardTypeHtml,
}
},
getMyTpl () {
// 获取我的模板
let that = this;
$.ajax({
url: this.api.getMyTplList,
method: 'GET',
data: {},
success: function (res) {
let result = JSON.parse(res);
if (result.success === 1 && result.thisTpls) {
that.tplList = [];
jQuery.each(result.thisTpls, function (i, item) {
let tpl_data = JSON.parse(item.tpl_data)
let num = parseInt(tpl_data.online_card_version && tpl_data.online_card_version.replace('.', '').replace('.', ''))
if (num >= 310) {
that.tplList.push(item)
}
})
if (that.tplList.length > 0) {
$('#tplListMsg').hide();
} else {
$('#tplListMsg').show()
}
$('#tplLength').html(that.tplList.length)
that.renderTplList(that.tplList)
}
}
})
},
renderTplList (tplList) {
let html = ''
tplList.forEach(value => {
let val = JSON.parse(value.tpl_data)
html += '\
\
\
'+ value.title + '\
\
\
总分:'+ value.total_score + '分\
题量:'+ value.total_topics + '小题\
\
\
其他信息
\
版式:'+ this.getCardInfo(val).cardTypeHtml + '\
考号:'+ this.getCardInfo(val).codeTypeHtml + '\
\
'
})
$('.tplList').html(html)
},
setReuseCard (data) {
// 复用答题卡
let that = this;
$.ajax({
url: this.api.reuseCardApi,
method: 'POST',
data: data,
success: function (data) {
if (JSON.parse(data).status == 1) {
layer.msg(JSON.parse(data).msg);
that.getCardList()
} else {
layer.msg(JSON.parse(data).msg);
}
}
})
},
setHideCard (id, isHide) {
// 隐藏答题卡
let that = this;
$.ajax({
url: this.api.hideCard,
method: 'POST',
data: {
multiplexId: id,
isHide: isHide
},
success: function (data) {
if (JSON.parse(data).status == 1) {
layer.msg('设置成功');
that.getCardList()
} else {
layer.msg(JSON.parse(data).msg);
}
}
})
},
saveAsMyTpl (idx) {
// 保存为我的模板
let that = this;
layer.open({
title: '保存模板',
area: ['350px', '200px'],
content: '模板名称:'
, btn: ['确定', '取消']
, yes: function (index, layero) {
tplTitle = $('#tplName').val();
$('.hgc_inputItem .error')[tplTitle ? 'hide' : 'show']()
if (tplTitle) {
that.getCurPositionData(that.cardListData[idx].multiplex_id, 3, tplTitle, that.cardListData[idx].position)
}
layer.close(index);
}
});
},
calcQuestionsLen: function (buildQuestions, modelId) {
let count = 0, score = 0;
// for(let modelId in buildQuestions){
if (buildQuestions[modelId].questionCreateTypeId == 17) {
count = buildQuestions[modelId].questions[0].total + '选' + buildQuestions[modelId].questions[0].required;
let tempTpLen = 0;
buildQuestions[modelId].questions.forEach((val, i) => {
if (val.smTopicLen === undefined && tempTpLen < buildQuestions[modelId].questions[0].required) {
// 不是小题 && 并且不能超过选择个数
tempTpLen++;
score += parseFloat(buildQuestions[modelId].questions[i].fullScore)
} else if (i < val.smTopicLen) {
score += parseFloat(val.fullScore)
}
});
//
} else {
buildQuestions[modelId].questions.forEach(function (val, index) {
if (val) {
score += parseFloat(val.fullScore)
if (!val.smallQtNo) {
count++;
}
} else {
buildQuestions[modelId].questions.splice(index, 1)
}
})
// count += buildQuestions[modelId].questions.length
}
// }
return { count: count, score: score };
},
calcTotalScore: function (buildQuestions) {
let count = 0, score = 0;
for (let modelId in buildQuestions) {
if (buildQuestions[modelId].questionCreateTypeId == 17) {
count += parseFloat(buildQuestions[modelId].questions[0].required);
let tempTpLen = 0;
buildQuestions[modelId].questions.forEach((val, i) => {
if (val.smTopicLen === undefined && tempTpLen < buildQuestions[modelId].questions[0].required) {
tempTpLen++;
score += parseFloat(buildQuestions[modelId].questions[i].fullScore)
} else if (i < val.smTopicLen) {
score += parseFloat(val.fullScore)
}
});
// score += parseFloat(buildQuestions[modelId].questions[0].fullScore)
} else if (!modelId.includes('Text')) {
buildQuestions[modelId].questions.forEach(function (val, index) {
if (val) {
score += parseFloat(val.fullScore)
if (!val.smallQtNo) {
count++;
}
} else {
buildQuestions[modelId].questions.splice(index, 1)
}
})
// count += buildQuestions[modelId].questions.length
}
}
return { count: count, score: score };
},
searchToObject () {
//location.search 转成 key:value格式
var pairs = window.location.search.substring(1).split("&"),
obj = {},
pair,
i;
for (i in pairs) {
if (pairs[i] === "") continue;
pair = pairs[i].split("=");
obj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return obj;
},
timestampToTime (timestamp) {
var date = new Date(timestamp * 1000);
var Y = date.getFullYear() + '-';
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
var D = date.getDate() + ' ';
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
return Y + this.addZero(M) + this.addZero(D) + this.addZero(h) + ':' + this.addZero(m) + ':' + this.addZero(s);
},
addZero (n) {
return n < 10 ? '0' + n : '' + n
},
// numberConvert(num){
// let chinese = '';
// var arr = [...num.toString()];
// for(var i=0;i= 0; i--) {
Num = Num.replace(",", "")//替换Num中的“,”
Num = Num.replace(" ", "")//替换Num中的空格
}
if (isNaN(Num)) { //验证输入的字符是否为数字
//alert("请检查小写金额是否正确");
return;
}
//字符处理完毕后开始转换,采用前后两部分分别转换
part = String(Num).split(".");
newchar = "";
//小数点前进行转化
for (i = part[0].length - 1; i >= 0; i--) {
if (part[0].length > 10) {
//alert("位数过大,无法计算");
return "";
}//若数量超过拾亿单位,提示
tmpnewchar = ""
perchar = part[0].charAt(i);
switch (perchar) {
case "0": tmpnewchar = "零" + tmpnewchar; break;
case "1": tmpnewchar = "一" + tmpnewchar; break;
case "2": tmpnewchar = "二" + tmpnewchar; break;
case "3": tmpnewchar = "三" + tmpnewchar; break;
case "4": tmpnewchar = "四" + tmpnewchar; break;
case "5": tmpnewchar = "五" + tmpnewchar; break;
case "6": tmpnewchar = "六" + tmpnewchar; break;
case "7": tmpnewchar = "七" + tmpnewchar; break;
case "8": tmpnewchar = "八" + tmpnewchar; break;
case "9": tmpnewchar = "九" + tmpnewchar; break;
}
switch (part[0].length - i - 1) {
case 0: tmpnewchar = tmpnewchar; break;
case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
case 4: tmpnewchar = tmpnewchar + "万"; break;
case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
case 8: tmpnewchar = tmpnewchar + "亿"; break;
case 9: tmpnewchar = tmpnewchar + "十"; break;
}
newchar = tmpnewchar + newchar;
}
//替换所有无用汉字,直到没有此类无用的数字为止
while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search("零万") != -1) {
newchar = newchar.replace("零亿", "亿");
newchar = newchar.replace("亿万", "亿");
newchar = newchar.replace("零万", "万");
newchar = newchar.replace("零零", "零");
}
//替换以“一十”开头的,为“十”
if (newchar.indexOf("一十") == 0) {
newchar = newchar.substr(1);
}
//替换以“零”结尾的,为“”
if (newchar.lastIndexOf("零") == newchar.length - 1) {
newchar = newchar.substr(0, newchar.length - 1);
}
return newchar;
}
}