batch.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. String.prototype.substitute = function(data) {
  2. if (data && typeof(data) == 'object') {
  3. return this.replace(/\{([^{}]+)\}/g, function(match, key) {
  4. var value = data[key];
  5. return (value !== undefined) ? '' + value: '';
  6. });
  7. } else {
  8. return this.toString();
  9. }
  10. }
  11. window.hgc_downLoadModel = {
  12. /**
  13. *
  14. * @param {paramData} paramData
  15. * 考试名称
  16. * 可选择下载的班级数据 & 不可选择下载的班级数据
  17. * 学情分析报告数据
  18. * 总分段人数分析表数据
  19. */
  20. init:function(paramData){
  21. this.initData(paramData.renderData);
  22. this.renderPage();
  23. this.bindEvent();
  24. this.initPageBehavior();
  25. this.submitCb = paramData.submitCb;
  26. this.cancelCb = paramData.cancelCb;
  27. this.closeCb = paramData.closeCb;
  28. },
  29. tpls:{
  30. scorePartTpl:'<li class="scoreItem">\
  31. <input type="number" value="{score}" data-index="{index}">\
  32. <label>-</label>\
  33. </li>',
  34. scorePartZeroTpl:'<li class="scoreItem last">\
  35. <input type="text" value="0" disabled>\
  36. </li>',
  37. examAllClassTpl:'<li class="checkItem checkAll exam">\
  38. <input type="checkbox" name="" id="downItem">\
  39. <label for="downItem">全部</label>\
  40. </li>',
  41. examItemTpl:'<li class="checkItem exam" data-index="{index}">\
  42. <input type="checkbox" name="" id="downItem{index}">\
  43. <label for="downItem{index}">{className}</label>\
  44. </li>',
  45. examNoSelTpl:'<li class="checkItem checkAll">\
  46. <input type="checkbox" name="" disabled>\
  47. <label>{className}</label>\
  48. </li>'
  49. },
  50. initData:function(data){
  51. this.$downLoadBg = $('.hgc_downLoadBg').show();
  52. //最大分数段
  53. this.maxScore = data.scorePart[0];
  54. this.examTitle = data.examTitle;
  55. //去除最后以为补0
  56. this.scorePart = data.scorePart.reverse().splice(1).reverse();
  57. //1 word 2excel 3 教师讲案 4 错题文档
  58. this.downType = 1;
  59. this.formatIsDownLoad(data.class);
  60. this.examClassCanSel = this.classReportDownLoadForType['word'].canSel || [];
  61. this.examClassNoSel = this.classReportDownLoadForType['word'].noSel || [];
  62. /**
  63. contain_student_card 系统准考证0否,1是
  64. contain_school_student_card 是否包含学校准考证:0否,1是',
  65. contain_id_card 是否包含身份证:0否,1是'
  66. filter_outer 过滤外校生:0不过滤,1过滤',
  67. */
  68. this.analysisData = {
  69. containStudentCard:0,
  70. containSchoolStudentSard:0,
  71. containIdCard:0,
  72. filterOuter:0
  73. }
  74. this.analysisKeyMap = {
  75. 0:'containStudentCard',
  76. 1:'containSchoolStudentSard',
  77. 2:'filterOuter',
  78. 3:'containIdCard'
  79. }
  80. this.examSel = [];
  81. this.analysisSel = []
  82. },
  83. //班级文档是否可以下载根据类型
  84. //word excel error teacher
  85. formatIsDownLoad:function(classList){
  86. var self = this;
  87. self.classReportDownLoadForType = {
  88. word:{
  89. canSel:[],
  90. noSel:[]
  91. },
  92. excel:{
  93. canSel:[],
  94. noSel:[]
  95. },
  96. error:{
  97. canSel:[],
  98. noSel:[]
  99. },
  100. teacher:{
  101. canSel:[],
  102. noSel:[]
  103. }
  104. };
  105. classList.forEach(function(curClass){
  106. for(var type in self.classReportDownLoadForType){
  107. if(curClass[type]){
  108. self.classReportDownLoadForType[type].canSel.push(curClass)
  109. }else{
  110. self.classReportDownLoadForType[type].noSel.push(curClass)
  111. }
  112. }
  113. })
  114. console.log(self.classReportDownLoadForType)
  115. },
  116. initPageBehavior:function(){
  117. //选择报表重置
  118. $('#reportList li').eq(0).children('input').trigger('click');
  119. //学情分析报告重置
  120. var analysis = $('.checkAll.analysis input');
  121. if(analysis.prop('checked')){
  122. analysis.trigger('click')
  123. }else{
  124. analysis.trigger('click').trigger('click');
  125. }
  126. },
  127. renderPage:function(){
  128. this.renderTitle()
  129. this.renderScore();
  130. this.renderExamClass();
  131. },
  132. renderTitle:function(){
  133. $('#hgc_examTitle').html(this.examTitle)
  134. },
  135. renderScore:function(){
  136. var self = this;
  137. var scoreHtml = this.scorePart.reduce(function(scorePartHtml,score,index){
  138. scorePartHtml += self.tpls.scorePartTpl.substitute({score:score,index:index})
  139. return scorePartHtml;
  140. },'')
  141. $('#scoreList').html(scoreHtml+self.tpls.scorePartZeroTpl)
  142. },
  143. renderExamClass:function(){
  144. var self = this;
  145. var examClassHtml = self.examClassCanSel.reduce(function(examHtml,item,index){
  146. var obj = $.extend(item,{index:index})
  147. examHtml+=self.tpls.examItemTpl.substitute(obj);
  148. return examHtml;
  149. },self.tpls.examAllClassTpl)
  150. $('#examCanSelClass').html(examClassHtml);
  151. var examNoSelHtml = self.examClassNoSel.reduce(function(htmlStr,item){
  152. htmlStr += self.tpls.examNoSelTpl.substitute(item);
  153. return htmlStr;
  154. },'')
  155. $('#examNoSelClass').html(examNoSelHtml)
  156. },
  157. reduceScorePart:function(){
  158. var self = this;
  159. var scorePartLength = self.scorePart.length;
  160. if(scorePartLength <= 2)return;
  161. self.scorePart = self.scorePart.splice(0,self.scorePart.length-1);
  162. self.renderScore()
  163. },
  164. addScorePart:function(){
  165. var self = this;
  166. var scorePartLength = self.scorePart.length;
  167. if(scorePartLength >= 10)return;
  168. self.scorePart.push('');
  169. self.renderScore()
  170. },
  171. clearScroePart:function(){
  172. var self = this;
  173. self.scorePart = self.scorePart.map(function(){
  174. return '';
  175. })
  176. self.renderScore()
  177. },
  178. hideModel:function(){
  179. this.$downLoadBg.hide()
  180. },
  181. //根据选择报表类型 更新选择考试班级模块
  182. updateCanSelExamClass:function(type){
  183. var self = this;
  184. self.examClassCanSel = self.classReportDownLoadForType[type].canSel || [];
  185. self.examClassNoSel = self.classReportDownLoadForType[type].noSel || [];
  186. self.examSel = [];
  187. self.renderExamClass();
  188. },
  189. bindEvent:function(){
  190. var self = this;
  191. //选择考试名称对应生成不同的表格
  192. var studyAnalysisEl = $('#fieldItemEW');
  193. var scoreAnalysisEL = $('#fieldItemE');
  194. scoreAnalysisEL.hide();
  195. $('#reportList li').unbind().click(function () {
  196. var fieldItem = $(this).attr('data-item');
  197. self.downType = $(this).index()+1;
  198. //更新考试班级模块
  199. self.updateCanSelExamClass(fieldItem)
  200. //教师讲案 错题文档,没有学情分析和分段人数分析
  201. if(~'error|teacher'.indexOf(fieldItem)){
  202. studyAnalysisEl.hide();
  203. scoreAnalysisEL.hide();
  204. }
  205. //word
  206. if(fieldItem === 'word'){
  207. scoreAnalysisEL.hide()
  208. studyAnalysisEl.show();
  209. }
  210. //excel
  211. if(fieldItem === 'excel'){
  212. studyAnalysisEl.show();
  213. scoreAnalysisEL.show();
  214. }
  215. })
  216. //选择 全选-单选
  217. $('.checkList').off('click').on('click','.checkItem',function(){
  218. var checkListEl = $(this).parent();
  219. var checkIputList = checkListEl.find('input');
  220. var checkStatus = $(this).find('input').prop('checked');
  221. //是否为选择班级模块
  222. var isExam = $(this).hasClass('exam');
  223. if($(this).hasClass('checkAll')){
  224. //通过全部控制单个
  225. checkIputList.prop('checked',checkStatus);
  226. if(isExam){
  227. self.examSel = checkStatus?self.examClassCanSel:[];
  228. }else{
  229. //改变所有选择学情分析报告数据的状态
  230. for(var key in self.analysisData){
  231. self.analysisData[key] = checkStatus?1:0;
  232. }
  233. }
  234. }else{
  235. var checkedCount = 0;
  236. var _index = +$(this).attr('data-index');
  237. checkIputList.each(function(index,el){
  238. if(!$(el).parent().hasClass('checkAll') && $(el).prop('checked')){
  239. checkedCount+=1;
  240. }
  241. })
  242. var isAllChecked = checkedCount >= checkIputList.length-1;
  243. //通过单个控制全部
  244. checkListEl.find('.checkAll input').prop('checked',isAllChecked)
  245. if(checkStatus){
  246. if(isExam){
  247. self.examSel.push(self.examClassCanSel[_index]);
  248. }else{
  249. self.analysisData[self.analysisKeyMap[_index]] = 1;
  250. }
  251. }else{
  252. if(isExam){
  253. var index = self.examSel.filter(function(item,index){
  254. if(item.id === self.examClassCanSel[_index].id){
  255. return index;
  256. }
  257. })[0];
  258. self.examSel.splice(index,1);
  259. }else{
  260. self.analysisData[self.analysisKeyMap[_index]] = 0;
  261. }
  262. }
  263. }
  264. })
  265. //分段人数分析
  266. //点击操作按钮
  267. $('.scoreOperator .operator .hBtn').unbind().click(function(){
  268. if($(this).hasClass('btnReduce')){
  269. self.reduceScorePart()
  270. }else if($(this).hasClass('btnAdd')){
  271. self.addScorePart()
  272. }else{
  273. self.clearScroePart()
  274. }
  275. })
  276. //文本框操作
  277. $('#scoreList').off('blur').on('blur','input',function(){
  278. var _index = +$(this).attr('data-index');
  279. var val = +$(this).val();
  280. if(
  281. val <= 0 ||
  282. (self.scorePart[_index+1] && val <= self.scorePart[_index+1]) ||
  283. (self.scorePart[_index-1] && val >= self.scorePart[_index-1]) ||
  284. val >= self.maxScore
  285. )
  286. {
  287. layer.msg('分段数值设置不正确,请重新输入')
  288. $(this).val(self.scorePart[_index]);
  289. }else{
  290. self.scorePart[_index] = val;
  291. }
  292. })
  293. //提交操作
  294. $('#submitBtns .submitBtn').unbind('click').click(function(){
  295. if($(this).hasClass('ensure')){
  296. var scorePart = $.extend([],self.scorePart,true)
  297. scorePart.push(0);
  298. self.submitCb(self.downType,self.examSel,self.analysisData,scorePart)
  299. }else{
  300. self.cancelCb && self.cancelCb();
  301. }
  302. })
  303. $('.hgc_downLoadBg .close').unbind('click').click(function(){
  304. self.closeCb && self.closeCb();
  305. })
  306. }
  307. }
  308. window.hgc_downProgress = {
  309. init:function(data,cb){
  310. /**
  311. * [{
  312. * examName:'fdasf',
  313. * task:[{
  314. *
  315. * }]
  316. *
  317. * }]
  318. *
  319. */
  320. this.listData = this.formatData(data.listData);
  321. this.cb = cb;
  322. this.render();
  323. this.initDom();
  324. this.bindEvent();
  325. },
  326. tpls:{
  327. examItemTpl:'<li class="examItem">\
  328. <div class="itemLeft">\
  329. <h3><input type="checkbox" data-index="{index}" /> {examName}</h3>\
  330. <div class="examProcess">\
  331. <em>{downFormat}:</em>\
  332. <strong>\
  333. {completedStatus}({count}个)\
  334. <span class="model">\
  335. <span class="modelContent">{classList}</span>\
  336. </span>\
  337. </strong>\
  338. </div>\
  339. </div>\
  340. {itemRight}\
  341. </li>',
  342. examItemRightTpl:'<li class="examItem">\
  343. <div class="itemLeft">\
  344. <h3><input type="checkbox" data-index="{index}" /> {examName}</h3>\
  345. <div class="examProcess">\
  346. <em>{downFormat}:</em>\
  347. <strong>\
  348. {completedStatus}({count}个)\
  349. <span class="model">\
  350. <span class="modelContent">{classList}</span>\
  351. </span>\
  352. </strong>\
  353. </div>\
  354. </div>\
  355. <div class="itemRight">\
  356. <a class="button" href="{zipUrl}">下载</a>\
  357. </div>\
  358. </li>',
  359. emptyDownloadTaskTpl:'<li class="emptyTask"><p>暂无下载任务</p></li>'
  360. },
  361. formatData:function(data){
  362. var resultData = []
  363. for(var i=0,ilen=data.length;i<ilen;i++){
  364. var examName = data[i].examName;
  365. var task = data[i].task;
  366. for(var j=0,jlen=task.length;j<jlen;j++){
  367. task[j].examName = examName;
  368. resultData.push(task[j])
  369. }
  370. }
  371. return resultData;
  372. },
  373. render(){
  374. //1word 2 excel 3教师讲案 4错题本
  375. var self = this;
  376. var data = self.listData;
  377. var downListHtml = '';
  378. //1word 2 excel 3教师讲案 4错题本
  379. var downloadTypeMap = {
  380. 1:'word',
  381. 2:'excel',
  382. 3:'教师讲案' ,
  383. 4:'错题前十'
  384. }
  385. var createStatusMap = {
  386. 1:'未生成',
  387. 2:'已生成',
  388. 3:'生成失败'
  389. }
  390. for(var i=0,ilen=data.length;i<ilen;i++){
  391. var item = data[i];
  392. var itemTpl = item.status == 2?self.tpls.examItemRightTpl:self.tpls.examItemTpl;
  393. item.completedStatus = createStatusMap[item.status];
  394. item.count = item.class.length;
  395. item.classList = item.class.toString();
  396. item.index = i;
  397. item.downFormat = downloadTypeMap[item.downloadType];
  398. downListHtml+=itemTpl.substitute(item)
  399. }
  400. if(!downListHtml)downListHtml = self.tpls.emptyDownloadTaskTpl;
  401. $('#hgc_examList').html(downListHtml);
  402. },
  403. initDom:function(){
  404. this.$processBg = $('.hgc_downProcessBg').show();
  405. this.$editBtnArea = $('#btnsEdit');
  406. this.$btnsOperatorArea = $('#btnsOperator')
  407. this.$checkBox = $('.hgc_downProcess .processContent input');
  408. },
  409. isAllChecked:function(){
  410. var self = this;
  411. var checkedCount = 0;
  412. self.$checkBox.each(function(index,el){
  413. if($(el).prop('checked')){
  414. checkedCount++;
  415. }
  416. })
  417. return checkedCount >= self.$checkBox.length;
  418. },
  419. refrush:function(ids){
  420. var self = this;
  421. ids.forEach(function(id){
  422. self.listData.forEach(function(item,index){
  423. if(item.id === id)self.listData.splice(index,1);
  424. })
  425. })
  426. $('#btnsOperator .return').click();
  427. self.render();
  428. self.initDom();
  429. self.bindEvent();
  430. },
  431. bindEvent:function(){
  432. var self = this;
  433. //开始默认是否全选
  434. var checkAllStatus = false;
  435. var selDownItem = [];
  436. //点击编辑按钮
  437. $('#btnsEdit button').unbind('click').click(function(){
  438. self.$editBtnArea.hide();
  439. self.$btnsOperatorArea.show();
  440. self.$checkBox.show();
  441. })
  442. //点击返回按钮
  443. $('#btnsOperator .return').unbind('click').click(function(){
  444. self.$editBtnArea.show();
  445. self.$btnsOperatorArea.hide();
  446. self.$checkBox.hide()
  447. })
  448. self.$checkBox.change(function(){
  449. var isChecked = $(this).prop('checked');
  450. var _index = +$(this).attr('data-index');
  451. checkAllStatus = self.isAllChecked();
  452. if(isChecked){
  453. //var selItem = JSON.parse(JSON.stringify(self.listData[_index]));
  454. selDownItem.push(self.listData[_index])
  455. }else{
  456. var $index;
  457. selDownItem.some(function(v,index){
  458. if(self.listData[_index].id === v.id){
  459. $index = index;
  460. return;
  461. }
  462. })
  463. selDownItem.splice($index,1);
  464. }
  465. })
  466. //全选
  467. $('#hgc_allCheck').unbind('click').click(function(event){
  468. event.preventDefault();
  469. checkAllStatus = !checkAllStatus;
  470. self.$checkBox.prop('checked',checkAllStatus)
  471. selDownItem = checkAllStatus?$.extend([],self.listData,true):[];
  472. })
  473. $('#hgc_downDelete').unbind('click').click(function(){
  474. var seledIds = selDownItem.map(function(v){return v.id});
  475. self.cb(seledIds)
  476. })
  477. $('.hgc_downProcess .close').unbind('click').click(function(){
  478. self.$processBg.hide()
  479. })
  480. }
  481. }
  482. $(function () {
  483. false && window.hgc_downLoadModel.init({
  484. renderData:{
  485. examTitle:'考试名称',
  486. //选择考试班级
  487. class:{
  488. //可以下载的班级
  489. canSel:[{
  490. className:'班级1',
  491. id:11
  492. }],
  493. //不可下载的班级
  494. noSel:[{
  495. className:'班级4',
  496. id:14
  497. }]
  498. },
  499. //分数段
  500. scorePart:[105,95,85,75,65,55,45,35,25,15,0]
  501. },
  502. submitCb:function(downType,examSel,analysisSel,scorePart){
  503. /*
  504. * downType 报表类型
  505. * examSel 选择可下载的考试班级
  506. * analysisSel 选择的学情报告数据分析
  507. * scorePart 总分段人数分析表
  508. */
  509. console.log(scorePart)
  510. console.log(examSel)
  511. console.log(analysisSel)
  512. window.hgc_downLoadModel.hideModel();
  513. },
  514. cancelCb:function(){},
  515. closeCb:function(){}
  516. })
  517. // window.hgc_downProgress.init({
  518. // listData:[{
  519. // examName:'考试',
  520. // task:[{
  521. // //1word 2 excel 3教师讲案 4错题本
  522. // downloadType:1,
  523. // id:1212,
  524. // //1 生成中 2已生成
  525. // status:3,
  526. // zipUrl:'http://baidu.com1',
  527. // class:['一班','二班','一班','二班','一班','二班','一班','二班','一班','二班','一班','二班','一班','二班']
  528. // }]
  529. // },{
  530. // examName:'考试',
  531. // task:[{
  532. // //1word 2 excel 3教师讲案 4错题本
  533. // downloadType:1,
  534. // id:121223,
  535. // //1 生成中 2已生成
  536. // status:3,
  537. // zipUrl:'http://baidu.com1',
  538. // class:['一班','二班']
  539. // },
  540. // {
  541. // //1word 2 excel 3教师讲案 4错题本
  542. // downloadType:1,
  543. // id:121223,
  544. // //1 生成中 2已生成
  545. // status:2,
  546. // zipUrl:'http://baidu.com1',
  547. // class:['一班','二班']
  548. // }
  549. // ]
  550. // }]
  551. // },function(dels){
  552. // //删除的数据
  553. // console.log(dels)
  554. // //刷新弹框下载项
  555. // //window.hgc_downLoadModel.refrush(seledIds);
  556. // });
  557. })