submit.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. /**序列化表单,多个value用数组存放**/
  2. $.fn.serializeObject = function() {
  3. var o = {};
  4. var arr = this.serializeArray();
  5. $.each(arr,function(){
  6. if (o[this.name]) { //返回json中有该属性
  7. if (!o[this.name].push) { //将已存在的属性值改成数组
  8. o[this.name] = [ o[this.name] ];
  9. }
  10. o[this.name].push(this.value || ''); //将值存放到数组中
  11. } else { //返回json中没有有该属性
  12. o[this.name] = this.value || ''; //直接将属性和值放入返回json中
  13. }
  14. });
  15. return o;
  16. }
  17. String.prototype.substitute = function(data) {
  18. if (data && typeof data == 'object') {
  19. return this.replace(/\{([^{}]+)\}/g, function(match, key) {
  20. var value = data[key]
  21. return value !== undefined ? '' + value : ''
  22. })
  23. } else {
  24. return this.toString()
  25. }
  26. }
  27. var isProduction = ~location.href.indexOf('zhixinhuixue')
  28. $(function(){
  29. $("body").delegate("#btnSubmit[active='true']", "click", function(e) {
  30. var classIds = '';
  31. $(".sel-classes[status=1]").children("span").each(function(){
  32. classIds += $(this).attr('classid')+",";
  33. });
  34. $('input[name="classIds"]').val(classIds);
  35. var classIds = $('input[name=classIds]').val();
  36. var teacherId = $('input[name="teacherId"]').val();
  37. var subjectId = $('input[name=subjectId]').val();
  38. var tpl_title = $('input[name=tpl_title]').val();
  39. if(tpl_title == "" || tpl_title == null){
  40. layer.msg('没有指定模板名称!');return false;
  41. }
  42. if(subjectId == 0 || subjectId == null){
  43. layer.msg('没有指定题源!');return false;
  44. }
  45. if(teacherId == '0' || teacherId == null){
  46. $('#choose-error').html('请指定阅卷老师');
  47. layer.msg('没有指定阅卷老师!');return false;
  48. }else{
  49. $('#choose-error').html('');
  50. if(classIds == "" || classIds == null){
  51. $('#classIds-error').html('请指定考试班级');
  52. layer.msg('没有指定考试班级!');return false;
  53. }else{
  54. $('#classIds-error').html('');
  55. }
  56. }
  57. if (!$(".ques-type-control label input").is(':checked')) {
  58. layer.msg('请选择题型!');return false;
  59. }
  60. var flag = 0;
  61. for(i = 0 ; i<TopicType.length;i++)
  62. {
  63. if(TopicType[i].length>0){
  64. flag = 1;
  65. if( i==4 &&!TopicType[4][0][0]){
  66. layer.msg('选做题设置有误,题型不能为空!');
  67. return false;
  68. }
  69. for (j = 0;j<TopicType[i].length;j++){
  70. if(TopicType[i][j][1]=='' || TopicType[i][j][1]==0)
  71. {
  72. layer.msg('题号不能为空!');
  73. return false;
  74. }
  75. }
  76. }
  77. }
  78. if(flag == 0){
  79. layer.msg('题号不能为空!');
  80. return false;
  81. }
  82. var data={
  83. tpl_title:tpl_title,
  84. teacherId:teacherId,
  85. classIds:classIds,
  86. subjectId:subjectId,
  87. textbookId:0,
  88. topic:JSON.stringify(TopicType),
  89. layout:$("input[name=layout]:checked").val(),
  90. select_card_type:$("input[name=select_card_type]:checked").val()
  91. };
  92. $.post("<?php echo Yii::app()->createUrl('third/createThirdTpl')?>",data,function (data) {
  93. var m = JSON.parse(data);
  94. if(m.status==1)
  95. { //$('#btnSubmit').attr('active','false');
  96. // layer.msg(m.msg);
  97. $(".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>');
  98. $("input[name=third_tpl_id]").val(m.result.third_tpl_id);
  99. $("._tpl.active").removeClass('active');
  100. $("._tpl").eq(0).addClass('active');
  101. $("#btnCover").removeClass('dn');
  102. layer.msg('保存成功!',{
  103. icon: 1
  104. });
  105. $(".ttd").hide();
  106. $(".bnt_width").addClass('c_bnt_width');
  107. return false;
  108. }else{
  109. layer.msg('保存失败',{
  110. icon: 5
  111. }, function(){
  112. $(".ttd").fadeOut();
  113. });
  114. return false;
  115. }
  116. });
  117. });
  118. $("body").delegate("#btnCover[active='true']", "click", function(e) {
  119. var classIds='';
  120. $(".sel-classes[status=1]").children("span").each(function(){
  121. classIds += $(this).attr('classid')+",";
  122. });
  123. $('input[name="classIds"]').val(classIds);
  124. var classIds = $('input[name=classIds]').val();
  125. var teacherId = $('input[name="teacherId"]').val();
  126. var subjectId = $('input[name=subjectId]').val();
  127. var tpl_title = $('input[name=tpl_title]').val();
  128. if(tpl_title == "" || tpl_title == null){
  129. layer.msg('没有指定模板名称!');return false;
  130. }
  131. if(subjectId == 0 || subjectId == null){
  132. layer.msg('没有指定题源!');return false;
  133. }
  134. if(teacherId == '0' || teacherId == null){
  135. $('#choose-error').html('请指定阅卷老师');
  136. layer.msg('没有指定阅卷老师!');return false;
  137. }else{
  138. $('#choose-error').html('');
  139. if(classIds == "" || classIds == null){
  140. $('#classIds-error').html('请指定考试班级');
  141. layer.msg('没有指定考试班级!');return false;
  142. }else{
  143. $('#classIds-error').html('');
  144. }
  145. }
  146. if (!$(".ques-type-control label input").is(':checked')) {
  147. layer.msg('请选择题型!');return false;
  148. }
  149. var flag = 0;
  150. for(i = 0 ; i<TopicType.length;i++)
  151. {
  152. if(TopicType[i].length>0){
  153. flag = 1;
  154. if( i==4 &&!TopicType[4][0][0]){
  155. layer.msg('选做题设置有误,题型不能为空!');
  156. return false;
  157. }
  158. for (j = 0;j<TopicType[i].length;j++){
  159. if(TopicType[i][j][1]=='' || TopicType[i][j][1]==0)
  160. {
  161. layer.msg('题号不能为空!');
  162. return false;
  163. }
  164. }
  165. }
  166. }
  167. if(flag == 0){
  168. layer.msg('题号不能为空!');
  169. return false;
  170. }
  171. var data={
  172. tpl_title:tpl_title,
  173. third_tpl_id:$("._tpl.active").attr('third_tpl_id'),
  174. teacherId:teacherId,
  175. classIds:classIds,
  176. subjectId:subjectId,
  177. textbookId:0,
  178. topic:JSON.stringify(TopicType),
  179. layout:$("input[name=layout]:checked").val(),
  180. select_card_type:$("input[name=select_card_type]:checked").val()
  181. };
  182. $.post("<?php echo Yii::app()->createUrl('third/updateThirdTpl')?>",data,function (data) {
  183. var m = JSON.parse(data);
  184. if(m.status==1)
  185. {
  186. $("._tpl.active").children().find('.size').html(m.result.layout);
  187. $("._tpl.active").children().find('.type').html(m.result.select_card_type);
  188. $("._tpl.active").children().find('.card-name').html(m.result.title);
  189. $("._tpl.active").removeClass('active');
  190. $("._tpl").eq(0).addClass('active');
  191. layer.msg('保存成功!',{
  192. icon: 1
  193. });
  194. $(".ttd").fadeOut();
  195. $("#btnCover").removeClass('dn');
  196. $(".bnt_width").addClass('c_bnt_width');
  197. return false;
  198. }else{
  199. layer.msg('保存失败',{
  200. icon: 5
  201. }, function(){
  202. $(".ttd").fadeOut();
  203. });
  204. return false;
  205. }
  206. });
  207. });
  208. //模版系列
  209. var hgc_DtkTplModule = {
  210. tpls:{
  211. tplItemTPl:'<div class="tplItem">\
  212. <div class="top itemModule">\
  213. <h3>\
  214. <strong>{title}</strong>\
  215. <div class="menu">\
  216. <strong><b></b><b></b><b></b></strong>\
  217. <i class="triangle"></i>\
  218. <div class="menuList">\
  219. <span class="use" data-id="{third_tpl_id}">使用</span>\
  220. <span class="preview" data-id="{third_tpl_id}">预览</span>\
  221. <span class="del" data-id="{third_tpl_id}">删除</span>\
  222. </div>\
  223. </div>\
  224. </h3>\
  225. <span>总分:{total_score}分</span>\
  226. <span>题量:{total_topics}小题</span>\
  227. </div>\
  228. <div class="bottom itemModule">\
  229. <h3>其他信息</h3>\
  230. <span>版式:{format}</span>\
  231. <span>考号:{examFields}</span>\
  232. </div>\
  233. </div>',
  234. dtkBaseInfoTpl:'<p>\
  235. <span>板式:{format}</span>\
  236. <span>考号:{examFields}</span>\
  237. <span>装订线:{hasBindline}</span>\
  238. <span>总分:{total_score}分</span>\
  239. <span>题量:{total_topics}</span>\
  240. </p>',
  241. dtkSubjectInfoTpl:'<p>\
  242. <span><strong>{bigTitle}</strong><i>{bigTitle}</i></span>\
  243. <span>{subjectType}</span>\
  244. <span>{questionLength}题</span>\
  245. <span>共{questionScore}分</span>\
  246. </p>',
  247. dtkSubjectInfoXZTpl:'<p>\
  248. <span><strong>{bigTitle}</strong><i>{bigTitle}</i></span>\
  249. <span>{subjectType}</span>\
  250. <span>{questionLength}</span>\
  251. <span>共{questionScore}分</span>\
  252. </p>'
  253. },
  254. init:function(){
  255. //判断[新创建]是数学还是其他学科(其他学科)
  256. this.isMathForNew = !~location.href.indexOf('third/thirdview_duo')
  257. //存放模版列表信息
  258. this.tplList = []
  259. this.dtkPosition = {}
  260. this.examGroupId = $('input[name="examGroupId"]').val();
  261. this.formatMap = {
  262. horizontal:'横版',
  263. vertical:'竖版',
  264. 1:'一栏',
  265. 2:'两栏',
  266. 3:'三栏'
  267. }
  268. this.questionTypes = {
  269. 1:'单选',
  270. 2:'多选',
  271. 11:'不定项选择',
  272. 5:'填空',
  273. 7:'解答',
  274. 17:'选做',
  275. '7c':'作文'
  276. }
  277. this.thirdOnlineUrl = '/index.php/online/third';
  278. this.savePrintInfo = JSON.parse(localStorage.getItem('savePrintInfo')) || {}
  279. //提供下载pdf 的唯一标识符
  280. this.downloadPdfIdentifier = ''
  281. this.initDom()
  282. this.bindEvent()
  283. this.initPage()
  284. this.getDtkInfo()
  285. this.getTplList();
  286. },
  287. initDom:function(){
  288. this.$dtkContentInfo = $('.hgc_leftContent .contentInfo')
  289. this.$dtkContentNoInfo = $('.hgc_leftContent .contentNoInfo')
  290. },
  291. initPage:function(){
  292. this.initConnectDtkStatus()
  293. },
  294. initConnectDtkStatus:function(){
  295. var self = this;
  296. //如果不是在线答题卡编辑页面跳转过来,直接清空storage
  297. if(!~document.referrer.indexOf('index.php/online/third')){
  298. self.clearStorage()
  299. self.savePrintInfo = {}
  300. }
  301. //判断是否有题目信息
  302. var hasSubjectInfo = Object.keys(self.savePrintInfo).length;
  303. self.setContentInfoStatus(hasSubjectInfo)
  304. //如果进入该页面是关联答题卡页面,直接显示
  305. if(localStorage.getItem('isConnect') === 'block'){
  306. $(".template-flag").trigger('click')
  307. }
  308. },
  309. setContentInfoStatus:function(hasSubjectInfo){
  310. var self = this;
  311. self.$dtkContentInfo[hasSubjectInfo?'show':'hide']()
  312. self.$dtkContentNoInfo.css('display',hasSubjectInfo?'none':'flex')
  313. },
  314. // setConnectStatus:function(status){
  315. // $('.hgc_leftContent').css('display',status)
  316. // localStorage.setItem('isConnect',status)
  317. // },
  318. getConnectStatus:function(){
  319. return localStorage.getItem('isConnect')
  320. },
  321. //获取当前答题卡信息
  322. getDtkInfo:function(){
  323. var self = this;
  324. var dtkInfo = null;
  325. //如果有记录的答题卡信息就使用记录的答题卡信息
  326. var storageInfo = self.savePrintInfo;
  327. var hasDtkInfo = Object.keys(storageInfo).length
  328. //考试id 存在就是编辑考试
  329. if(self.examGroupId && !hasDtkInfo &&hasOnlineCard==1){
  330. $.post('/third/getTemplateByExamGroupId',{examGroupId:self.examGroupId},function(res){
  331. var savePrintInfoObj = {}
  332. if(!JSON.parse(res).success){
  333. // self.setConnectStatus('none')
  334. self.setContentInfoStatus(false)
  335. return;
  336. }
  337. dtkInfo = JSON.parse(res).data.position ? JSON.parse(JSON.parse(res).data.position) :{};
  338. dtkInfo.position = JSON.parse(JSON.stringify(dtkInfo));
  339. let question_info={
  340. content:[]
  341. }
  342. //判断是否是老版在线答题卡
  343. if(dtkInfo.position.bigTopicArr){
  344. question_info.content = JSON.parse(res).data.questions
  345. let timu = {
  346. KeGuanTi:JSON.parse(res).data.ke_topic_num,
  347. TianKongTi:JSON.parse(res).data.tian_topic_num,
  348. ZhuGuanTi:JSON.parse(res).data.zu_topic_num,
  349. XuanZuoTi:JSON.parse(res).data.xuan_topic_num
  350. }
  351. savePrintInfoObj = {
  352. position:dtkInfo.position,
  353. sheet_answer:JSON.parse(res).data.sheet_answer,
  354. sheet_score:JSON.parse(res).data.sheet_score,
  355. timu:timu,
  356. title:JSON.parse(res).data.name,
  357. question_info:question_info,
  358. pdf_url:JSON.parse(res).data.online_card_pdf
  359. }
  360. localStorage.setItem('savePrintInfo',JSON.stringify(savePrintInfoObj))
  361. self.setContentInfoStatus(false)
  362. return;
  363. }
  364. self.dtkPosition = dtkInfo;
  365. jQuery.each( dtkInfo.buildQuestions, function( i, val ) {
  366. question_info.content = question_info.content.concat(val.questions)
  367. });
  368. // dtkInfo.buildQuestions
  369. savePrintInfoObj = {
  370. position:dtkInfo.position,
  371. sheet_answer:dtkInfo.sheet_answer,
  372. sheet_score:dtkInfo.sheet_score,
  373. timu:dtkInfo.timu,
  374. title:dtkInfo.title,
  375. question_info:question_info,
  376. pdf_url:JSON.parse(res).data.online_card_pdf
  377. }
  378. self.verificationDtkInfo(savePrintInfoObj,JSON.parse(res).data.questions)
  379. self.savePrintInfo = savePrintInfoObj
  380. localStorage.setItem('savePrintInfo',JSON.stringify(savePrintInfoObj))
  381. self.renderDtkInfo(savePrintInfoObj)
  382. // self.setConnectStatus('block')
  383. self.setContentInfoStatus(true)
  384. })
  385. }else{
  386. if(hasDtkInfo){
  387. dtkInfo = storageInfo;
  388. self.dtkPosition = dtkInfo.position;
  389. //直接把dtkInfo存到
  390. self.renderDtkInfo(dtkInfo)
  391. // self.setConnectStatus('block')
  392. self.setContentInfoStatus(true)
  393. }else{
  394. // self.setConnectStatus('none')
  395. self.setContentInfoStatus(false)
  396. }
  397. }
  398. },
  399. verificationDtkInfo:function(data,resData){
  400. var self = this;
  401. let topicAll = [];
  402. let topicMod = JSON.parse(JSON.stringify(data.position.buildQuestions));
  403. jQuery.each(topicMod,function (modI,topicModItem){
  404. topicAll = topicAll.concat(topicModItem.questions)
  405. })
  406. jQuery.each(resData,function (i,item){
  407. jQuery.each(data.question_info.content,function (j,topic){
  408. if(topic.questionNum==item.questionNum){
  409. let isEdit = false;
  410. if(topic.fullScore!=item.fullScore){
  411. isEdit = true
  412. topic.fullScore=item.fullScore
  413. }
  414. if(item.questionTypeId == 2){
  415. if(item.ruleScoreHalf != topic.halfScore){
  416. isEdit = true
  417. topic.halfScore = item.ruleScoreHalf
  418. }
  419. }
  420. if(isEdit){
  421. self.editDtkInfo(topicAll,topic.topicNo,item)
  422. }
  423. }
  424. })
  425. })
  426. },
  427. editDtkInfo:function(topicAll,topicNo,resDataTtem){
  428. jQuery.each(topicAll,function (idx,topic){
  429. if(topic.topicNo==topicNo){
  430. topic.fullScore=resDataTtem.fullScore
  431. if(resDataTtem.questionTypeId == 2){
  432. if(resDataTtem.ruleScoreHalf != topic.halfScore){
  433. topic.halfScore = resDataTtem.ruleScoreHalf
  434. }
  435. }
  436. }
  437. })
  438. },
  439. renderDtkInfo:function(dtkInfo){
  440. var self = this;
  441. self.downloadPdfIdentifier = dtkInfo.position.identifier
  442. self.renderDtkBaseInfo(dtkInfo)
  443. self.renderDtkSubjectInfo(dtkInfo.position.buildQuestions)
  444. },
  445. renderDtkBaseInfo:function(dtkInfo){
  446. var self = this;
  447. var tpl_data = dtkInfo.position
  448. var dtkbaseInfo = self.getOtherInfo(tpl_data)
  449. var paperScoreAll = self.getScoreAll(dtkInfo.question_info.content)
  450. var calcScoreTimu = self.calcScoreTimu(paperScoreAll,dtkInfo.timu)
  451. var baseInfoHtmls = self.tpls.dtkBaseInfoTpl.substitute({
  452. ...dtkbaseInfo,
  453. total_score:calcScoreTimu.total_score,
  454. total_topics:calcScoreTimu.total_topics,
  455. hasBindline:tpl_data.hasBindingLine?'有':'无'
  456. })
  457. $('.hgc_leftContent .module').eq(0).find('.infoItem').eq(0).children('.info').html(baseInfoHtmls)
  458. },
  459. getScoreAll:function (data) {
  460. let scoreArr = [];
  461. let pId = 0;
  462. for (let i = 0; i < data.length; i++) {
  463. if(data[i].questionTypeId==17){
  464. if(data[i].topicNo!=pId){
  465. scoreArr.push(Number(data[i].fullScore))
  466. pId = data[i].topicNo
  467. }
  468. }else{
  469. scoreArr.push(Number(data[i].fullScore))
  470. }
  471. }
  472. return scoreArr
  473. },
  474. renderDtkSubjectInfo:function(buildQuestions){
  475. var self = this;
  476. var subjectInfoHtml = '';
  477. for(var modelId in buildQuestions){
  478. var buildQuestionItem = buildQuestions[modelId];
  479. var subjectType = '';
  480. if(buildQuestionItem.questionType===7){
  481. subjectType = self.questionTypes[buildQuestionItem.markQuestionType];
  482. }else {
  483. subjectType = self.questionTypes[buildQuestionItem.questionType];
  484. }
  485. var questionLength = buildQuestionItem.questions.length
  486. if(buildQuestionItem.questionType ==17){
  487. questionLength = buildQuestionItem.commonFields.ChooseNum+'选1'
  488. }
  489. var questionScore = buildQuestionItem.questions.reduce(function(totalScore,cur){
  490. // totalScore+=cur.fullScore;
  491. totalScore = Number(totalScore)+Number(cur.fullScore)
  492. return totalScore
  493. },0)
  494. if(buildQuestionItem.questionType===17){
  495. questionScore = buildQuestionItem.questions[0].fullScore
  496. subjectInfoHtml+=self.tpls.dtkSubjectInfoXZTpl.substitute({
  497. subjectType,
  498. questionLength,
  499. questionScore,
  500. bigTitle:buildQuestionItem.bigTitle
  501. })
  502. } else{
  503. subjectInfoHtml+=self.tpls.dtkSubjectInfoTpl.substitute({
  504. subjectType,
  505. questionLength,
  506. questionScore,
  507. bigTitle:buildQuestionItem.bigTitle
  508. })
  509. }
  510. }
  511. $('.hgc_leftContent .module').eq(0).find('.infoItem').eq(1).children('.info').html(subjectInfoHtml)
  512. },
  513. //获取模版
  514. getTplList:function(){
  515. var self = this
  516. $.get('/index.php/third/tplList',function(res){
  517. var result = JSON.parse(res);
  518. if(result.success === 1 && result.thisTpls){
  519. self.tplList = []
  520. jQuery.each(result.thisTpls, function (i, item){
  521. let tpl_data = JSON.parse(item.tpl_data)
  522. if(tpl_data.position){
  523. if(!tpl_data.position.bigTopicArr){
  524. self.tplList.push(item)
  525. }
  526. } else {
  527. // let errTplMsg = '在线答题卡模板:'+item.title+'(id:'+item.third_tpl_id+')'+'缺少数据,是否删除模板?'
  528. // layer.confirm(errTplMsg, {title:'提示'}, function(index){
  529. // self.delTpl(item.third_tpl_id)
  530. // layer.close(index);
  531. // });
  532. }
  533. })
  534. if(self.tplList.length>0){
  535. $('#tplListMsg').hide();
  536. } else{
  537. $('#tplListMsg').show()
  538. }
  539. self.renderTplList(self.tplList)
  540. }
  541. })
  542. },
  543. //format examFields
  544. getOtherInfo:function(tpl_data){
  545. var self = this;
  546. var format = tpl_data.paper+'-'+self.formatMap[tpl_data.direction]+'-'+self.formatMap[tpl_data.columns]
  547. var examFields = ''
  548. if(tpl_data.examNumberConfig.barCode){
  549. examFields+='条形码'
  550. }
  551. if(tpl_data.examNumberConfig.ticketNumber){
  552. examFields+=' 填涂'
  553. }
  554. return {
  555. format:format,
  556. examFields:examFields
  557. }
  558. },
  559. calcScoreTimu:function(sheet_score,timu){
  560. var self = this;
  561. var total_topics = 0;
  562. var total_score = 0
  563. for(var key in sheet_score){
  564. total_score+=Number(sheet_score[key])
  565. }
  566. for(var type in timu){
  567. total_topics+=Number(timu[type])
  568. }
  569. return {
  570. total_topics:total_topics,
  571. total_score:total_score
  572. }
  573. },
  574. renderTplList:function(tpls){
  575. var self = this;
  576. // if(!tpls.length)alert('数据不存在');
  577. var htmls = tpls.reduce( function(str,item){
  578. var tpl_data = JSON.parse(item.tpl_data)
  579. var otherInfo = self.getOtherInfo(tpl_data.position)
  580. item.format = otherInfo.format
  581. item.examFields = otherInfo.examFields
  582. str += self.tpls.tplItemTPl.substitute(item)
  583. return str
  584. },'')
  585. $('.tplList').html(htmls)
  586. $('#tplLength').text(tpls.length)
  587. },
  588. bindEvent:function(){
  589. var self = this;
  590. // $(".template-flag").click(function(){
  591. // var $rightContent = $(".hgc_leftContent");
  592. // $(".hgc_leftContent").toggle();
  593. // self.setConnectStatus($rightContent.css('display'))
  594. // });
  595. $('body').on('click','.menu',function(e){
  596. e.stopPropagation()
  597. $(this).children('.triangle').css('display','flex')
  598. $(this).children('.menuList').css('display','flex')
  599. })
  600. $(document).click(function(){
  601. $('.menu').children('.triangle').css('display','none')
  602. $('.menu').children('.menuList').css('display','none')
  603. })
  604. $('body').on('click','.menuList span',function(e){
  605. var $this = $(this);
  606. var type = $(this).attr('class');
  607. var tplId = $(this).attr('data-id')
  608. switch(type){
  609. case 'del':
  610. self.delTpl(tplId,$this)
  611. break;
  612. case 'preview':
  613. self.previewTpl(tplId);
  614. break;
  615. case 'use':
  616. self.useTpl(tplId);
  617. break;
  618. }
  619. })
  620. //修改答题卡
  621. $('#editMyTpl').click(function(e){
  622. // localStorage.setItem('position',JSON.stringify(self.dtkPosition))
  623. // localStorage.setItem('buildQuestions',JSON.stringify(self.dtkPosition.buildQuestions))
  624. // 修改答题卡
  625. // self.goOnlineCard()
  626. if(examStatus){
  627. localStorage.setItem('examStatus',JSON.stringify(examStatus))
  628. }
  629. location.href = self.thirdOnlineUrl+'/isEdit=true';
  630. })
  631. //保存模版
  632. $('#saveMyTpl').click(function(){
  633. var tplTitle = ''
  634. var {sheet_score,timu,position} = self.savePrintInfo;
  635. var total_topics = 0;
  636. var total_score = 0
  637. for(var key in sheet_score){
  638. total_score+=+sheet_score[key]
  639. }
  640. for(var type in timu){
  641. total_topics+=timu[type]
  642. }
  643. layer.confirm('<div class="hgc_inputItem">\
  644. <p><em>模版名称:</em><input type="text" id="tplName" /></p>\
  645. <p class="error">模版名称不能为空</p>\
  646. </div>', function(index){
  647. //do something
  648. tplTitle = $('#tplName').val()
  649. $('.hgc_inputItem .error')[tplTitle?'hide':'show']()
  650. if(tplTitle){
  651. $.ajax({
  652. url: '/third/saveTemplateByOnline',
  653. method: 'POST',
  654. data:{
  655. title:tplTitle,
  656. total_score,
  657. total_topics,
  658. tpl_data:JSON.stringify(self.savePrintInfo)
  659. },
  660. success: function (data) {
  661. if(JSON.parse(data).success === 1){
  662. layer.msg('保存答题卡成功');
  663. self.getTplList()
  664. } else {
  665. layer.msg(JSON.parse(data).message);
  666. }
  667. }
  668. })
  669. }
  670. tplTitle && layer.close(index);
  671. });
  672. })
  673. var $tplListEl = $('.hgc_leftContent .tplList');
  674. $('.hgc_leftContent .btnItem').click(function(){
  675. var stepNum = $(this).hasClass('leftBtn')?225:-225;
  676. var curLeft =Math.abs($tplListEl.position().left);
  677. if(stepNum<0 && curLeft<220){
  678. return false
  679. }
  680. var listW = Math.abs($tplListEl.width());
  681. var boxW = Math.abs($('.relation-answer-card .tplBox').width());
  682. if((curLeft + boxW +stepNum -240)==listW || (curLeft + boxW +stepNum -240)>listW){
  683. return false
  684. }
  685. $tplListEl.animate({left:-(curLeft+stepNum)},100)
  686. })
  687. $('.contentNoInfo .hbtn').click(function(){
  688. self.goOnlineCard()
  689. })
  690. //下载pdf
  691. $('#downLoadPdfBtn').click(function () {
  692. //isProduction
  693. // var host = isProduction?'//zsyapi.zhixinhuixue.com':'//192.168.1.60:8001'
  694. // location.href = host+'/download/'+self.downloadPdfIdentifier
  695. // location.href = self.savePrintInfo.pdf_url;
  696. location.href = '/third/download?url=' + self.savePrintInfo.pdf_url + '&title=pdf-'+self.examGroupId+'.pdf'
  697. })
  698. if(!self.examGroupId){
  699. if(self.isMathForNew){
  700. self.createSubmitForMath()
  701. }else{
  702. self.createSubmit()
  703. }
  704. }else{
  705. self.editSubmit()
  706. }
  707. },
  708. clearStorage:function(){
  709. //清空storage
  710. localStorage.removeItem('position')
  711. localStorage.removeItem('buildQuestions')
  712. localStorage.removeItem('savePrintInfo')
  713. localStorage.removeItem('testFormData')
  714. localStorage.removeItem('isCardReturn')
  715. localStorage.removeItem('upDataThreeCard')
  716. },
  717. useTpl:function(tplId){
  718. var self = this;
  719. var tpl = self.tplList.find(v=>v.third_tpl_id === tplId);
  720. // localStorage.setItem('position',tpl.tpl_data)
  721. // localStorage.setItem('buildQuestions',JSON.stringify(JSON.parse(tpl.tpl_data).buildQuestions))
  722. localStorage.setItem('savePrintInfo',JSON.stringify(JSON.parse(tpl.tpl_data)))
  723. // this.savePrintInfo = JSON.parse(tpl.tpl_data)
  724. // self.goOnlineCard()
  725. // hgc_DtkTplModule.getDtkInfo()
  726. location.href = self.thirdOnlineUrl;
  727. },
  728. previewTpl:function(tplId){
  729. var self = this;
  730. var tpl = self.tplList.find(v=>v.third_tpl_id === tplId);
  731. localStorage.setItem('previewPosition',tpl.tpl_data)
  732. localStorage.setItem('previewBuildQuestions',JSON.stringify(JSON.parse(tpl.tpl_data).position.buildQuestions))
  733. // self.goOnlineCard()
  734. localStorage.setItem('grade',grade);
  735. location.href = self.thirdOnlineUrl+'/isPreview=true';
  736. },
  737. goOnlineCard:function(){
  738. var self = this;
  739. self.isOldTpl();
  740. },
  741. isOldTpl:function (isPreview) {
  742. var self = this;
  743. var addGrade = 0
  744. $('.grade-sel ul li').each(function(){
  745. if($(this).hasClass('active')){
  746. addGrade = $(this).attr('grade')
  747. }
  748. })
  749. if(addGrade!=undefined&&addGrade!==0){
  750. var grade = addGrade
  751. } else {
  752. var grade = $("input[name='grade']").val();
  753. }
  754. // var grade = 1;
  755. // modifyThirdExam
  756. var isEdit = ~location.href.indexOf('modifyThirdExam');
  757. if(isEdit){
  758. if(hasThirdCard==1&&hasOnlineCard==0){
  759. layer.confirm('<div class="hgc_inputItem">\
  760. <p>当前考试存在制作模板数据,如果继续使用并保存【在线答题卡】,则会清空制作模板数据,请确认!</p>\
  761. </div>', function(index){
  762. // $.ajax({
  763. // url: 'index.php/third/clearExamTpl',
  764. // method: 'POST',
  765. // data:{
  766. // examGroupId:self.examGroupId,
  767. // },
  768. // success: function (data) {
  769. // if(data.success === 1){
  770. // $('.grade-sel ul li').each(function(){
  771. // if($(this).hasClass('active')){
  772. // grade = $(this).attr('grade')
  773. // }
  774. // })
  775. localStorage.setItem('grade',grade)
  776. location.href = self.thirdOnlineUrl
  777. // }else{
  778. // layer.msg(data.info)
  779. // }
  780. // }
  781. // })
  782. });
  783. }else{
  784. // $('.grade-sel ul li').each(function(){
  785. // if($(this).hasClass('active')){
  786. // grade = $(this).attr('grade')
  787. // }
  788. // })
  789. localStorage.setItem('grade',grade)
  790. location.href = self.thirdOnlineUrl
  791. }
  792. }else{
  793. // $('.grade-sel ul li').each(function(){
  794. // if($(this).hasClass('active')){
  795. // grade = $(this).attr('grade')
  796. // }
  797. // })
  798. localStorage.setItem('grade',grade)
  799. location.href = self.thirdOnlineUrl
  800. }
  801. },
  802. delTpl:function(tplId,$this){
  803. $.post('/third/delTpl',{third_tpl_id:tplId},function(res){
  804. var result = JSON.parse(res);
  805. if(result.success === 1 && $this){
  806. $this.closest('.tplItem').remove()
  807. $('#tplLength').text(Number($('#tplLength').text() -1))
  808. if(Number($('#tplLength').text())==1){
  809. $('#tplListMsg').hide()
  810. } else{
  811. $('#tplListMsg').show()
  812. }
  813. }
  814. })
  815. },
  816. createSubmit:function(){
  817. var self = this;
  818. //创建试卷
  819. $("body").delegate("#createThirdCard[active='true']", "click", function(e) {
  820. e.preventDefault();
  821. if(localStorage.savePrintInfo==undefined){
  822. location.href = '/index.php/third/index'
  823. }
  824. var error=[];
  825. if(error.length == 0){
  826. $("#createThirdCard").attr('active','false');
  827. var data = JSON.parse(localStorage.getItem('testFormData')) || {};
  828. //如果选择关联答题卡的时候
  829. if($('.hgc_leftContent').css('display') === 'block'){
  830. var tplInfo = self.savePrintInfo;
  831. for(var key in tplInfo){
  832. var keyInfo = tplInfo[key];
  833. if(typeof keyInfo === 'object'){
  834. if(key === 'pdfTemplate')continue;
  835. data[key] = JSON.stringify(keyInfo)
  836. }else{
  837. if(key === 'pdfHtml'){
  838. keyInfo = new Blob([keyInfo], {
  839. type: 'text/plain;charset=utf-8'
  840. })
  841. key = 'pdfTemplate'
  842. }
  843. data[key] = keyInfo
  844. }
  845. }
  846. }
  847. var formData = new FormData()
  848. for(var k in data){
  849. if(k === 'pdfTemplate'){
  850. formData.append(k,data[k],'pdfTepmlate.txt')
  851. }else{
  852. formData.append(k,data[k])
  853. }
  854. }
  855. $.ajax({
  856. //'//192.168.1.51/index.php/print/saveCardOnline' + loginStatus,
  857. url:"/index.php/third/insertThirdSheet",
  858. method: 'POST',
  859. processData: false,
  860. contentType: false,
  861. dataType: 'json',
  862. data: formData,
  863. success: function (data) {
  864. if(data.success === 1){
  865. self.clearStorage()
  866. // location.href = data.result;
  867. location.href = '/index.php/third/index'
  868. }else {
  869. layer.msg(data.message);
  870. self.clearStorage()
  871. setTimeout(function () {
  872. location.href = '/index.php/third/index'
  873. },3000)
  874. }
  875. }
  876. })
  877. }else{
  878. layer.msg(error.join(','));
  879. $("#createThirdCard").attr('active','true');
  880. }
  881. });
  882. },
  883. editSubmit:function(){
  884. var self = this;
  885. $("body").delegate("#createThirdCard[active='true']", "click", function(e) {
  886. e.preventDefault();
  887. if(localStorage.savePrintInfo==undefined){
  888. location.href = '/index.php/third/index'
  889. }
  890. var error = [];
  891. if(error.length == 0){
  892. $(this).attr("active","false");
  893. var data = JSON.parse(localStorage.getItem('testFormData')) || {};
  894. if($('.hgc_leftContent').css('display') === 'block'){
  895. var tplInfo = self.savePrintInfo;
  896. for(var key in tplInfo){
  897. var keyInfo = tplInfo[key];
  898. if(typeof keyInfo === 'object'){
  899. if(key === 'pdfTemplate')continue;
  900. data[key] = JSON.stringify(keyInfo)
  901. }else{
  902. if(key === 'pdfHtml'){
  903. keyInfo = new Blob([keyInfo], {
  904. type: 'text/plain;charset=utf-8'
  905. })
  906. key = 'pdfTemplate'
  907. }
  908. data[key] = keyInfo
  909. }
  910. }
  911. }
  912. var formData = new FormData()
  913. for(var k in data){
  914. if(k === 'pdfTemplate'){
  915. formData.append(k,data[k],'pdfTepmlate.txt')
  916. }else{
  917. formData.append(k,data[k])
  918. }
  919. }
  920. $.ajax({
  921. url:"/index.php/third/insertThirdSheet",
  922. method: 'POST',
  923. processData: false,
  924. contentType: false,
  925. dataType: 'json',
  926. data: formData,
  927. success: function (data) {
  928. if(data.success === 1){
  929. // location.href = document.referrer
  930. location.href = '/index.php/third/index'
  931. } else {
  932. layer.msg(data.message);
  933. setTimeout(function () {
  934. location.href = '/index.php/third/index'
  935. },3000)
  936. }
  937. }
  938. })
  939. }
  940. });
  941. },
  942. createSubmitForMath:function(){
  943. var self = this;
  944. $("body").delegate("#createThirdCard[active='true']", "click", function(e) {
  945. e.preventDefault();
  946. if(localStorage.savePrintInfo==undefined){
  947. location.href = '/index.php/third/index'
  948. }
  949. var error = [];
  950. if(error.length == 0){
  951. $(this).attr("active","false");
  952. var data = JSON.parse(localStorage.getItem('testFormData')) || {};
  953. if($('.hgc_leftContent').css('display') === 'block'){
  954. var tplInfo = self.savePrintInfo;
  955. for(var key in tplInfo){
  956. var keyInfo = tplInfo[key];
  957. if(typeof keyInfo === 'object'){
  958. if(key === 'pdfTemplate')continue;
  959. data[key] = JSON.stringify(keyInfo)
  960. }else{
  961. if(key === 'pdfHtml'){
  962. keyInfo = new Blob([keyInfo], {
  963. type: 'text/plain;charset=utf-8'
  964. })
  965. key = 'pdfTemplate'
  966. }
  967. data[key] = keyInfo
  968. }
  969. }
  970. }
  971. // var saveFormData = JSON.parse(localStorage.getItem('testFormData'));
  972. var formData = new FormData()
  973. for(var k in data){
  974. if(k === 'pdfTemplate'){
  975. formData.append(k,data[k],'pdfTepmlate.txt')
  976. }else{
  977. formData.append(k,data[k])
  978. }
  979. }
  980. $.ajax({
  981. url:"/index.php/third/insertThirdSheet",
  982. method: 'POST',
  983. processData: false,
  984. contentType: false,
  985. dataType: 'json',
  986. data: formData,
  987. success: function (data) {
  988. if(data.success === 1){
  989. location.href = '/index.php/third/index'
  990. // alert('试卷创建成')
  991. //location.href = document.referrer
  992. }else {
  993. layer.msg(data.message);
  994. setTimeout(function () {
  995. location.href = '/index.php/third/index'
  996. },3000)
  997. }
  998. }
  999. })
  1000. }
  1001. });
  1002. },
  1003. }
  1004. hgc_DtkTplModule.init()
  1005. })