submitNewThree.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /**序列化表单,多个value用数组存放**/
  2. String.prototype.substitute = function(data) {
  3. if (data && typeof data == 'object') {
  4. return this.replace(/\{([^{}]+)\}/g, function(match, key) {
  5. var value = data[key]
  6. return value !== undefined ? '' + value : ''
  7. })
  8. } else {
  9. return this.toString()
  10. }
  11. }
  12. function tplNameReplace(num){
  13. var str=num.value;
  14. var value=str.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g,'');
  15. num.value=value;
  16. }
  17. $(function(){
  18. //模版系列
  19. var hgc_DtkTplModule = {
  20. tpls:{
  21. tplItemTPl:'<div class="tplItem">\
  22. <div class="top itemModule">\
  23. <h3>\
  24. <strong>{title}</strong>\
  25. <div class="menu">\
  26. <strong><b></b><b></b><b></b></strong>\
  27. <i class="triangle"></i>\
  28. <div class="menuList">\
  29. <span class="use" data-id="{third_tpl_id}">使用</span>\
  30. <span class="preview" data-id="{third_tpl_id}">预览</span>\
  31. <span class="del" data-id="{third_tpl_id}">删除</span>\
  32. </div>\
  33. </div>\
  34. </h3>\
  35. <span>总分:{total_score}分</span>\
  36. <span>题量:{total_topics}小题</span>\
  37. </div>\
  38. <div class="bottom itemModule">\
  39. <h3>其他信息</h3>\
  40. <span>版式:{format}</span>\
  41. <span>考号:{examFields}</span>\
  42. </div>\
  43. </div>',
  44. dtkBaseInfoTpl:'<p>\
  45. <span>板式:{format}</span>\
  46. <span>考号:{examFields}</span>\
  47. <span>装订线:{hasBindline}</span>\
  48. <span>总分:<em class="dtkTotalScore">{total_score}</em>分</span>\
  49. <span>题量:{total_topics}</span>\
  50. </p>',
  51. dtkSubjectInfoTpl:'<p>\
  52. <span><strong>{bigTitle}</strong><i>{bigTitle}</i></span>\
  53. <span>{subjectType}</span>\
  54. <span>{questionLength}题</span>\
  55. <span>共{questionScore}分</span>\
  56. </p>',
  57. dtkSubjectInfoXZTpl:'<p>\
  58. <span><strong>{bigTitle}</strong><i>{bigTitle}</i></span>\
  59. <span>{subjectType}</span>\
  60. <span>{questionLength}</span>\
  61. <span>共{questionScore}分</span>\
  62. </p>'
  63. },
  64. init:function(){
  65. //判断[新创建]是数学还是其他学科(其他学科)
  66. this.isMathForNew = !~location.href.indexOf('third/thirdview_duo')
  67. //存放模版列表信息
  68. this.tplList = []
  69. this.dtkPosition = {}
  70. this.examGroupId = $('input[name="examGroupId"]').val();
  71. this.formatMap = {
  72. horizontal:'横版',
  73. vertical:'竖版',
  74. 1:'一栏',
  75. 2:'两栏',
  76. 3:'三栏'
  77. }
  78. this.questionTypes = {
  79. 1:'单选',
  80. 2:'多选',
  81. 11:'不定项选择',
  82. 5:'填空',
  83. 7:'解答',
  84. 17:'选做',
  85. '7c':'作文'
  86. }
  87. this.savePrintInfo = localStorage.getItem('savePrintInfo')!=undefined? JSON.parse(localStorage.getItem('savePrintInfo')):{}
  88. let _this = this;
  89. this.thirdOnlineUrl = '/index.php/online/third';
  90. let isCardReturn = window.location.href.indexOf('isCardReturn');
  91. // let isCardReturn = document.referrer.indexOf('vue');
  92. if(isCardReturn>-1){
  93. let resData = JSON.parse(localStorage.getItem('upDataThreeCard'));
  94. // let resData = JSON.parse(upDataThreeCard);
  95. if(resData.savePrintInfo){
  96. localStorage.setItem('savePrintInfo',JSON.stringify(resData.savePrintInfo));
  97. _this.savePrintInfo = resData.savePrintInfo;
  98. }
  99. // $.post('/print/getOnlineCardTempData',{
  100. // examGroupId:saveFormData.examGroupId,
  101. // },function(res){
  102. // res = JSON.parse(res);
  103. // let resData = JSON.parse(res.data);
  104. // if(resData.savePrintInfo){
  105. // localStorage.setItem('savePrintInfo',JSON.stringify(resData.savePrintInfo));
  106. // _this.savePrintInfo = resData.savePrintInfo;
  107. // _this.initDom()
  108. // _this.initPage()
  109. // _this.getDtkInfo()
  110. // }
  111. // })
  112. }
  113. //提供下载pdf 的唯一标识符
  114. this.downloadPdfIdentifier = ''
  115. this.initDom()
  116. this.bindEvent()
  117. this.initPage()
  118. this.getDtkInfo()
  119. this.getTplList();
  120. },
  121. initDom:function(){
  122. this.$dtkContentInfo = $('.hgc_leftContent .contentInfo')
  123. this.$dtkContentNoInfo = $('.hgc_leftContent .contentNoInfo')
  124. },
  125. initPage:function(){
  126. this.initConnectDtkStatus()
  127. },
  128. initConnectDtkStatus:function(){
  129. var self = this;
  130. //如果不是在线答题卡编辑页面跳转过来,直接清空storage
  131. // if(!~document.referrer.indexOf('vue')){
  132. // self.clearStorage()
  133. // self.savePrintInfo = {}
  134. // }
  135. //判断是否有题目信息
  136. var hasSubjectInfo = Object.keys(self.savePrintInfo).length;
  137. self.setContentInfoStatus(hasSubjectInfo)
  138. //如果进入该页面是关联答题卡页面,直接显示
  139. if(localStorage.getItem('isConnect') === 'block'){
  140. $(".template-flag").trigger('click')
  141. }
  142. },
  143. setContentInfoStatus:function(hasSubjectInfo){
  144. var self = this;
  145. self.$dtkContentInfo[hasSubjectInfo?'show':'hide']()
  146. self.$dtkContentNoInfo.css('display',hasSubjectInfo?'none':'flex')
  147. },
  148. // setConnectStatus:function(status){
  149. // $('.hgc_leftContent').css('display',status)
  150. // localStorage.setItem('isConnect',status)
  151. // },
  152. //获取当前答题卡信息
  153. getDtkInfo:function(){
  154. var self = this;
  155. var dtkInfo = null;
  156. //如果有记录的答题卡信息就使用记录的答题卡信息
  157. var storageInfo = self.savePrintInfo;
  158. var hasDtkInfo = Object.keys(storageInfo).length
  159. self.examGroupId = JSON.parse(localStorage.getItem('testFormData')).examGroupId
  160. var hasOnlineCard = JSON.parse(localStorage.getItem('testFormData')).hasOnlineCard
  161. //考试id 存在就是编辑考试
  162. if(self.examGroupId && !hasDtkInfo &&hasOnlineCard==1){
  163. //console.log('test')
  164. $.post('/index.php/third/getTemplateByExamGroupId',{examGroupId:self.examGroupId},function(res){
  165. //console.log(res)
  166. var savePrintInfoObj = {}
  167. if(!JSON.parse(res).success){
  168. // self.setConnectStatus('none')
  169. self.setContentInfoStatus(false)
  170. return;
  171. }
  172. dtkInfo = JSON.parse(res).data;
  173. // dtkInfo = JSON.parse(res).data.position ? JSON.parse(JSON.parse(res).data.position) :{};
  174. // dtkInfo.position = JSON.parse(JSON.stringify(dtkInfo));
  175. self.dtkPosition = dtkInfo;
  176. //判断是否是老版在线答题卡
  177. if(JSON.parse(dtkInfo.position).online_card_version && JSON.parse(dtkInfo.position).online_card_version != '3.0.0'){
  178. self.setContentInfoStatus(false)
  179. return;
  180. }
  181. let question_info={
  182. content:dtkInfo.questions
  183. }
  184. savePrintInfoObj = {
  185. position:JSON.parse(dtkInfo.position),
  186. sheet_answer:dtkInfo.sheet_answer,
  187. sheet_score:dtkInfo.sheet_score,
  188. timu:dtkInfo.timu,
  189. title:dtkInfo.name,
  190. question_info:question_info,
  191. pdf_url:dtkInfo.online_card_pdf
  192. }
  193. self.verificationDtkInfo(savePrintInfoObj,dtkInfo.questions)
  194. self.savePrintInfo = savePrintInfoObj
  195. localStorage.setItem('savePrintInfo',JSON.stringify(savePrintInfoObj))
  196. self.renderDtkInfo(savePrintInfoObj)
  197. // self.setConnectStatus('block')
  198. self.setContentInfoStatus(true)
  199. })
  200. }else{
  201. if(hasDtkInfo){
  202. dtkInfo = storageInfo;
  203. self.dtkPosition = dtkInfo.position;
  204. //直接把dtkInfo存到
  205. self.renderDtkInfo(dtkInfo)
  206. // self.setConnectStatus('block')
  207. self.setContentInfoStatus(true)
  208. }else{
  209. // self.setConnectStatus('none')
  210. self.setContentInfoStatus(false)
  211. }
  212. }
  213. },
  214. verificationDtkInfo:function(data,resData){
  215. var self = this;
  216. let topicAll = JSON.parse(JSON.stringify(resData));
  217. // let topicMod = JSON.parse(JSON.stringify(data.position.buildQuestions));
  218. // jQuery.each(topicMod,function (modI,topicModItem){
  219. // topicAll = topicAll.concat(topicModItem.questions)
  220. // })
  221. jQuery.each(resData,function (i,item){
  222. jQuery.each(data.question_info.content,function (j,topic){
  223. if(topic.questionNum==item.questionNum){
  224. let isEdit = false;
  225. if(topic.fullScore!=item.fullScore){
  226. isEdit = true
  227. topic.fullScore=item.fullScore
  228. }
  229. if(item.questionTypeId == 2){
  230. if(item.ruleScoreHalf != topic.halfScore){
  231. isEdit = true
  232. topic.halfScore = item.ruleScoreHalf
  233. }
  234. }
  235. if(isEdit){
  236. self.editDtkInfo(topicAll,topic.topicNo,item)
  237. }
  238. }
  239. })
  240. })
  241. },
  242. editDtkInfo:function(topicAll,topicNo,resDataTtem){
  243. jQuery.each(topicAll,function (idx,topic){
  244. if(topic.topicNo==topicNo){
  245. topic.fullScore=resDataTtem.fullScore
  246. if(resDataTtem.questionTypeId == 2){
  247. if(resDataTtem.ruleScoreHalf != topic.halfScore){
  248. topic.halfScore = resDataTtem.ruleScoreHalf
  249. }
  250. }
  251. }
  252. })
  253. },
  254. renderDtkInfo:function(dtkInfo){
  255. var self = this;
  256. // self.downloadPdfIdentifier = dtkInfo.position.identifier
  257. self.renderDtkBaseInfo(dtkInfo)
  258. self.renderDtkSubjectInfo(dtkInfo.position.topicListObject)
  259. },
  260. renderDtkBaseInfo:function(dtkInfo){
  261. var self = this;
  262. var tpl_data = dtkInfo.position
  263. var dtkbaseInfo = self.getOtherInfo(tpl_data)
  264. var paperScoreAll = self.getScoreAll(dtkInfo.question_info.content)
  265. var calcScoreTimu = self.calcScoreTimu(paperScoreAll,dtkInfo.timu)
  266. calcScoreTimu.total_score = tpl_data.cardSetting.examInfoConfig.fullScore.text;
  267. var baseInfoHtmls = self.tpls.dtkBaseInfoTpl.substitute({
  268. ...dtkbaseInfo,
  269. total_score:calcScoreTimu.total_score,
  270. total_topics:calcScoreTimu.total_topics,
  271. hasBindline:tpl_data.cardSetting.hasBindingLine?'有':'无'
  272. })
  273. $('.hgc_leftContent .module').eq(0).find('.infoItem').eq(0).children('.info').html(baseInfoHtmls)
  274. },
  275. getScoreAll:function (data) {
  276. let scoreArr = [];
  277. let pId = 0;
  278. for (let i = 0; i < data.length; i++) {
  279. if(data[i].questionTypeId==17){
  280. if(data[i].topicNo!=pId){
  281. scoreArr.push(Number(data[i].fullScore))
  282. pId = data[i].topicNo
  283. }
  284. }else{
  285. scoreArr.push(Number(data[i].fullScore))
  286. }
  287. }
  288. return scoreArr
  289. },
  290. calcQuestionsLen:function(buildQuestions,modelId){
  291. let count = 0,score = 0;
  292. // for(let modelId in buildQuestions){
  293. if(buildQuestions[modelId].questionTypeId == 17){
  294. count = buildQuestions[modelId].questions[0].total + '选' + buildQuestions[modelId].questions[0].required;
  295. score += parseFloat(buildQuestions[modelId].questions[0].fullScore)
  296. }else{
  297. buildQuestions[modelId].questions.forEach(function(val,index){
  298. if(val){
  299. score += parseFloat(val.fullScore)
  300. }else{
  301. buildQuestions[modelId].questions.splice(index,1)
  302. }
  303. })
  304. count += buildQuestions[modelId].questions.filter(v=>v!=null).length
  305. }
  306. // }
  307. return {count:count,score:score};
  308. },
  309. calcTotalScore:function(buildQuestions,modelId){
  310. let count = 0,score = 0;
  311. for(let modelId in buildQuestions){
  312. if(buildQuestions[modelId].questionTypeId == 17){
  313. count += parseFloat(buildQuestions[modelId].questions[0].total);
  314. score += parseFloat(buildQuestions[modelId].questions[0].fullScore)
  315. }else{
  316. buildQuestions[modelId].questions.forEach(function(val,index){
  317. if(val){
  318. score += parseFloat(val.fullScore)
  319. }else{
  320. buildQuestions[modelId].questions.splice(index,1)
  321. }
  322. })
  323. count += buildQuestions[modelId].questions.filter(v=>v!=null).length
  324. }
  325. }
  326. // return {count:count,score:score};
  327. $('.dtkTotalScore').html(score).attr('data-topics',count)
  328. },
  329. renderDtkSubjectInfo:function(buildQuestions){
  330. var self = this;
  331. var subjectInfoHtml = '';
  332. for(let modelId in buildQuestions){
  333. // subjectInfoHtml += '<div class="infoItem">\
  334. // <div class="info">\
  335. subjectInfoHtml += '<p>\
  336. <span><strong>'+buildQuestions[modelId].questionTitleReadonly+'</strong><i>'+buildQuestions[modelId].questionTitleReadonly+'</i></span>\
  337. <span>'+PaperAndTopicConfig.topicTypeObj[buildQuestions[modelId].questionCreateTypeId]+'</span>\
  338. <span>'+this.calcQuestionsLen(buildQuestions,modelId).count+'题</span>\
  339. <span>共'+this.calcQuestionsLen(buildQuestions,modelId).score+'分</span>\
  340. </p>'
  341. // </div>\
  342. // </div>'
  343. this.calcTotalScore(buildQuestions,modelId);
  344. }
  345. $('.cardTopicInfo').html(subjectInfoHtml)
  346. },
  347. //获取模版
  348. getTplList:function(){
  349. var self = this
  350. $.get('/index.php/third/tplList',function(res){
  351. var result = JSON.parse(res);
  352. if(result.success === 1 && result.thisTpls){
  353. self.tplList = []
  354. jQuery.each(result.thisTpls, function (i, item){
  355. let tpl_data = JSON.parse(item.tpl_data)
  356. if(tpl_data.position && tpl_data.position.online_card_version == '3.0.0'){
  357. // if(tpl_data.position.){
  358. self.tplList.push(item)
  359. // }
  360. } else {
  361. // let errTplMsg = '在线答题卡模板:'+item.title+'(id:'+item.third_tpl_id+')'+'缺少数据,是否删除模板?'
  362. // layer.confirm(errTplMsg, {title:'提示'}, function(index){
  363. // self.delTpl(item.third_tpl_id)
  364. // layer.close(index);
  365. // });
  366. }
  367. })
  368. if(self.tplList.length>0){
  369. $('#tplListMsg').hide();
  370. } else{
  371. $('#tplListMsg').show()
  372. }
  373. self.renderTplList(self.tplList)
  374. }
  375. })
  376. },
  377. //format examFields
  378. getOtherInfo:function(tpl_data){
  379. var self = this;
  380. let papers = ['','A3','A4','16K','8Ks','8Kb'];
  381. let direction = tpl_data.cardSetting.direction==1?'horizontal':'vertical';
  382. var format = papers[tpl_data.cardSetting.paperSize]+'-'+self.formatMap[direction]+'-'+self.formatMap[tpl_data.cardSetting.column]
  383. var examFields = ''
  384. if(tpl_data.cardSetting.examinationNumberType.indexOf(1)){
  385. examFields+='条形码'
  386. }
  387. if(tpl_data.cardSetting.examinationNumberType.indexOf(2)){
  388. examFields+=' 填涂'
  389. }
  390. return {
  391. format:format,
  392. examFields:examFields
  393. }
  394. },
  395. calcScoreTimu:function(sheet_score,timu){
  396. var self = this;
  397. var total_topics = 0;
  398. var total_score = 0
  399. for(var key in sheet_score){
  400. total_score+=Number(sheet_score[key])
  401. }
  402. for(var type in timu){
  403. total_topics+=Number(timu[type])
  404. }
  405. if(timu==undefined){
  406. total_topics = sheet_score.length
  407. }
  408. return {
  409. total_topics:total_topics,
  410. total_score:total_score
  411. }
  412. },
  413. renderTplList:function(tpls){
  414. var self = this;
  415. // if(!tpls.length)alert('数据不存在');
  416. var htmls = tpls.reduce( function(str,item){
  417. var tpl_data = JSON.parse(item.tpl_data)
  418. var otherInfo = self.getOtherInfo(tpl_data.position)
  419. item.format = otherInfo.format
  420. item.examFields = otherInfo.examFields
  421. str += self.tpls.tplItemTPl.substitute(item)
  422. return str
  423. },'')
  424. $('.tplList').html(htmls)
  425. $('#tplLength').text(tpls.length)
  426. // if(tpls.length > 0){
  427. // $('#tplListMsg').show();
  428. // }else{
  429. // $('#tplListMsg').hide();
  430. // }
  431. },
  432. bindEvent:function(){
  433. var self = this;
  434. // $(".template-flag").click(function(){
  435. // var $rightContent = $(".hgc_leftContent");
  436. // $(".hgc_leftContent").toggle();
  437. // self.setConnectStatus($rightContent.css('display'))
  438. // });
  439. $('body').on('click','.menu',function(e){
  440. e.stopPropagation()
  441. $(this).children('.triangle').css('display','flex')
  442. $(this).children('.menuList').css('display','flex')
  443. })
  444. $(document).click(function(){
  445. $('.menu').children('.triangle').css('display','none')
  446. $('.menu').children('.menuList').css('display','none')
  447. })
  448. $('body').on('click','.menuList span',function(e){
  449. var $this = $(this);
  450. var type = $(this).attr('class');
  451. var tplId = $(this).attr('data-id')
  452. switch(type){
  453. case 'del':
  454. self.delTpl(tplId,$this)
  455. break;
  456. case 'preview':
  457. self.previewTpl(tplId);
  458. break;
  459. case 'use':
  460. self.useTpl(tplId);
  461. break;
  462. }
  463. })
  464. //修改新版答题卡
  465. $('#editNewMyTpl').click(function(e){
  466. self.goEditAnswerSheet();
  467. })
  468. //保存模版
  469. $('#saveMyTpl').click(function(){
  470. var tplTitle = '',total_score,total_topics;
  471. // var {sheet_score,timu,position,question_info} = self.savePrintInfo;
  472. // var total_topics = 0;
  473. // var total_score = position.cardSetting.examInfoConfig[1].text;
  474. // if(typeof(sheet_score) === 'string'){
  475. // sheet_score = JSON.parse(sheet_score);
  476. // }
  477. // for(var key in sheet_score){
  478. // total_score+=+sheet_score[key]
  479. // }
  480. // for(var type in timu){
  481. // total_topics+=Number(timu[type])
  482. // }
  483. // if(timu==undefined){
  484. // total_topics = question_info.content.length
  485. // }
  486. layer.confirm('<div class="hgc_inputItem">\
  487. <p><em>模版名称:</em><input type="text" id="tplName" maxlength="20" onkeyup="tplNameReplace(this)" /></p>\
  488. <p class="error">模版名称不能为空</p>\
  489. </div>', function(index){
  490. //do something
  491. tplTitle = $('#tplName').val();
  492. $('.hgc_inputItem .error')[tplTitle?'hide':'show']()
  493. total_score = $('.dtkTotalScore').html();
  494. total_topics = $('.dtkTotalScore').attr('data-topics')
  495. if(tplTitle){
  496. $.ajax({
  497. url: '/index.php/third/saveTemplateByOnline',
  498. method: 'POST',
  499. data:{
  500. title:tplTitle,
  501. total_score,
  502. total_topics,
  503. tpl_data:JSON.stringify(self.savePrintInfo)
  504. },
  505. success: function (data) {
  506. if(JSON.parse(data).success === 1){
  507. layer.msg('保存答题卡成功');
  508. self.getTplList()
  509. } else {
  510. layer.msg(JSON.parse(data).message);
  511. }
  512. }
  513. })
  514. }
  515. tplTitle && layer.close(index);
  516. });
  517. })
  518. var $tplListEl = $('.hgc_leftContent .tplList');
  519. $('.hgc_leftContent .btnItem').click(function(){
  520. var stepNum = $(this).hasClass('leftBtn')?225:-225;
  521. var curLeft =Math.abs($tplListEl.position().left);
  522. if(stepNum<0 && curLeft<220){
  523. return false
  524. }
  525. var listW = Math.abs($tplListEl.width());
  526. var boxW = Math.abs($('.relation-answer-card .tplBox').width());
  527. if((curLeft + boxW +stepNum -240)==listW || (curLeft + boxW +stepNum -240)>listW){
  528. return false
  529. }
  530. $tplListEl.animate({left:-(curLeft+stepNum)},100)
  531. })
  532. $('.contentNoInfo .hbtn').click(function(){
  533. self.goOnlineCard()
  534. })
  535. /*创建答题卡*/
  536. $('#goAnswerSheet').click(function(){
  537. var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
  538. var AnswerSheetUrl = '/index.php/online/answersheet?examGroupId='+newTestFormData.examGroupId+'&cardType=0&isEdit=0'
  539. location.href = AnswerSheetUrl;
  540. })
  541. //下载pdf
  542. $('#downLoadPdfBtn').click(function () {
  543. var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
  544. //isProduction
  545. // var host = isProduction?'//zsyapi.zhixinhuixue.com':'//192.168.1.60:8001'
  546. // location.href = host+'/download/'+self.downloadPdfIdentifier
  547. // location.href = self.savePrintInfo.pdf_url;
  548. location.href = '/third/download?url=' + self.savePrintInfo.pdf_url + '&title=pdf-'+self.savePrintInfo.title+newTestFormData.examGroupId
  549. })
  550. // 保存并返回
  551. $("body").delegate("#createThirdCard", "click", function(e) {
  552. e.preventDefault();
  553. if(!localStorage.savePrintInfo || !JSON.parse(localStorage.savePrintInfo).online_card_version){
  554. location.href = '/index.php/third/index'
  555. return false
  556. }
  557. // var error=[];
  558. // if(error.length == 0){
  559. $(this).attr('active','false');
  560. var data = JSON.parse(localStorage.getItem('testFormData')) || {};
  561. //如果选择关联答题卡的时候
  562. if($('.hgc_leftContent').is(':visible')){
  563. var tplInfo = self.savePrintInfo;
  564. for(var key in tplInfo){
  565. var keyInfo = tplInfo[key];
  566. if(typeof keyInfo === 'object'){
  567. if(key === 'pdfTemplate')continue;
  568. data[key] = JSON.stringify(keyInfo)
  569. }else{
  570. if(key === 'pdfHtml'){
  571. keyInfo = new Blob([keyInfo], {
  572. type: 'text/plain;charset=utf-8'
  573. })
  574. key = 'pdfTemplate'
  575. }
  576. data[key] = keyInfo
  577. }
  578. }
  579. }
  580. var formData = new FormData()
  581. for(var k in data){
  582. if(k === 'pdfTemplate'){
  583. formData.append(k,data[k],'pdfTepmlate.txt')
  584. }else{
  585. formData.append(k,data[k])
  586. }
  587. }
  588. //console.log(formData)
  589. $.ajax({
  590. //'//192.168.1.51/index.php/print/saveCardOnline' + loginStatus,
  591. url:"/index.php/third/insertThirdSheet",
  592. method: 'POST',
  593. processData: false,
  594. contentType: false,
  595. dataType: 'json',
  596. data: formData,
  597. success: function (data) {
  598. //console.log(data)
  599. if(data.success === 1){
  600. layer.msg(data.message);
  601. self.clearStorage()
  602. location.href = data.result;
  603. location.href = '/index.php/third/index'
  604. }else {
  605. layer.msg(data.message);
  606. self.clearStorage()
  607. setTimeout(function () {
  608. location.href = '/index.php/third/index'
  609. },3000)
  610. }
  611. }
  612. })
  613. // }else{
  614. // layer.msg(error.join(','));
  615. // $("#createThirdCard").attr('active','true');
  616. // }
  617. });
  618. },
  619. clearStorage:function(){
  620. //清空storage
  621. localStorage.removeItem('position')
  622. localStorage.removeItem('buildQuestions')
  623. localStorage.removeItem('savePrintInfo')
  624. localStorage.removeItem('testFormData')
  625. localStorage.removeItem('isCardReturn')
  626. },
  627. useTpl:function(tplId){
  628. var self = this;
  629. var tpl = self.tplList.find(v=>v.third_tpl_id === tplId);
  630. var tpl_data = JSON.parse(tpl.tpl_data);
  631. var tplTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
  632. tpl_data.examGroupId = tplTestFormData.examGroupId;
  633. // localStorage.setItem('position',tpl.tpl_data)
  634. // localStorage.setItem('buildQuestions',JSON.stringify(JSON.parse(tpl.tpl_data).buildQuestions))
  635. localStorage.setItem('savePrintInfo',JSON.stringify(tpl_data));
  636. this.savePrintInfo = tpl_data;
  637. // this.savePrintInfo = JSON.parse(tpl.tpl_data)
  638. // self.goOnlineCard()
  639. // hgc_DtkTplModule.getDtkInfo()
  640. // location.href = self.thirdOnlineUrl;
  641. self.goEditAnswerSheet();
  642. },
  643. previewTpl:function(tplId){
  644. var self = this;
  645. var tpl = self.tplList.find(v=>v.third_tpl_id === tplId);
  646. var tpl_data = JSON.parse(tpl.tpl_data);
  647. var tplTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
  648. tpl_data.examGroupId = tplTestFormData.examGroupId;
  649. // 存储预览前的试卷信息
  650. if(localStorage.getItem('savePrintInfo')){
  651. localStorage.setItem('previewSavePrintInfo',localStorage.getItem('savePrintInfo'));
  652. }
  653. localStorage.setItem('savePrintInfo',JSON.stringify(tpl_data));
  654. this.savePrintInfo = tpl_data;
  655. location.href = '/index.php/online/answersheet?examGroupId='+tpl_data.examGroupId+'&cardType=0&isEdit=1&isPreview=1';
  656. },
  657. goOnlineCard:function(){
  658. var self = this;
  659. self.isOldTpl();
  660. },
  661. isOldTpl:function (isPreview) {
  662. var self = this;
  663. var addGrade = 0
  664. $('.grade-sel ul li').each(function(){
  665. if($(this).hasClass('active')){
  666. addGrade = $(this).attr('grade')
  667. }
  668. })
  669. if(addGrade!=undefined&&addGrade!==0){
  670. var grade = addGrade
  671. } else {
  672. var grade = $("input[name='grade']").val();
  673. }
  674. // var grade = 1;
  675. // modifyThirdExam
  676. var isEdit = ~location.href.indexOf('modifyThirdExam');
  677. if(isEdit){
  678. if(hasThirdCard==1&&hasOnlineCard==0){
  679. layer.confirm('<div class="hgc_inputItem">\
  680. <p>当前考试存在制作模板数据,如果继续使用并保存【在线答题卡】,则会清空制作模板数据,请确认!</p>\
  681. </div>', function(index){
  682. // $.ajax({
  683. // url: 'index.php/third/clearExamTpl',
  684. // method: 'POST',
  685. // data:{
  686. // examGroupId:self.examGroupId,
  687. // },
  688. // success: function (data) {
  689. // if(data.success === 1){
  690. // $('.grade-sel ul li').each(function(){
  691. // if($(this).hasClass('active')){
  692. // grade = $(this).attr('grade')
  693. // }
  694. // })
  695. localStorage.setItem('grade',grade)
  696. location.href = self.thirdOnlineUrl
  697. // }else{
  698. // layer.msg(data.info)
  699. // }
  700. // }
  701. // })
  702. });
  703. }else{
  704. // $('.grade-sel ul li').each(function(){
  705. // if($(this).hasClass('active')){
  706. // grade = $(this).attr('grade')
  707. // }
  708. // })
  709. localStorage.setItem('grade',grade)
  710. location.href = self.thirdOnlineUrl
  711. }
  712. }else{
  713. // $('.grade-sel ul li').each(function(){
  714. // if($(this).hasClass('active')){
  715. // grade = $(this).attr('grade')
  716. // }
  717. // })
  718. localStorage.setItem('grade',grade)
  719. location.href = self.thirdOnlineUrl
  720. }
  721. },
  722. goEditAnswerSheet:function () {
  723. var newTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
  724. location.href = '/index.php/online/answersheet?examGroupId='+newTestFormData.examGroupId+'&cardType=0&isEdit=1';
  725. },
  726. delTpl:function(tplId,$this){
  727. $.post('/third/delTpl',{third_tpl_id:tplId},function(res){
  728. var result = JSON.parse(res);
  729. if(result.success === 1 && $this){
  730. $this.closest('.tplItem').remove()
  731. $('#tplLength').text(Number($('#tplLength').text() -1))
  732. if(Number($('#tplLength').text())==1){
  733. $('#tplListMsg').hide()
  734. } else{
  735. $('#tplListMsg').show()
  736. }
  737. }
  738. })
  739. }
  740. }
  741. hgc_DtkTplModule.init()
  742. })