cardList.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  1. $(function () {
  2. layui.use(['layer', 'form', 'table'], function () {
  3. var layer = layui.layer
  4. , form = layui.form;
  5. form.render('select');
  6. });
  7. let baseIdx = 0;
  8. /**
  9. *模板轮播切换
  10. **/
  11. $('.modules-box .btnItem').click(function () {
  12. let $tplListEl = $('.modules-box .tplList');
  13. let listW = $tplListEl.width();
  14. let curLeft = Math.abs($tplListEl.position().left);
  15. let curTpBoxW = $('.modules-box .tplCut').width();
  16. let baseW = $('.modules-box .tplItem').eq(0).width() + 10;
  17. if ($(this).hasClass('leftBtn')) {
  18. if (baseIdx == 0) {
  19. return
  20. }
  21. baseIdx--
  22. } else if ($(this).hasClass('rightBtn')) {
  23. if (curLeft + curTpBoxW == listW || curLeft + curTpBoxW > listW) {
  24. return
  25. }
  26. baseIdx++
  27. }
  28. $tplListEl.animate({ left: -(baseIdx * baseW) }, 100)
  29. })
  30. /**
  31. *切换答题卡列表
  32. **/
  33. $('body').on('change', 'input[name="cardUse"]', function (e) {
  34. let idx = $('input[name="cardUse"]:checked').closest('tr').index()
  35. cardListData.changeCardFun(cardListData.cardListData[idx].multiplex_id);
  36. })
  37. /**
  38. *预览编辑模板
  39. **/
  40. $('body').on('click', '.menu', function (e) {
  41. e.stopPropagation()
  42. $(this).children('.triangle').css('display', 'flex')
  43. $(this).children('.menuList').css('display', 'flex')
  44. })
  45. $(document).click(function () {
  46. $('.menu').children('.triangle').css('display', 'none')
  47. $('.menu').children('.menuList').css('display', 'none')
  48. })
  49. /**
  50. *创建答题卡模板
  51. **/
  52. $('body').on('click', '#goAnswerSheet', function (e) {
  53. let url = cardListData.useCardTool(cardListData.examGroupId)
  54. if (this.item_collect) {
  55. window.location.href = `${url}/mixSubjects.html?examGroupId=${cardListData.examGroupId}`
  56. } else {
  57. window.location.href = `${url}?isEdit=0&cardType=0&examGroupId=${cardListData.examGroupId}`
  58. }
  59. // window.location.href= '/index.php/online/answersheet?isEdit=0&cardType=0&examGroupId='+cardListData.examGroupId;
  60. })
  61. /**
  62. *编辑模板
  63. **/
  64. $('body').on('click', '.setEditCard', function (e) {
  65. if (cardListData.assist_status == 1 || cardListData.assist_status == 2) {
  66. var that = this;
  67. layer.tips('后台操作员未完成任务,暂不支持编辑!', that, { tips: [3, '#787878'] });
  68. } else {
  69. let idx = $(this).closest('tr').index()
  70. // 非复用&已上传试卷考试,需要弹层提示
  71. if (cardListData.isDownLoad == 0 && cardListData.isThird == 1 && cardListData.isUploadPaper == 1) {
  72. layer.open({
  73. title: '提示',
  74. content: '试卷已上传,如更改试题结构,需重新上传试卷,请确认!',
  75. btn: ['确认', '取消'],
  76. yes: function (index, layero) {
  77. cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 5, cardListData.cardListData[idx].is_copy)
  78. layer.close(index);
  79. }
  80. });
  81. } else {
  82. cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 5, cardListData.cardListData[idx].is_copy)
  83. }
  84. }
  85. })
  86. /**
  87. *下载模板
  88. **/
  89. $('body').on('click', '.setDownloadCard', function (e) {
  90. if (cardListData.assist_status == 1 || cardListData.assist_status == 2) {
  91. var that = this;
  92. layer.tips('后台操作员未完成任务,暂不支持下载!', that, { tips: [3, '#787878'] });
  93. } else {
  94. let idx = $(this).closest('tr').index()
  95. if (cardListData.isDownLoad == 0 && cardListData.isThird == 1) {
  96. // 未被下载过的答题卡首次下载,需要弹层提示
  97. layer.open({
  98. title: '提示',
  99. content: '下载后答题卡结构不能调整,是否下载答题卡?',
  100. btn: ['确认下载', '取消'],
  101. yes: function (index, layero) {
  102. cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 2)
  103. layer.close(index);
  104. }
  105. });
  106. } else {
  107. cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 2)
  108. }
  109. }
  110. })
  111. /**
  112. * 打印
  113. */
  114. $('body').on('click', '.handlerPrintPdf', function (e) {
  115. let idx = $(this).closest('tr').index()
  116. if (cardListData.assist_status == 1 || cardListData.assist_status == 2) {
  117. var that = this;
  118. layer.tips('后台操作员未完成任务,暂不支持打印!', that, { tips: [3, '#787878'] });
  119. } else {
  120. evaluationClient.BulkPrintPDF(JSON.stringify(cardListData.printParams));
  121. cardListData.downloadCardFun(cardListData.cardListData[idx].multiplex_id);
  122. }
  123. })
  124. /**
  125. *查看模板
  126. **/
  127. $('body').on('click', '.setPreviewCard', function (e) {
  128. let idx = $(this).closest('tr').index()
  129. cardListData.getCurPositionData(cardListData.cardListData[idx].multiplex_id, 4)
  130. })
  131. /**
  132. *复用模板:当前存在可编辑模板时不能复用模板
  133. **/
  134. $('body').on('click', '.setReuseCard', function (e) {
  135. let idx = $(this).closest('tr').index()
  136. let defaultName = cardListData.cardListData[idx].name;
  137. let id = cardListData.cardListData[idx].multiplex_id;
  138. // cardListData.cardListData[idx].multiplex_id
  139. let hasEditItem = cardListData.cardListData.filter(v => v.is_download == 0).length > 0;
  140. if (hasEditItem) {
  141. layer.msg('当前有可编辑答题卡,不允许复用!')
  142. return;
  143. }
  144. layer.open({
  145. title: '答题卡名称',
  146. area: ['400px', '250px'],
  147. content: '答题卡名称:<input type="text" placeholder="请输入答题卡名称" value="' + defaultName + '" maxlength="20" class="layui-input" id="newCardName"><span id="cardErr"></span>'
  148. , btn: ['确定', '取消']
  149. , yes: function (index, layero) {
  150. let curName = $('#newCardName').val().trim();
  151. if (curName == '') {
  152. $('#cardErr').html('请输入答题卡名称!')
  153. } else if (cardListData.cardListData.filter(val => val.name == curName).length > 0) {
  154. $('#cardErr').html('答题卡名称已存在!')
  155. } else {
  156. $('#cardErr').html('')
  157. cardListData.setReuseCard({
  158. multiplexId: id,
  159. name: curName
  160. })
  161. layer.close(index);
  162. }
  163. return false
  164. }
  165. });
  166. })
  167. /**
  168. *隐藏答题卡
  169. **/
  170. $('body').on('click', '.setHideCard', function (e) {
  171. let idx = $(this).closest('tr').index();
  172. let id = cardListData.cardListData[idx].multiplex_id;
  173. if ($(this).closest('tr').find('.card-use').is(':checked')) {
  174. layer.msg('当前应用模板不能隐藏!')
  175. return
  176. }
  177. cardListData.setHideCard(id, cardListData.isHideList == 0 ? 1 : 0);
  178. })
  179. /**
  180. *保存为我的模板
  181. **/
  182. $('body').on('click', '.setSaveTpl', function (e) {
  183. let idx = $(this).closest('tr').index();
  184. cardListData.saveAsMyTpl(idx);
  185. })
  186. /**
  187. *显示隐藏答题卡列表
  188. **/
  189. $('body').on('change', '.show-all', function (e) {
  190. cardListData.isHideList = $(this).is(':checked') ? 1 : 0;
  191. cardListData.getCardList();
  192. })
  193. /**
  194. *使用、预览、删除 模板
  195. **/
  196. $('body').on('click', '.menuList span', function (e) {
  197. let idx = $(this).closest('.tplItem').index();
  198. //存数据
  199. let tplData = JSON.parse(cardListData.tplList[idx].tpl_data);
  200. let tplTestFormData = JSON.parse(localStorage.getItem('testFormData')) || {};
  201. tplData.examGroupId = tplTestFormData.examGroupId;
  202. // 没有下载答题卡&答题卡列表长度>1时, 拼接multiplexId
  203. let str = '';
  204. if ($('input[data-active="1"]').length > 0) {
  205. let cardIdx = $('input[data-active="1"]').closest('tr').index();
  206. let id = cardListData.cardListData[cardIdx].multiplex_id;
  207. str = '&multiplexId=' + id
  208. }
  209. if ($(e.target).hasClass('use')) {
  210. // 使用:当前存在答题卡列表,传入当前应用的multiplex_id
  211. if ($('.create-card').is(':hidden') && cardListData.isUploadPaper == 1) {
  212. //已创建过答题卡&已创建过试卷,需要弹层提示
  213. layer.open({
  214. title: '提示',
  215. content: '试卷已上传,如更改试题结构,需重新上传试卷,请确认!',
  216. btn: ['确认', '取消'],
  217. yes: function (index, layero) {
  218. let url = cardListData.useCardTool(tplTestFormData.examGroupId);
  219. window.location.href = `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=0&isCopy=0&cardType=0${str}`;
  220. layer.close(index);
  221. // tplData.position.isUseTemp = true;
  222. // localStorage.setItem('savePrintInfo',JSON.stringify(tplData));
  223. // window.location.href= '/index.php/online/answersheet?examGroupId='+tplTestFormData.examGroupId+'&isEdit=0&isCopy=0&cardType=0'+str;
  224. // layer.close(index);
  225. }
  226. });
  227. } else {
  228. let url = cardListData.useCardTool(tplTestFormData.examGroupId);
  229. window.location.href = `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=0&isCopy=0&cardType=0${str}&tplId=${cardListData.tplList[idx].third_tpl_id}`;
  230. // tplData.position.isUseTemp = true;
  231. // localStorage.setItem('savePrintInfo',JSON.stringify(tplData));
  232. // window.location.href= '/index.php/online/answersheet?examGroupId='+tplTestFormData.examGroupId+'&isEdit=0&isCopy=0&cardType=0'+str;
  233. }
  234. } else if ($(e.target).hasClass('preview')) {
  235. // 预览
  236. let url = cardListData.useCardTool(tplTestFormData.examGroupId);
  237. window.location.href = `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=1&isPreview=1&isCopy=0&cardType=0${str}&tplId=${cardListData.tplList[idx].third_tpl_id}`;
  238. // window.location.href= `${url}?examGroupId=${tplTestFormData.examGroupId}&isEdit=1&isPreview=1&isCopy=0&cardType=0${str}`;
  239. // localStorage.setItem('savePrintInfo',JSON.stringify(tplData));
  240. // window.location.href= '/index.php/online/answersheet?examGroupId='+tplTestFormData.examGroupId+'&isEdit=1&isPreview=1&isCopy=0&cardType=0'+str;
  241. } else if ($(e.target).hasClass('del')) {
  242. // 删除
  243. let _this = $(this);
  244. $.post(cardListData.api.delTpl, { third_tpl_id: cardListData.tplList[idx].third_tpl_id }, function (res) {
  245. var result = JSON.parse(res);
  246. if (result.success === 1) {
  247. _this.closest('.tplItem').remove()
  248. $('#tplLength').text($('.tplItem').length)
  249. if ($('.tplItem').length > 0) {
  250. $('#tplListMsg').hide()
  251. } else {
  252. $('#tplListMsg').show()
  253. }
  254. }
  255. })
  256. }
  257. // cardListData.saveAsMyTpl(idx);
  258. })
  259. // 题目审查
  260. $('body').on('click', '#examine', function (e) {
  261. let position = JSON.parse(cardListData.curCardTplData.position)
  262. let topicListObject = Object.values(position.topicListObject)
  263. const subjectName = { 12: "物理", 13: '化学', 14: '生物', 15: '政治', 16: '历史', 17: '地理' }
  264. // 大题循环
  265. let splitLis = []
  266. for (let index = 0; index < topicListObject.length; index++) {
  267. let json = { name: topicListObject[index].questionTitleVal, groups: {} }
  268. // 找出学科相同组
  269. for (let ind = 0; ind < topicListObject[index].quesNoArr.length; ind++) {
  270. const element = topicListObject[index].quesNoArr[ind];
  271. let subject = element.subject;
  272. if (json.groups[subject] === undefined) {
  273. json.groups[subject] = [element];
  274. } else {
  275. // 判断下一个是不是跟前一个连贯的
  276. if (element.start - 1 == json.groups[subject].slice(-1)[0].end - 0 && json.groups[subject].slice(-1)[0].subject == element.subject) {
  277. json.groups[subject][json.groups[subject].length - 1].end = element.end
  278. } else {
  279. json.groups[subject].push(element);
  280. }
  281. }
  282. }
  283. // // 存储的小题
  284. // let questions = topicListObject[index].questions
  285. // const result = questions.reduce((acc, cur) => {
  286. // const index = acc.findIndex(item => item.name === cur.subject);
  287. // if (index === -1) {
  288. // acc.push({ name: cur.subject, alias: [String(cur.alias)] });
  289. // } else {
  290. // const lastAlias = acc[index].alias[acc[index].alias.length - 1];
  291. // if (lastAlias && lastAlias.split("-")[1] === String(cur.alias - 1)) {
  292. // acc[index].alias[acc[index].alias.length - 1] = `${lastAlias.split("-")[0]}-${cur.alias}`;
  293. // } else {
  294. // acc[index].alias.push(String(cur.alias));
  295. // }
  296. // }
  297. // return acc;
  298. // }, []);
  299. // json.list = result
  300. splitLis.push(json)
  301. }
  302. let html = '<div style="padding:20px"><div class="layui-row">'
  303. for (let index = 0; index < splitLis.length; index++) {
  304. html += `<div class="layui-col-md2">${splitLis[index].name}</div>`
  305. let str = '';
  306. const element = splitLis[index];
  307. Object.keys(element.groups).forEach((keys, i) => {
  308. const list = element.groups[keys];
  309. str += `<p>${subjectName[keys]} `
  310. for (let index = 0; index < list.length; index++) {
  311. if (list[index].start != list[index].end) {
  312. str += (list[index].start + "~" + list[index].end) + (list.length > 1 && index < list.length - 1 ? ',' : '')
  313. } else {
  314. str += list[index].start + (list.length > 1 && index < list.length - 1 ? ',' : '');
  315. }
  316. }
  317. str += `</p>`
  318. });
  319. html += `<div class="layui-col-md10">
  320. ${str}
  321. </div>`
  322. }
  323. html += '</div></div>'
  324. //墨绿深蓝风
  325. layer.open({
  326. type: 1,
  327. area: ['500px', '300px'],
  328. title: '学科试题',
  329. skin: 'layui-layer-examine', //样式类名
  330. closeBtn: 1, //不显示关闭按钮
  331. shadeClose: true, //开启遮罩关闭
  332. anim: 2,
  333. content: html
  334. });
  335. })
  336. cardListData.init();
  337. })
  338. function tplNameReplace (num) {
  339. var str = num.value;
  340. var value = str.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\.]/g, '');
  341. num.value = value;
  342. }
  343. var locationUrl = window.location.href.substring(0, window.location.href.indexOf('/index.php'));
  344. var baseLocalUrl = locationUrl
  345. let loginStatus = ''
  346. if (!locationUrl.includes('xbas3')) {
  347. baseLocalUrl = 'http://xbas3.testing.xiaoben.com';
  348. loginStatus = '/username/zhangxiuxiu/time/1681456191/sig/1ed6d280e52136f2304dba7a1c10c3c9/sessionid/session_456132ef87c57a8db843b7157feb9eaa'//秀秀
  349. }
  350. // window.baseUrl = 'http://zsyas2.dev.xueping.com/index.php/vue/';
  351. let apiBaseUrl = baseLocalUrl + '/index.php';
  352. window.baseUrl = baseLocalUrl + '/answersheet/';
  353. var cardListData = {
  354. item_collect: false,//是否全学科答题卡
  355. item_collectData: [],//是否全学科答题卡
  356. printParams: {},
  357. examGroupId: '',
  358. isThird: 0,
  359. isHideList: 0,//1显示隐藏列表,0不显示
  360. cardListData: [],//答题卡列表
  361. tplList: [],//模板列表
  362. curCardTplData: {},//当前模板详细信息
  363. isDownLoad: 0,//当前考试是否下载/生成过
  364. isUploadPaper: 0,//当前试卷是否已上传
  365. api: {
  366. getList: baseLocalUrl + '/index.php/third/getTemplateByExamGroupId' + loginStatus,//获取答题卡列表
  367. changeCard: baseLocalUrl + '/index.php/third/changeCard' + loginStatus,
  368. getOnlinePdf: baseLocalUrl + '/index.php/printTools/getOnlinePdf' + loginStatus,
  369. downloadCard: baseLocalUrl + '/index.php/third/downloadStatus' + loginStatus,
  370. // downFileApi:baseLocalUrl+'/third/download'+loginStatus,
  371. reuseCardApi: baseLocalUrl + '/third/multiplex' + loginStatus,
  372. getMyTplList: baseLocalUrl + '/third/tplList' + loginStatus,
  373. hideCard: baseLocalUrl + '/third/hideAnswerCard' + loginStatus,
  374. saveTpl: baseLocalUrl + '/third/saveTemplateByOnline' + loginStatus,
  375. delTpl: baseLocalUrl + '/third/delTpl' + loginStatus,
  376. getCurPosition: baseLocalUrl + '/third/getMultiplex' + loginStatus,
  377. GetOnlineToken: baseLocalUrl + '/print/GetOnlineToken' + loginStatus,
  378. },
  379. init () {
  380. if (this.searchToObject().isThird == 1) {
  381. // 第三方
  382. this.isThird = 1;
  383. this.examGroupId = JSON.parse(localStorage.getItem('testFormData')).examGroupId
  384. } else {
  385. //知心慧学
  386. this.isThird = 0;
  387. this.examGroupId = this.searchToObject().examGroupId
  388. }
  389. this.getCardList();
  390. },
  391. getCardList () {
  392. // 获取答题卡列表
  393. let that = this;
  394. $.ajax({
  395. url: that.api.getList,
  396. method: 'POST',
  397. data: {
  398. examGroupId: this.examGroupId,
  399. isHide: this.isHideList
  400. },
  401. success: function (data) {
  402. that.item_collect = JSON.parse(data).item_collect ? true : false;
  403. if (that.item_collect) {
  404. that.item_collectData = JSON.parse(data).item_collect;
  405. }
  406. if (JSON.parse(data).success === 1) {
  407. // let list = JSON.parse(data).multiplex;
  408. // let carData = JSON.parse(data)
  409. that.cardListData = JSON.parse(data).multiplex || [];
  410. that.isOnlinePrint = JSON.parse(data).isOnlinePrint;
  411. cardListData.assist_status = JSON.parse(data).data && JSON.parse(data).data.assist_status
  412. //当前考试是否被下载过
  413. that.isDownLoad = JSON.parse(data).data && JSON.parse(data).data.is_download;
  414. that.isUploadPaper = JSON.parse(data).data && JSON.parse(data).data.paper_uploaded;
  415. that.getOnlinePdf()
  416. $('#cardListLength').html(that.cardListData.length);
  417. if (that.cardListData.length == 0 && that.isHideList == 0) {
  418. $('.create-card').show();
  419. $('.cardinfo-box,#tplListModule').hide();
  420. } else {
  421. $('.create-card').hide();
  422. $('.cardinfo-box,#tplListModule').show();
  423. }
  424. if ((that.isDownLoad == 0 || !that.isDownLoad) && that.isHideList == 0) {
  425. that.getMyTpl();
  426. $('#myModule').show();
  427. } else {
  428. $('#myModule').hide();
  429. }
  430. let html = '';
  431. that.cardListData.forEach((val, idx) => {
  432. // 创建列表
  433. html += '<tr>\
  434. <td>'+ val.name + '</td>\
  435. <td>'+ that.timestampToTime(val.update_time) + '</td>\
  436. <td><input type="radio" name="cardUse" class="card-use" data-active="'+ val.active + '">应用</td>\
  437. <td>';
  438. if (that.isHideList == 0) {
  439. if (val.is_download == 0) {
  440. html += '<a href="javascript:;" class="setEditCard">编辑</a>'
  441. } else {
  442. html += '<a href="javascript:;" class="setPreviewCard">查看</a>\
  443. <a href="javascript:;" class="setReuseCard">复用</a>'
  444. }
  445. if (val.is_qrcode_online != 1) { // 没有二维码
  446. html += '<a href="#" class="setDownloadCard">下载</a>'
  447. if ((typeof evaluationClient != "undefined") && ('BulkPrintPDF' in evaluationClient)) {
  448. html += '<a href="#" class="handlerPrintPdf">打印</a>'
  449. }
  450. }
  451. if (that.isThird == 1) {
  452. html += '<a href="#" class="setSaveTpl">保存为我的模板</a>'
  453. }
  454. }
  455. if (val.is_download != 0) {
  456. html += '<a href="#" class="setHideCard">' + (that.isHideList == 1 ? '显示' : '隐藏') + '</a>'
  457. }
  458. html += '</td>\
  459. </tr>';
  460. if (val.active == 1) {
  461. that.getCurPositionData(val.multiplex_id, 1)
  462. }
  463. })
  464. $('#cardListTable tbody').html(html)
  465. $('#cardListTable tbody input[data-active="1"]').prop('checked', true)
  466. if (that.isHideList) {
  467. $('.card-use').prop('disabled', true)
  468. }
  469. } else {
  470. if (JSON.parse(data).message) {
  471. layer.msg(JSON.parse(data).message);
  472. }
  473. }
  474. }
  475. })
  476. },
  477. getOnlinePdf () {
  478. let that = this;
  479. $.ajax({
  480. url: this.api.getOnlinePdf,
  481. method: 'POST',
  482. data: {
  483. examGroupId: cardListData.examGroupId
  484. },
  485. success: function (data) {
  486. if (JSON.parse(data).success === 1) {
  487. cardListData.printParams = JSON.parse(data).data
  488. if (!('studentIds' in cardListData.printParams.params)) {
  489. cardListData.printParams.params.studentIds = []
  490. }
  491. }
  492. }
  493. })
  494. },
  495. changeCardFun (id) {
  496. let that = this;
  497. $.ajax({
  498. url: this.api.changeCard,
  499. method: 'POST',
  500. data: {
  501. multiplexId: id
  502. },
  503. success: function (data) {
  504. layer.msg(JSON.parse(data).msg)
  505. that.getCurPositionData(id, 1)
  506. }
  507. })
  508. },
  509. downloadCardFun (id) {
  510. let that = this;
  511. $.ajax({
  512. url: this.api.downloadCard,
  513. method: 'POST',
  514. data: {
  515. multiplexId: id
  516. },
  517. success: function (data) {
  518. that.getCardList()
  519. }
  520. })
  521. },
  522. getCurPositionData (id, type, tplTitle, positionTxt) {
  523. // type:1应用 2下载 3 保存我的模板 4查看 5编辑
  524. // tplTitle 保存模板title||编辑isCopy
  525. // positionTxt 存储position对应txt文件
  526. let that = this;
  527. $.ajax({
  528. url: this.api.getCurPosition,
  529. method: 'POST',
  530. data: {
  531. multiplexId: id
  532. },
  533. success: function (data) {
  534. if (JSON.parse(data).status == 0) {
  535. let positionData = JSON.parse(data).data;
  536. if (type == 1) {
  537. that.curCardTplData = positionData;
  538. that.createCurCard();
  539. } else if (type == 2) {
  540. that.downloadCardFun(id);
  541. location.href = baseLocalUrl + '/third/download?url=' + positionData.online_card_pdf + '&title=' + positionData.name
  542. } else if (type == 3) {
  543. let position = JSON.parse(positionData.position)
  544. total_score = position.totalScore;
  545. total_topics = that.calcTotalScore(position.topicListObject).count;
  546. $.ajax({
  547. url: that.api.saveTpl,
  548. method: 'POST',
  549. data: {
  550. title: tplTitle,
  551. total_score,
  552. total_topics,
  553. tpl_data: positionTxt
  554. },
  555. success: function (saveData) {
  556. if (JSON.parse(saveData).success === 1) {
  557. layer.msg('保存答题卡成功');
  558. that.getMyTpl();
  559. } else {
  560. layer.msg(JSON.parse(saveData).message);
  561. }
  562. }
  563. })
  564. } else if (type == 4) {
  565. let cardType = that.isThird == 0 ? 1 : 0
  566. let url = that.useCardTool(cardListData.examGroupId)
  567. // 无Token信息 跳转本地
  568. if (that.item_collect) {
  569. if(positionData.new_answer_sheet_subject==1){
  570. window.location.href = `${url}/subjects13.html?examGroupId=${cardListData.examGroupId}&isPreview=1&multiplexId=${positionData.multiplex_id}`
  571. }else{
  572. window.location.href = `${url}/mixSubjects.html?examGroupId=${cardListData.examGroupId}&isPreview=1&multiplexId=${positionData.multiplex_id}`
  573. }
  574. } else {
  575. window.location.href = `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&isPreview=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}`
  576. }
  577. // window.location.href= `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&isPreview=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}`
  578. // if(cardListData.isThird == 1){
  579. // localStorage.setItem('savePrintInfo',JSON.stringify(positionData))
  580. // }
  581. // window.location.href= '/index.php/online/answersheet?examGroupId='+cardListData.examGroupId+'&&isEdit=1&isPreview=1&cardType='+cardType+'&multiplexId='+positionData.multiplex_id;
  582. } else if (type == 5) {
  583. let cardType = cardListData.isThird == 0 ? 1 : 0
  584. let url = that.useCardTool(cardListData.examGroupId)
  585. if (that.item_collect) {
  586. if(positionData.new_answer_sheet_subject==1){
  587. window.location.href = `${url}/subjects13.html?examGroupId=${cardListData.examGroupId}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
  588. }else{
  589. window.location.href = `${url}/mixSubjects.html?examGroupId=${cardListData.examGroupId}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
  590. }
  591. } else {
  592. window.location.href = `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
  593. }
  594. // window.location.href= `${url}?examGroupId=${cardListData.examGroupId}&isEdit=1&cardType=${cardType}&multiplexId=${positionData.multiplex_id}&isCopy=${tplTitle}`
  595. // if(cardListData.isThird == 1){
  596. // localStorage.setItem('savePrintInfo',JSON.stringify(positionData))
  597. // }
  598. // window.location.href= '/index.php/online/answersheet?examGroupId='+cardListData.examGroupId+'&isEdit=1&cardType='+cardType+'&multiplexId='+positionData.multiplex_id+'&isCopy='+tplTitle;
  599. }
  600. }
  601. }
  602. })
  603. },
  604. useCardTool (examGroupId) {
  605. let item_collect = this.item_collect;
  606. let url = 'http://xbcard.testing.xiaoben.com'
  607. if (window.location.href.includes('dev.xiaoben.com')) {
  608. url = 'http://xbcard.dev.xiaoben.com'
  609. } else if (window.location.href.includes('schcur.com')) {
  610. url = 'http://xbcard.schcur.com'
  611. }
  612. // let token='731768365816463360'
  613. $.ajax({
  614. url: cardListData.api.GetOnlineToken,
  615. type: 'POST',
  616. dataType: 'json',
  617. async: false,
  618. success: function (res) {
  619. if (res.status == 1 && res.data != undefined) {
  620. let token = res.data;
  621. $.cookie('cardToken', null, { path: '/', domain: url.substring(url.indexOf('card.') + 4) });
  622. $.cookie("cardToken", token, { path: '/', expires: 1, domain: url.substring(url.indexOf('card.') + 4) });
  623. // if(item_collect){
  624. // window.location.href=`${url}mixSubjects.html?examGroupId=${examGroupId}&cardType=1`;
  625. // } else {
  626. // window.location.href=`${url}?examGroupId=${examGroupId}&cardType=1`;
  627. // }
  628. } else {
  629. if (res.msg != undefined) {
  630. layer.msg(res.msg)
  631. } else {
  632. layer.msg('token读取失败');
  633. }
  634. }
  635. }
  636. });
  637. return url;
  638. },
  639. createCurCard () {
  640. let data = this.curCardTplData;
  641. let collectData = this.item_collectData;
  642. $('.card-name').html(data.name)
  643. $('.card-time').html(this.timestampToTime(data.update_time))
  644. let position = JSON.parse(data.position);
  645. // 版式
  646. $('#cardType').html(this.getCardInfo(position).cardTypeHtml)
  647. // 考号
  648. $('#codeType').html(this.getCardInfo(position).codeTypeHtml)
  649. // 装订线
  650. $('#lineType').html(position.cardSetting.hasBindingLine == 1 ? '有' : '无')
  651. let topicListHtml = '';
  652. // 题目信息
  653. if (this.item_collect) {
  654. let totalScore = 0;
  655. let totalCount = 0;
  656. collectData.forEach((it, ind) => {
  657. totalCount += it.topic_count == '2选1' ? 1 : it.topic_count;
  658. totalScore += it.total_score;
  659. topicListHtml += '<li class="clearfix">\
  660. <div class="fl">'
  661. topicListHtml += this.numberConvert(ind + 1) + '、' + it.topic_type_name
  662. topicListHtml += '</div>\
  663. <div class="fl">'+ it.topic_basic_name + '</div>\
  664. <div class="fl">'+ it.topic_count + '题</div>\
  665. <div class="fl">共'+ it.total_score + '分</div>\
  666. </li>'
  667. })
  668. $('#totalScore').html(totalScore)
  669. $('#totalCount').html(totalCount)
  670. $('#cardTopicInfo').html(topicListHtml)
  671. } else {
  672. for (let topicType in position.topicListObject) {
  673. let curTopicItem = position.topicListObject[topicType];
  674. if (!curTopicItem.isQuestionText) {
  675. topicListHtml += '<li class="clearfix">\
  676. <div class="fl">'
  677. if (this.isThird == 1) {
  678. topicListHtml += curTopicItem.questionTitleReadonly
  679. } else {
  680. topicListHtml += curTopicItem.bigTopicNum + '、' + PaperAndTopicConfig.topicTypeObj[curTopicItem.questionCreateTypeId] + '题'
  681. }
  682. topicListHtml += '</div>\
  683. <div class="fl">'+ PaperAndTopicConfig.topicTypeObj[curTopicItem.questionCreateTypeId] + '</div>\
  684. <div class="fl">'+ this.calcQuestionsLen(position.topicListObject, topicType).count + '题</div>\
  685. <div class="fl">共'+ this.calcQuestionsLen(position.topicListObject, topicType).score + '分</div>\
  686. </li>'
  687. }
  688. };
  689. $('#totalScore').html(this.calcTotalScore(position.topicListObject).score)
  690. $('#totalCount').html(this.calcTotalScore(position.topicListObject).count)
  691. $('#cardTopicInfo').html(topicListHtml)
  692. }
  693. if ('batchSettings' in position.cardSetting && position.cardSetting.batchSettings) {
  694. $('#examine').show()
  695. }
  696. },
  697. getCardInfo (position) {
  698. // 版式、考号
  699. let codeTypeHtml = '';
  700. if (position.useQrCode == 1) {
  701. codeTypeHtml = '系统二维码'
  702. } else {
  703. position.cardSetting.examinationNumberType.forEach((val, idx) => {
  704. if (idx > 0) {
  705. codeTypeHtml += '、';
  706. }
  707. if (val == 1) {
  708. codeTypeHtml += '填涂考号'
  709. } else {
  710. codeTypeHtml += '条形码'
  711. }
  712. });
  713. }
  714. let cardTypeHtml = '';
  715. cardTypeHtml += position.paper;
  716. cardTypeHtml += position.cardSetting.direction == 2 ? '-竖版-' : '-横版-';
  717. cardTypeHtml += utilsJs.sectionToChinese(position.cardSetting.column) + '栏'
  718. return {
  719. codeTypeHtml,
  720. cardTypeHtml,
  721. }
  722. },
  723. getMyTpl () {
  724. // 获取我的模板
  725. let that = this;
  726. $.ajax({
  727. url: this.api.getMyTplList,
  728. method: 'GET',
  729. data: {},
  730. success: function (res) {
  731. let result = JSON.parse(res);
  732. if (result.success === 1 && result.thisTpls) {
  733. that.tplList = [];
  734. jQuery.each(result.thisTpls, function (i, item) {
  735. let tpl_data = JSON.parse(item.tpl_data)
  736. let num = parseInt(tpl_data.online_card_version && tpl_data.online_card_version.replace('.', '').replace('.', ''))
  737. if (num >= 310) {
  738. that.tplList.push(item)
  739. }
  740. })
  741. if (that.tplList.length > 0) {
  742. $('#tplListMsg').hide();
  743. } else {
  744. $('#tplListMsg').show()
  745. }
  746. $('#tplLength').html(that.tplList.length)
  747. that.renderTplList(that.tplList)
  748. }
  749. }
  750. })
  751. },
  752. renderTplList (tplList) {
  753. let html = ''
  754. tplList.forEach(value => {
  755. let val = JSON.parse(value.tpl_data)
  756. html += '<div class="tplItem">\
  757. <div class="top itemModule">\
  758. <h3>\
  759. <strong>'+ value.title + '</strong>\
  760. <div class="menu">\
  761. <strong><b></b><b></b><b></b></strong>\
  762. <i class="triangle" style="display: none;"></i>\
  763. <div class="menuList" style="display: none;">\
  764. <span class="use" data-id="65">使用</span>\
  765. <span class="preview" data-id="65">预览</span>\
  766. <span class="del" data-id="65">删除</span>\
  767. </div>\
  768. </div>\
  769. </h3>\
  770. <span>总分:'+ value.total_score + '分</span>\
  771. <span>题量:'+ value.total_topics + '小题</span>\
  772. </div>\
  773. <div class="bottom itemModule">\
  774. <h3>其他信息</h3>\
  775. <span>版式:'+ this.getCardInfo(val).cardTypeHtml + '</span>\
  776. <span>考号:'+ this.getCardInfo(val).codeTypeHtml + '</span>\
  777. </div>\
  778. </div>'
  779. })
  780. $('.tplList').html(html)
  781. },
  782. setReuseCard (data) {
  783. // 复用答题卡
  784. let that = this;
  785. $.ajax({
  786. url: this.api.reuseCardApi,
  787. method: 'POST',
  788. data: data,
  789. success: function (data) {
  790. if (JSON.parse(data).status == 1) {
  791. layer.msg(JSON.parse(data).msg);
  792. that.getCardList()
  793. } else {
  794. layer.msg(JSON.parse(data).msg);
  795. }
  796. }
  797. })
  798. },
  799. setHideCard (id, isHide) {
  800. // 隐藏答题卡
  801. let that = this;
  802. $.ajax({
  803. url: this.api.hideCard,
  804. method: 'POST',
  805. data: {
  806. multiplexId: id,
  807. isHide: isHide
  808. },
  809. success: function (data) {
  810. if (JSON.parse(data).status == 1) {
  811. layer.msg('设置成功');
  812. that.getCardList()
  813. } else {
  814. layer.msg(JSON.parse(data).msg);
  815. }
  816. }
  817. })
  818. },
  819. saveAsMyTpl (idx) {
  820. // 保存为我的模板
  821. let that = this;
  822. layer.open({
  823. title: '保存模板',
  824. area: ['350px', '200px'],
  825. content: '模板名称:<input type="text" placeholder="请输入模板名称" maxlength="20" class="layui-input" id="tplName" onkeyup="tplNameReplace(this)">'
  826. , btn: ['确定', '取消']
  827. , yes: function (index, layero) {
  828. tplTitle = $('#tplName').val();
  829. $('.hgc_inputItem .error')[tplTitle ? 'hide' : 'show']()
  830. if (tplTitle) {
  831. that.getCurPositionData(that.cardListData[idx].multiplex_id, 3, tplTitle, that.cardListData[idx].position)
  832. }
  833. layer.close(index);
  834. }
  835. });
  836. },
  837. calcQuestionsLen: function (buildQuestions, modelId) {
  838. let count = 0, score = 0;
  839. // for(let modelId in buildQuestions){
  840. if (buildQuestions[modelId].questionCreateTypeId == 17) {
  841. count = buildQuestions[modelId].questions[0].total + '选' + buildQuestions[modelId].questions[0].required;
  842. let tempTpLen = 0;
  843. buildQuestions[modelId].questions.forEach((val, i) => {
  844. if (val.smTopicLen === undefined && tempTpLen < buildQuestions[modelId].questions[0].required) {
  845. // 不是小题 && 并且不能超过选择个数
  846. tempTpLen++;
  847. score += parseFloat(buildQuestions[modelId].questions[i].fullScore)
  848. } else if (i < val.smTopicLen) {
  849. score += parseFloat(val.fullScore)
  850. }
  851. });
  852. //
  853. } else {
  854. buildQuestions[modelId].questions.forEach(function (val, index) {
  855. if (val) {
  856. score += parseFloat(val.fullScore)
  857. if (!val.smallQtNo) {
  858. count++;
  859. }
  860. } else {
  861. buildQuestions[modelId].questions.splice(index, 1)
  862. }
  863. })
  864. // count += buildQuestions[modelId].questions.length
  865. }
  866. // }
  867. return { count: count, score: score };
  868. },
  869. calcTotalScore: function (buildQuestions) {
  870. let count = 0, score = 0;
  871. for (let modelId in buildQuestions) {
  872. if (buildQuestions[modelId].questionCreateTypeId == 17) {
  873. count += parseFloat(buildQuestions[modelId].questions[0].required);
  874. let tempTpLen = 0;
  875. buildQuestions[modelId].questions.forEach((val, i) => {
  876. if (val.smTopicLen === undefined && tempTpLen < buildQuestions[modelId].questions[0].required) {
  877. tempTpLen++;
  878. score += parseFloat(buildQuestions[modelId].questions[i].fullScore)
  879. } else if (i < val.smTopicLen) {
  880. score += parseFloat(val.fullScore)
  881. }
  882. });
  883. // score += parseFloat(buildQuestions[modelId].questions[0].fullScore)
  884. } else if (!modelId.includes('Text')) {
  885. buildQuestions[modelId].questions.forEach(function (val, index) {
  886. if (val) {
  887. score += parseFloat(val.fullScore)
  888. if (!val.smallQtNo) {
  889. count++;
  890. }
  891. } else {
  892. buildQuestions[modelId].questions.splice(index, 1)
  893. }
  894. })
  895. // count += buildQuestions[modelId].questions.length
  896. }
  897. }
  898. return { count: count, score: score };
  899. },
  900. searchToObject () {
  901. //location.search 转成 key:value格式
  902. var pairs = window.location.search.substring(1).split("&"),
  903. obj = {},
  904. pair,
  905. i;
  906. for (i in pairs) {
  907. if (pairs[i] === "") continue;
  908. pair = pairs[i].split("=");
  909. obj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
  910. }
  911. return obj;
  912. },
  913. timestampToTime (timestamp) {
  914. var date = new Date(timestamp * 1000);
  915. var Y = date.getFullYear() + '-';
  916. var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  917. var D = date.getDate() + ' ';
  918. var h = date.getHours();
  919. var m = date.getMinutes();
  920. var s = date.getSeconds();
  921. return Y + this.addZero(M) + this.addZero(D) + this.addZero(h) + ':' + this.addZero(m) + ':' + this.addZero(s);
  922. },
  923. addZero (n) {
  924. return n < 10 ? '0' + n : '' + n
  925. },
  926. // numberConvert(num){
  927. // let chinese = '';
  928. // var arr = [...num.toString()];
  929. // for(var i=0;i<arr.length;i++){
  930. // switch (arr[i]) {
  931. // case '0': chinese += "零"; break;
  932. // case '1': chinese += "一" ; break;
  933. // case '2': chinese += "二" ; break;
  934. // case '3': chinese += "三" ; break;
  935. // case '4': chinese += "四" ; break;
  936. // case '5': chinese += "五" ; break;
  937. // case '6': chinese += "六" ; break;
  938. // case '7': chinese += "七" ; break;
  939. // case '8': chinese += "八" ; break;
  940. // case '9': chinese += "九" ; break;
  941. // }
  942. // }
  943. // return chinese;
  944. // }
  945. //阿拉伯数字转换为简写汉字
  946. numberConvert (Num) {
  947. for (i = Num.length - 1; i >= 0; i--) {
  948. Num = Num.replace(",", "")//替换Num中的“,”
  949. Num = Num.replace(" ", "")//替换Num中的空格
  950. }
  951. if (isNaN(Num)) { //验证输入的字符是否为数字
  952. //alert("请检查小写金额是否正确");
  953. return;
  954. }
  955. //字符处理完毕后开始转换,采用前后两部分分别转换
  956. part = String(Num).split(".");
  957. newchar = "";
  958. //小数点前进行转化
  959. for (i = part[0].length - 1; i >= 0; i--) {
  960. if (part[0].length > 10) {
  961. //alert("位数过大,无法计算");
  962. return "";
  963. }//若数量超过拾亿单位,提示
  964. tmpnewchar = ""
  965. perchar = part[0].charAt(i);
  966. switch (perchar) {
  967. case "0": tmpnewchar = "零" + tmpnewchar; break;
  968. case "1": tmpnewchar = "一" + tmpnewchar; break;
  969. case "2": tmpnewchar = "二" + tmpnewchar; break;
  970. case "3": tmpnewchar = "三" + tmpnewchar; break;
  971. case "4": tmpnewchar = "四" + tmpnewchar; break;
  972. case "5": tmpnewchar = "五" + tmpnewchar; break;
  973. case "6": tmpnewchar = "六" + tmpnewchar; break;
  974. case "7": tmpnewchar = "七" + tmpnewchar; break;
  975. case "8": tmpnewchar = "八" + tmpnewchar; break;
  976. case "9": tmpnewchar = "九" + tmpnewchar; break;
  977. }
  978. switch (part[0].length - i - 1) {
  979. case 0: tmpnewchar = tmpnewchar; break;
  980. case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
  981. case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
  982. case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
  983. case 4: tmpnewchar = tmpnewchar + "万"; break;
  984. case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "十"; break;
  985. case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "百"; break;
  986. case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "千"; break;
  987. case 8: tmpnewchar = tmpnewchar + "亿"; break;
  988. case 9: tmpnewchar = tmpnewchar + "十"; break;
  989. }
  990. newchar = tmpnewchar + newchar;
  991. }
  992. //替换所有无用汉字,直到没有此类无用的数字为止
  993. while (newchar.search("零零") != -1 || newchar.search("零亿") != -1 || newchar.search("亿万") != -1 || newchar.search("零万") != -1) {
  994. newchar = newchar.replace("零亿", "亿");
  995. newchar = newchar.replace("亿万", "亿");
  996. newchar = newchar.replace("零万", "万");
  997. newchar = newchar.replace("零零", "零");
  998. }
  999. //替换以“一十”开头的,为“十”
  1000. if (newchar.indexOf("一十") == 0) {
  1001. newchar = newchar.substr(1);
  1002. }
  1003. //替换以“零”结尾的,为“”
  1004. if (newchar.lastIndexOf("零") == newchar.length - 1) {
  1005. newchar = newchar.substr(0, newchar.length - 1);
  1006. }
  1007. return newchar;
  1008. }
  1009. }