/**序列化表单,多个value用数组存放**/ $.fn.serializeObject = function() { var o = {}; var arr = this.serializeArray(); $.each(arr,function(){ if (o[this.name]) { //返回json中有该属性 if (!o[this.name].push) { //将已存在的属性值改成数组 o[this.name] = [ o[this.name] ]; } o[this.name].push(this.value || ''); //将值存放到数组中 } else { //返回json中没有有该属性 o[this.name] = this.value || ''; //直接将属性和值放入返回json中 } }); return o; } String.prototype.substitute = function(data) { if (data && typeof data == 'object') { return this.replace(/\{([^{}]+)\}/g, function(match, key) { var value = data[key] return value !== undefined ? '' + value : '' }) } else { return this.toString() } } var isProduction = ~location.href.indexOf('zhixinhuixue') var newBuildBaseUrl = ''; var newBuildBaseUrlObj = { testing:'http://zsyas2nx.testing.xueping.com', dev:'http://zsyas2nx.dev.xueping.com', production:'http://zsyas2nx.zhixinhuixue.com', } if(~location.href.indexOf('zhixinhuixue')){ newBuildBaseUrl = newBuildBaseUrlObj.production }else if(~location.href.indexOf('testing')){ newBuildBaseUrl = newBuildBaseUrlObj.testing }else{ newBuildBaseUrl = newBuildBaseUrlObj.dev } function tplNameReplace(num){ var str=num.value; var value=str.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,''); num.value=value; } $(function(){ $("body").delegate("#btnSubmit[active='true']", "click", function(e) { var classIds = ''; $(".sel-classes[status=1]").children("span").each(function(){ classIds += $(this).attr('classid')+","; }); $('input[name="classIds"]').val(classIds); var classIds = $('input[name=classIds]').val(); var teacherId = $('input[name="teacherId"]').val(); var subjectId = $('input[name=subjectId]').val(); var tpl_title = $('input[name=tpl_title]').val(); if(tpl_title == "" || tpl_title == null){ layer.msg('没有指定模板名称!');return false; } if(subjectId == 0 || subjectId == null){ layer.msg('没有指定题源!');return false; } if(teacherId == '0' || teacherId == null){ $('#choose-error').html('请指定阅卷老师'); layer.msg('没有指定阅卷老师!');return false; }else{ $('#choose-error').html(''); if(classIds == "" || classIds == null){ $('#classIds-error').html('请指定考试班级'); layer.msg('没有指定考试班级!');return false; }else{ $('#classIds-error').html(''); } } if (!$(".ques-type-control label input").is(':checked')) { layer.msg('请选择题型!');return false; } var flag = 0; for(i = 0 ; i0){ flag = 1; if( i==4 &&!TopicType[4][0][0]){ layer.msg('选做题设置有误,题型不能为空!'); return false; } for (j = 0;jcreateUrl('third/createThirdTpl')?>",data,function (data) { var m = JSON.parse(data); if(m.status==1) { //$('#btnSubmit').attr('active','false'); // layer.msg(m.msg); $(".template-box").prepend('
  • '+m.result.layout+''+m.result.select_card_type+'

    '+m.result.title+'

  • '); $("input[name=third_tpl_id]").val(m.result.third_tpl_id); $("._tpl.active").removeClass('active'); $("._tpl").eq(0).addClass('active'); $("#btnCover").removeClass('dn'); layer.msg('保存成功!',{ icon: 1 }); $(".ttd").hide(); $(".bnt_width").addClass('c_bnt_width'); return false; }else{ layer.msg('保存失败',{ icon: 5 }, function(){ $(".ttd").fadeOut(); }); return false; } }); }); $("body").delegate("#btnCover[active='true']", "click", function(e) { var classIds=''; $(".sel-classes[status=1]").children("span").each(function(){ classIds += $(this).attr('classid')+","; }); $('input[name="classIds"]').val(classIds); var classIds = $('input[name=classIds]').val(); var teacherId = $('input[name="teacherId"]').val(); var subjectId = $('input[name=subjectId]').val(); var tpl_title = $('input[name=tpl_title]').val(); if(tpl_title == "" || tpl_title == null){ layer.msg('没有指定模板名称!');return false; } if(subjectId == 0 || subjectId == null){ layer.msg('没有指定题源!');return false; } if(teacherId == '0' || teacherId == null){ $('#choose-error').html('请指定阅卷老师'); layer.msg('没有指定阅卷老师!');return false; }else{ $('#choose-error').html(''); if(classIds == "" || classIds == null){ $('#classIds-error').html('请指定考试班级'); layer.msg('没有指定考试班级!');return false; }else{ $('#classIds-error').html(''); } } if (!$(".ques-type-control label input").is(':checked')) { layer.msg('请选择题型!');return false; } var flag = 0; for(i = 0 ; i0){ flag = 1; if( i==4 &&!TopicType[4][0][0]){ layer.msg('选做题设置有误,题型不能为空!'); return false; } for (j = 0;jcreateUrl('third/updateThirdTpl')?>",data,function (data) { var m = JSON.parse(data); if(m.status==1) { $("._tpl.active").children().find('.size').html(m.result.layout); $("._tpl.active").children().find('.type').html(m.result.select_card_type); $("._tpl.active").children().find('.card-name').html(m.result.title); $("._tpl.active").removeClass('active'); $("._tpl").eq(0).addClass('active'); layer.msg('保存成功!',{ icon: 1 }); $(".ttd").fadeOut(); $("#btnCover").removeClass('dn'); $(".bnt_width").addClass('c_bnt_width'); return false; }else{ layer.msg('保存失败',{ icon: 5 }, function(){ $(".ttd").fadeOut(); }); return false; } }); }); //模版系列 var hgc_DtkTplModule = { tpls:{ tplItemTPl:'
    \
    \

    \ {title}\ \

    \ 总分:{total_score}分\ 题量:{total_topics}小题\
    \
    \

    其他信息

    \ 版式:{format}\ 考号:{examFields}\
    \
    ', dtkBaseInfoTpl:'

    \ 板式:{format}\ 考号:{examFields}\ 装订线:{hasBindline}\ 总分:{total_score}分\ 题量:{total_topics}\

    ', dtkSubjectInfoTpl:'

    \ {bigTitle}{bigTitle}\ {subjectType}\ {questionLength}题\ 共{questionScore}分\

    ', dtkSubjectInfoXZTpl:'

    \ {bigTitle}{bigTitle}\ {subjectType}\ {questionLength}\ 共{questionScore}分\

    ' }, init:function(){ //判断[新创建]是数学还是其他学科(其他学科) this.isMathForNew = !~location.href.indexOf('third/thirdview_duo') //存放模版列表信息 this.tplList = [] this.dtkPosition = {} this.examGroupId = $('input[name="examGroupId"]').val(); this.formatMap = { horizontal:'横版', vertical:'竖版', 1:'一栏', 2:'两栏', 3:'三栏' } this.questionTypes = { 1:'单选', 2:'多选', 11:'不定项选择', 5:'填空', 7:'解答', 17:'选做', '7c':'作文' } this.savePrintInfo = localStorage.getItem('savePrintInfo')!=undefined? JSON.parse(localStorage.getItem('savePrintInfo')):{} let _this = this; this.thirdOnlineUrl = '/index.php/online/third'; let isCardReturn = window.location.href.indexOf('isCardReturn'); // let isCardReturn = document.referrer.indexOf('vue'); if(isCardReturn>-1){ let resData = JSON.parse(localStorage.getItem('upDataThreeCard')); // let resData = JSON.parse(upDataThreeCard); if(resData.savePrintInfo){ localStorage.setItem('savePrintInfo',JSON.stringify(resData.savePrintInfo)); _this.savePrintInfo = resData.savePrintInfo; } // $.post('/print/getOnlineCardTempData',{ // examGroupId:saveFormData.examGroupId, // },function(res){ // res = JSON.parse(res); // let resData = JSON.parse(res.data); // if(resData.savePrintInfo){ // localStorage.setItem('savePrintInfo',JSON.stringify(resData.savePrintInfo)); // _this.savePrintInfo = resData.savePrintInfo; // _this.initDom() // _this.initPage() // _this.getDtkInfo() // } // }) } //提供下载pdf 的唯一标识符 this.downloadPdfIdentifier = '' this.initDom() this.bindEvent() this.initPage() this.getDtkInfo() this.getTplList(); }, initDom:function(){ this.$dtkContentInfo = $('.hgc_leftContent .contentInfo') this.$dtkContentNoInfo = $('.hgc_leftContent .contentNoInfo') }, initPage:function(){ this.initConnectDtkStatus() }, initConnectDtkStatus:function(){ var self = this; //如果不是在线答题卡编辑页面跳转过来,直接清空storage // if(!~document.referrer.indexOf('vue')){ // self.clearStorage() // self.savePrintInfo = {} // } //判断是否有题目信息 var hasSubjectInfo = Object.keys(self.savePrintInfo).length; self.setContentInfoStatus(hasSubjectInfo) //如果进入该页面是关联答题卡页面,直接显示 if(localStorage.getItem('isConnect') === 'block'){ $(".template-flag").trigger('click') } }, setContentInfoStatus:function(hasSubjectInfo){ var self = this; self.$dtkContentInfo[hasSubjectInfo?'show':'hide']() self.$dtkContentNoInfo.css('display',hasSubjectInfo?'none':'flex') }, // setConnectStatus:function(status){ // $('.hgc_leftContent').css('display',status) // localStorage.setItem('isConnect',status) // }, getConnectStatus:function(){ return localStorage.getItem('isConnect') }, //获取当前答题卡信息 getDtkInfo:function(){ var self = this; var dtkInfo = null; //如果有记录的答题卡信息就使用记录的答题卡信息 var storageInfo = self.savePrintInfo; var hasDtkInfo = Object.keys(storageInfo).length //考试id 存在就是编辑考试 if(self.examGroupId && !hasDtkInfo &&hasOnlineCard==1){ $.post('/third/getTemplateByExamGroupId',{examGroupId:self.examGroupId},function(res){ var savePrintInfoObj = {} if(!JSON.parse(res).success){ // self.setConnectStatus('none') self.setContentInfoStatus(false) return; } dtkInfo = JSON.parse(res).data; // dtkInfo = JSON.parse(res).data.position ? JSON.parse(JSON.parse(res).data.position) :{}; // dtkInfo.position = JSON.parse(JSON.stringify(dtkInfo)); self.dtkPosition = dtkInfo; //判断是否是老版在线答题卡 if(!JSON.parse(dtkInfo.position).bigTopicArr){ self.setContentInfoStatus(false) return; } // let timu = { // KeGuanTi:dtkInfo.ke_topic_num, // TianKongTi:dtkInfo.tian_topic_num, // ZhuGuanTi:dtkInfo.zu_topic_num, // XuanZuoTi:dtkInfo.xuan_topic_num // } // let question_info={ // content:[] // } let question_info={ content:dtkInfo.questions } // jQuery.each( dtkInfo.buildQuestions, function( i, val ) { // question_info.content = question_info.content.concat(val.questions) // }); // dtkInfo.buildQuestions savePrintInfoObj = { position:JSON.parse(dtkInfo.position), sheet_answer:dtkInfo.sheet_answer, sheet_score:dtkInfo.sheet_score, timu:dtkInfo.timu, title:dtkInfo.name, question_info:question_info, pdf_url:dtkInfo.online_card_pdf } self.verificationDtkInfo(savePrintInfoObj,dtkInfo.questions) self.savePrintInfo = savePrintInfoObj localStorage.setItem('savePrintInfo',JSON.stringify(savePrintInfoObj)) self.renderDtkInfo(savePrintInfoObj) // self.setConnectStatus('block') self.setContentInfoStatus(true) }) }else{ if(hasDtkInfo){ dtkInfo = storageInfo; self.dtkPosition = dtkInfo.position; //直接把dtkInfo存到 self.renderDtkInfo(dtkInfo) // self.setConnectStatus('block') self.setContentInfoStatus(true) }else{ // self.setConnectStatus('none') self.setContentInfoStatus(false) } } }, verificationDtkInfo:function(data,resData){ var self = this; let topicAll = JSON.parse(JSON.stringify(resData)); // let topicMod = JSON.parse(JSON.stringify(data.position.buildQuestions)); // jQuery.each(topicMod,function (modI,topicModItem){ // topicAll = topicAll.concat(topicModItem.questions) // }) jQuery.each(resData,function (i,item){ jQuery.each(data.question_info.content,function (j,topic){ if(topic.questionNum==item.questionNum){ let isEdit = false; if(topic.fullScore!=item.fullScore){ isEdit = true topic.fullScore=item.fullScore } if(item.questionTypeId == 2){ if(item.ruleScoreHalf != topic.halfScore){ isEdit = true topic.halfScore = item.ruleScoreHalf } } if(isEdit){ self.editDtkInfo(topicAll,topic.topicNo,item) } } }) }) }, editDtkInfo:function(topicAll,topicNo,resDataTtem){ jQuery.each(topicAll,function (idx,topic){ if(topic.topicNo==topicNo){ topic.fullScore=resDataTtem.fullScore if(resDataTtem.questionTypeId == 2){ if(resDataTtem.ruleScoreHalf != topic.halfScore){ topic.halfScore = resDataTtem.ruleScoreHalf } } } }) }, renderDtkInfo:function(dtkInfo){ var self = this; self.downloadPdfIdentifier = dtkInfo.position.identifier self.renderDtkBaseInfo(dtkInfo) self.renderDtkSubjectInfo(dtkInfo.position.bigTopicArr) }, renderDtkBaseInfo:function(dtkInfo){ var self = this; var tpl_data = dtkInfo.position var dtkbaseInfo = self.getOtherInfo(tpl_data) var paperScoreAll = self.getScoreAll(dtkInfo.question_info.content) var calcScoreTimu = self.calcScoreTimu(paperScoreAll,dtkInfo.timu) calcScoreTimu.total_score = tpl_data.cardSetting.examInfoConfig[1].text; var baseInfoHtmls = self.tpls.dtkBaseInfoTpl.substitute({ ...dtkbaseInfo, total_score:calcScoreTimu.total_score, total_topics:calcScoreTimu.total_topics, hasBindline:tpl_data.cardSetting.hasBindingLine?'有':'无' }) $('.hgc_leftContent .module').eq(0).find('.infoItem').eq(0).children('.info').html(baseInfoHtmls) }, getScoreAll:function (data) { let scoreArr = []; let pId = 0; for (let i = 0; i < data.length; i++) { if(data[i].questionTypeId==17){ if(data[i].topicNo!=pId){ scoreArr.push(Number(data[i].fullScore)) pId = data[i].topicNo } }else{ scoreArr.push(Number(data[i].fullScore)) } } return scoreArr }, renderDtkSubjectInfo:function(buildQuestions){ var self = this; var subjectInfoHtml = ''; for(var modelId in buildQuestions){ var buildQuestionItem = buildQuestions[modelId]; var subjectType = ''; if(buildQuestionItem.questionTypeId===77){ subjectType = self.questionTypes['7c']; }else { subjectType = self.questionTypes[buildQuestionItem.questionTypeId]; } var questionLength = buildQuestionItem.questions.length if(buildQuestionItem.questionTypeId ==17){ questionLength = buildQuestionItem.topicConfigureData.topicTypeArr[0].chooseOption+'选1' } var questionScore = buildQuestionItem.questions.reduce(function(totalScore,cur){ // totalScore+=cur.fullScore; totalScore = Number(totalScore)+Number(cur.fullScore) return totalScore },0) if(buildQuestionItem.questionTypeId===17){ questionScore = buildQuestionItem.questions[0].fullScore subjectInfoHtml+=self.tpls.dtkSubjectInfoXZTpl.substitute({ subjectType, questionLength, questionScore, bigTitle:buildQuestionItem.bigTitle }) } else{ subjectInfoHtml+=self.tpls.dtkSubjectInfoTpl.substitute({ subjectType, questionLength, questionScore, bigTitle:buildQuestionItem.bigTitle }) } } $('.hgc_leftContent .module').eq(0).find('.infoItem').eq(1).children('.info').html(subjectInfoHtml) }, //获取模版 getTplList:function(){ var self = this $.get('/index.php/third/tplList',function(res){ var result = JSON.parse(res); if(result.success === 1 && result.thisTpls){ self.tplList = [] jQuery.each(result.thisTpls, function (i, item){ let tpl_data = JSON.parse(item.tpl_data) if(tpl_data.position){ if(tpl_data.position.bigTopicArr){ self.tplList.push(item) } } else { // let errTplMsg = '在线答题卡模板:'+item.title+'(id:'+item.third_tpl_id+')'+'缺少数据,是否删除模板?' // layer.confirm(errTplMsg, {title:'提示'}, function(index){ // self.delTpl(item.third_tpl_id) // layer.close(index); // }); } }) if(self.tplList.length>0){ $('#tplListMsg').hide(); } else{ $('#tplListMsg').show() } self.renderTplList(self.tplList) } }) }, //format examFields getOtherInfo:function(tpl_data){ var self = this; let papers = ['','A3','A4','16K','8Ks','8Kb']; let direction = tpl_data.cardSetting.direction==1?'horizontal':'vertical'; var format = papers[tpl_data.cardSetting.paperSize]+'-'+self.formatMap[direction]+'-'+self.formatMap[tpl_data.cardSetting.column] var examFields = '' if(tpl_data.cardSetting.examinationNumberType.indexOf(1)){ examFields+='条形码' } if(tpl_data.cardSetting.examinationNumberType.indexOf(2)){ examFields+=' 填涂' } return { format:format, examFields:examFields } }, calcScoreTimu:function(sheet_score,timu){ var self = this; var total_topics = 0; var total_score = 0 for(var key in sheet_score){ total_score+=Number(sheet_score[key]) } for(var type in timu){ total_topics+=Number(timu[type]) } if(timu==undefined){ total_topics = sheet_score.length } return { total_topics:total_topics, total_score:total_score } }, renderTplList:function(tpls){ var self = this; // if(!tpls.length)alert('数据不存在'); var htmls = tpls.reduce( function(str,item){ var tpl_data = JSON.parse(item.tpl_data) var otherInfo = self.getOtherInfo(tpl_data.position) item.format = otherInfo.format item.examFields = otherInfo.examFields str += self.tpls.tplItemTPl.substitute(item) return str },'') $('.tplList').html(htmls) $('#tplLength').text(tpls.length) }, bindEvent:function(){ var self = this; // $(".template-flag").click(function(){ // var $rightContent = $(".hgc_leftContent"); // $(".hgc_leftContent").toggle(); // self.setConnectStatus($rightContent.css('display')) // }); $('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','.menuList span',function(e){ var $this = $(this); var type = $(this).attr('class'); var tplId = $(this).attr('data-id') switch(type){ case 'del': self.delTpl(tplId,$this) break; case 'preview': self.previewTpl(tplId); break; case 'use': self.useTpl(tplId); break; } }) //修改答题卡 $('#editMyTpl').click(function(e){ // localStorage.setItem('position',JSON.stringify(self.dtkPosition)) // localStorage.setItem('buildQuestions',JSON.stringify(self.dtkPosition.buildQuestions)) // 修改答题卡 // self.goOnlineCard() if(examStatus){ localStorage.setItem('examStatus',JSON.stringify(examStatus)) } location.href = self.thirdOnlineUrl+'/isEdit=true'; }) //修改新版答题卡 $('#editNewMyTpl').click(function(e){ self.goEditAnswerSheet(); }) //保存模版 $('#saveMyTpl').click(function(){ var tplTitle = '' var {sheet_score,timu,position,question_info} = self.savePrintInfo; var total_topics = 0; var total_score = position.cardSetting.examInfoConfig[1].text; // if(typeof(sheet_score) === 'string'){ // sheet_score = JSON.parse(sheet_score); // } // for(var key in sheet_score){ // total_score+=+sheet_score[key] // } for(var type in timu){ total_topics+=Number(timu[type]) } if(timu==undefined){ total_topics = question_info.content.length } layer.confirm('
    \

    模版名称:

    \

    模版名称不能为空

    \
    ', function(index){ //do something tplTitle = $('#tplName').val(); $('.hgc_inputItem .error')[tplTitle?'hide':'show']() if(tplTitle){ $.ajax({ url: '/third/saveTemplateByOnline', method: 'POST', data:{ title:tplTitle, total_score, total_topics, tpl_data:JSON.stringify(self.savePrintInfo) }, success: function (data) { if(JSON.parse(data).success === 1){ layer.msg('保存答题卡成功'); self.getTplList() } else { layer.msg(JSON.parse(data).message); } } }) } tplTitle && layer.close(index); }); }) var $tplListEl = $('.hgc_leftContent .tplList'); $('.hgc_leftContent .btnItem').click(function(){ var stepNum = $(this).hasClass('leftBtn')?225:-225; var curLeft =Math.abs($tplListEl.position().left); if(stepNum<0 && curLeft<220){ return false } var listW = Math.abs($tplListEl.width()); var boxW = Math.abs($('.relation-answer-card .tplBox').width()); if((curLeft + boxW +stepNum -240)==listW || (curLeft + boxW +stepNum -240)>listW){ return false } $tplListEl.animate({left:-(curLeft+stepNum)},100) }) $('.contentNoInfo .hbtn').click(function(){ self.goOnlineCard() }) $('#goAnswerSheet').click(function(){ self.goNewAnswerSheet() }) //下载pdf $('#downLoadPdfBtn').click(function () { var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {}; //isProduction // var host = isProduction?'//zsyapi.zhixinhuixue.com':'//192.168.1.60:8001' // location.href = host+'/download/'+self.downloadPdfIdentifier // location.href = self.savePrintInfo.pdf_url; location.href = '/third/download?url=' + self.savePrintInfo.pdf_url + '&title=pdf-'+self.savePrintInfo.title+newTestFormData.examGroupId+'.pdf' }) if(!self.examGroupId){ if(self.isMathForNew){ self.createSubmitForMath() }else{ self.createSubmit() } }else{ self.editSubmit() } }, clearStorage:function(){ //清空storage localStorage.removeItem('position') localStorage.removeItem('buildQuestions') localStorage.removeItem('savePrintInfo') localStorage.removeItem('testFormData') localStorage.removeItem('isCardReturn') }, useTpl:function(tplId){ var self = this; var tpl = self.tplList.find(v=>v.third_tpl_id === tplId); var tpl_data = JSON.parse(tpl.tpl_data); var tplTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {}; tpl_data.examGroupId = tplTestFormData.examGroupId; // localStorage.setItem('position',tpl.tpl_data) // localStorage.setItem('buildQuestions',JSON.stringify(JSON.parse(tpl.tpl_data).buildQuestions)) localStorage.setItem('savePrintInfo',JSON.stringify(tpl_data)); this.savePrintInfo = tpl_data; // this.savePrintInfo = JSON.parse(tpl.tpl_data) // self.goOnlineCard() // hgc_DtkTplModule.getDtkInfo() // location.href = self.thirdOnlineUrl; self.goEditAnswerSheet(); }, previewTpl:function(tplId){ var self = this; var tpl = self.tplList.find(v=>v.third_tpl_id === tplId); // localStorage.setItem('previewPosition',tpl.tpl_data); // localStorage.setItem('previewBuildQuestions',JSON.stringify(JSON.parse(tpl.tpl_data).position.buildQuestions)) // // self.goOnlineCard() // localStorage.setItem('grade',grade); // location.href = self.thirdOnlineUrl+'/isPreview=true'; var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {}; newTestFormData.editType = 1; //保存第三方临时数据 let upData={ testFormData:newTestFormData, savePrintInfo:tpl.tpl_data } localStorage.setItem('previewPosition',JSON.stringify(upData)); // $.post('/print/saveOnlineCardTempData',{ // examGroupId:newTestFormData.examGroupId, // text:JSON.stringify(upData) // },function(res){ // console.log(res) // }) // location.href = newBuildBaseUrl+'/#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; location.href = '/vue/index.html#/AnswerSheetPreview?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; }, goOnlineCard:function(){ var self = this; self.isOldTpl(); }, isOldTpl:function (isPreview) { var self = this; var addGrade = 0 $('.grade-sel ul li').each(function(){ if($(this).hasClass('active')){ addGrade = $(this).attr('grade') } }) if(addGrade!=undefined&&addGrade!==0){ var grade = addGrade } else { var grade = $("input[name='grade']").val(); } // var grade = 1; // modifyThirdExam var isEdit = ~location.href.indexOf('modifyThirdExam'); if(isEdit){ if(hasThirdCard==1&&hasOnlineCard==0){ layer.confirm('
    \

    当前考试存在制作模板数据,如果继续使用并保存【在线答题卡】,则会清空制作模板数据,请确认!

    \
    ', function(index){ // $.ajax({ // url: 'index.php/third/clearExamTpl', // method: 'POST', // data:{ // examGroupId:self.examGroupId, // }, // success: function (data) { // if(data.success === 1){ // $('.grade-sel ul li').each(function(){ // if($(this).hasClass('active')){ // grade = $(this).attr('grade') // } // }) localStorage.setItem('grade',grade) location.href = self.thirdOnlineUrl // }else{ // layer.msg(data.info) // } // } // }) }); }else{ // $('.grade-sel ul li').each(function(){ // if($(this).hasClass('active')){ // grade = $(this).attr('grade') // } // }) localStorage.setItem('grade',grade) location.href = self.thirdOnlineUrl } }else{ // $('.grade-sel ul li').each(function(){ // if($(this).hasClass('active')){ // grade = $(this).attr('grade') // } // }) localStorage.setItem('grade',grade) location.href = self.thirdOnlineUrl } }, goNewAnswerSheet:function () { var self = this; var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {}; var hasThirdCard = newTestFormData.hasThirdCard?newTestFormData.hasThirdCard:0; var hasOnlineCard = newTestFormData.hasOnlineCard?newTestFormData.hasOnlineCard:0; newTestFormData.referrerUrl = window.location.href; // var addGrade = 0; // $('.grade-sel ul li').each(function(){ // if($(this).hasClass('active')){ // addGrade = $(this).attr('grade') // } // }) // if(addGrade!=undefined&&addGrade!==0){ // var grade = addGrade // } else { // var grade = $("input[name='grade']").val(); // } // newTestFormData.grade = grade; // 答题卡编辑状态,0新建答题卡,1编辑已保存答题卡 newTestFormData.editType = 0; //保存第三方临时数据 let upData={ testFormData:newTestFormData } localStorage.setItem('upDataThreeCard',JSON.stringify(upData)); // $.post('/print/saveOnlineCardTempData',{ // examGroupId:newTestFormData.examGroupId, // text:JSON.stringify(upData) // },function(res){ // console.log(res) // }) var isEdit = ~location.href.indexOf('modifyThirdExam'); if(isEdit){ if(hasThirdCard==1&&hasOnlineCard==0){ layer.confirm('
    \

    当前考试存在制作模板数据,如果继续使用并保存【在线答题卡】,则会清空制作模板数据,请确认!

    \
    ', function(index){ // location.href = newBuildBaseUrl+'/#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; location.href = '/vue/index.html#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; }); }else{ // location.href = newBuildBaseUrl+'/#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; location.href = '/vue/index.html#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; } }else{ // card_type 答题卡类型 0第三方,1知心慧学 // location.href = newBuildBaseUrl+'/#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; location.href = '/vue/index.html#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; } }, goEditAnswerSheet:function () { var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {}; var editPrintInfo = JSON.parse(localStorage.getItem('savePrintInfo')) || {}; newTestFormData.editType = 1; newTestFormData.pdf_url = editPrintInfo.pdf_url?editPrintInfo.pdf_url:''; newTestFormData.referrerUrl = window.location.href; newTestFormData.referrerUrl = window.location.href; //保存第三方临时数据 let upData={ testFormData:newTestFormData, savePrintInfo:editPrintInfo } localStorage.setItem('upDataThreeCard',JSON.stringify(upData)); // $.post('/print/saveOnlineCardTempData',{ // examGroupId:newTestFormData.examGroupId, // text:JSON.stringify(upData) // },function(res){ // console.log(res) // }) // location.href = newBuildBaseUrl+'/#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; location.href = '/vue/index.html#/AnswerSheet?exam_group_id='+newTestFormData.examGroupId+'&card_type=0'; }, delTpl:function(tplId,$this){ $.post('/third/delTpl',{third_tpl_id:tplId},function(res){ var result = JSON.parse(res); if(result.success === 1 && $this){ $this.closest('.tplItem').remove() $('#tplLength').text(Number($('#tplLength').text() -1)) if(Number($('#tplLength').text())==1){ $('#tplListMsg').hide() } else{ $('#tplListMsg').show() } } }) }, createSubmit:function(){ var self = this; //创建试卷 $("body").delegate("#createThirdCard[active='true']", "click", function(e) { e.preventDefault(); if(localStorage.upDataThreeCard==undefined||localStorage.upDataThreeCard==null){ location.href = '/index.php/third/index' return false } var error=[]; if(error.length == 0){ $("#createThirdCard").attr('active','false'); var data = JSON.parse(localStorage.getItem('testFormData')) || {}; //如果选择关联答题卡的时候 if($('.hgc_leftContent').css('display') === 'block'){ var tplInfo = self.savePrintInfo; for(var key in tplInfo){ var keyInfo = tplInfo[key]; if(typeof keyInfo === 'object'){ if(key === 'pdfTemplate')continue; data[key] = JSON.stringify(keyInfo) }else{ if(key === 'pdfHtml'){ keyInfo = new Blob([keyInfo], { type: 'text/plain;charset=utf-8' }) key = 'pdfTemplate' } data[key] = keyInfo } } } var formData = new FormData() for(var k in data){ if(k === 'pdfTemplate'){ formData.append(k,data[k],'pdfTepmlate.txt') }else{ formData.append(k,data[k]) } } $.ajax({ //'//192.168.1.51/index.php/print/saveCardOnline' + loginStatus, url:"/index.php/third/insertThirdSheet", method: 'POST', processData: false, contentType: false, dataType: 'json', data: formData, success: function (data) { if(data.success === 1){ self.clearStorage() // location.href = data.result; location.href = '/index.php/third/index' }else { layer.msg(data.message); self.clearStorage() setTimeout(function () { location.href = '/index.php/third/index' },3000) } } }) }else{ layer.msg(error.join(',')); $("#createThirdCard").attr('active','true'); } }); }, editSubmit:function(){ var self = this; $("body").delegate("#createThirdCard[active='true']", "click", function(e) { e.preventDefault(); if(localStorage.upDataThreeCard==undefined||localStorage.upDataThreeCard==null){ location.href = '/index.php/third/index' return false } var error = []; if(error.length == 0){ $(this).attr("active","false"); var data = JSON.parse(localStorage.getItem('testFormData')) || {}; if($('.hgc_leftContent').css('display') === 'block'){ var tplInfo = self.savePrintInfo; for(var key in tplInfo){ var keyInfo = tplInfo[key]; if(typeof keyInfo === 'object'){ if(key === 'pdfTemplate')continue; data[key] = JSON.stringify(keyInfo) }else{ if(key === 'pdfHtml'){ keyInfo = new Blob([keyInfo], { type: 'text/plain;charset=utf-8' }) key = 'pdfTemplate' } data[key] = keyInfo } } } var formData = new FormData() for(var k in data){ if(k === 'pdfTemplate'){ formData.append(k,data[k],'pdfTepmlate.txt') }else{ formData.append(k,data[k]) } } $.ajax({ url:"/index.php/third/insertThirdSheet", method: 'POST', processData: false, contentType: false, dataType: 'json', data: formData, success: function (data) { if(data.success === 1){ // location.href = document.referrer location.href = '/index.php/third/index' } else { layer.msg(data.message); setTimeout(function () { location.href = '/index.php/third/index' },3000) } } }) } }); }, createSubmitForMath:function(){ var self = this; $("body").delegate("#createThirdCard[active='true']", "click", function(e) { e.preventDefault(); if(localStorage.upDataThreeCard==undefined||localStorage.upDataThreeCard==null){ location.href = '/index.php/third/index' return false } var error = []; if(error.length == 0){ $(this).attr("active","false"); var data = JSON.parse(localStorage.getItem('testFormData')) || {}; if($('.hgc_leftContent').css('display') === 'block'){ var tplInfo = self.savePrintInfo; for(var key in tplInfo){ var keyInfo = tplInfo[key]; if(typeof keyInfo === 'object'){ if(key === 'pdfTemplate')continue; data[key] = JSON.stringify(keyInfo) }else{ if(key === 'pdfHtml'){ keyInfo = new Blob([keyInfo], { type: 'text/plain;charset=utf-8' }) key = 'pdfTemplate' } data[key] = keyInfo } } } // var saveFormData = JSON.parse(localStorage.getItem('testFormData')); var formData = new FormData() for(var k in data){ if(k === 'pdfTemplate'){ formData.append(k,data[k],'pdfTepmlate.txt') }else{ formData.append(k,data[k]) } } $.ajax({ url:"/index.php/third/insertThirdSheet", method: 'POST', processData: false, contentType: false, dataType: 'json', data: formData, success: function (data) { if(data.success === 1){ location.href = '/index.php/third/index' // alert('试卷创建成') //location.href = document.referrer }else { layer.msg(data.message); setTimeout(function () { location.href = '/index.php/third/index' },3000) } } }) } }); }, } hgc_DtkTplModule.init() })