12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271 |
- /**序列化表单,多个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 ; i<TopicType.length;i++)
- {
- if(TopicType[i].length>0){
- flag = 1;
- if( i==4 &&!TopicType[4][0][0]){
- layer.msg('选做题设置有误,题型不能为空!');
- return false;
- }
- for (j = 0;j<TopicType[i].length;j++){
- if(TopicType[i][j][1]=='' || TopicType[i][j][1]==0)
- {
- layer.msg('题号不能为空!');
- return false;
- }
- }
- }
- }
- if(flag == 0){
- layer.msg('题号不能为空!');
- return false;
- }
- var data={
- tpl_title:tpl_title,
- teacherId:teacherId,
- classIds:classIds,
- subjectId:subjectId,
- textbookId:0,
- topic:JSON.stringify(TopicType),
- layout:$("input[name=layout]:checked").val(),
- select_card_type:$("input[name=select_card_type]:checked").val()
- };
- $.post("<?php echo Yii::app()->createUrl('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('<li class="_tpl" showmsg="1" third_tpl_id="'+m.result.third_tpl_id+'"><a href="#"><div class="card-type"><span class="size">'+m.result.layout+'</span><span class="type">'+m.result.select_card_type+'</span><i class="icon-delete"></i></div> <p class="card-name">'+m.result.title+'</p></a></li>');
- $("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 ; i<TopicType.length;i++)
- {
- if(TopicType[i].length>0){
- flag = 1;
- if( i==4 &&!TopicType[4][0][0]){
- layer.msg('选做题设置有误,题型不能为空!');
- return false;
- }
- for (j = 0;j<TopicType[i].length;j++){
- if(TopicType[i][j][1]=='' || TopicType[i][j][1]==0)
- {
- layer.msg('题号不能为空!');
- return false;
- }
- }
- }
- }
- if(flag == 0){
- layer.msg('题号不能为空!');
- return false;
- }
- var data={
- tpl_title:tpl_title,
- third_tpl_id:$("._tpl.active").attr('third_tpl_id'),
- teacherId:teacherId,
- classIds:classIds,
- subjectId:subjectId,
- textbookId:0,
- topic:JSON.stringify(TopicType),
- layout:$("input[name=layout]:checked").val(),
- select_card_type:$("input[name=select_card_type]:checked").val()
- };
- $.post("<?php echo Yii::app()->createUrl('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:'<div class="tplItem">\
- <div class="top itemModule">\
- <h3>\
- <strong>{title}</strong>\
- <div class="menu">\
- <strong><b></b><b></b><b></b></strong>\
- <i class="triangle"></i>\
- <div class="menuList">\
- <span class="use" data-id="{third_tpl_id}">使用</span>\
- <span class="preview" data-id="{third_tpl_id}">预览</span>\
- <span class="del" data-id="{third_tpl_id}">删除</span>\
- </div>\
- </div>\
- </h3>\
- <span>总分:{total_score}分</span>\
- <span>题量:{total_topics}小题</span>\
- </div>\
- <div class="bottom itemModule">\
- <h3>其他信息</h3>\
- <span>版式:{format}</span>\
- <span>考号:{examFields}</span>\
- </div>\
- </div>',
- dtkBaseInfoTpl:'<p>\
- <span>板式:{format}</span>\
- <span>考号:{examFields}</span>\
- <span>装订线:{hasBindline}</span>\
- <span>总分:{total_score}分</span>\
- <span>题量:{total_topics}</span>\
- </p>',
- dtkSubjectInfoTpl:'<p>\
- <span><strong>{bigTitle}</strong><i>{bigTitle}</i></span>\
- <span>{subjectType}</span>\
- <span>{questionLength}题</span>\
- <span>共{questionScore}分</span>\
- </p>',
- dtkSubjectInfoXZTpl:'<p>\
- <span><strong>{bigTitle}</strong><i>{bigTitle}</i></span>\
- <span>{subjectType}</span>\
- <span>{questionLength}</span>\
- <span>共{questionScore}分</span>\
- </p>'
- },
- 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('<div class="hgc_inputItem">\
- <p><em>模版名称:</em><input type="text" id="tplName" maxlength="20" onkeyup="tplNameReplace(this)" /></p>\
- <p class="error">模版名称不能为空</p>\
- </div>', 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('<div class="hgc_inputItem">\
- <p>当前考试存在制作模板数据,如果继续使用并保存【在线答题卡】,则会清空制作模板数据,请确认!</p>\
- </div>', 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('<div class="hgc_inputItem">\
- <p>当前考试存在制作模板数据,如果继续使用并保存【在线答题卡】,则会清空制作模板数据,请确认!</p>\
- </div>', 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()
- })
|