down_table.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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,cb){
  21. this.initData(paramData);
  22. this.renderPage();
  23. this.bindEvent();
  24. this.cb = cb;
  25. },
  26. tpls:{
  27. scorePartTpl:'<li class="scoreItem">\
  28. <input type="number" value="{score}" data-index="{index}">\
  29. <label>-</label>\
  30. </li>',
  31. scorePartZeroTpl:'<li class="scoreItem last">\
  32. <input type="text" value="0" disabled>\
  33. </li>',
  34. examAllClassTpl:'<li class="checkItem checkAll exam">\
  35. <input type="checkbox" name="" id="downItem">\
  36. <label for="downItem">全部</label>\
  37. </li>',
  38. examItemTpl:'<li class="checkItem exam" data-index="{index}">\
  39. <input type="checkbox" name="" id="downItem{index}">\
  40. <label for="downItem{index}">{className}</label>\
  41. </li>',
  42. examNoSelTpl:'<li class="checkItem checkAll">\
  43. <input type="checkbox" name="" disabled>\
  44. <label>{className}</label>\
  45. </li>'
  46. },
  47. initData:function(data){
  48. //去除最后以为补0
  49. this.scorePart = data.scorePart.reverse().splice(1).reverse();
  50. //0 word 1excel 2 教师讲案 3 错题文档
  51. this.downType = 0;
  52. this.examClassCanSel = data.class.canSel;
  53. this.examClassNoSel = data.class.noSel;
  54. this.analysisData = [{
  55. analysisName:'系统准考证',
  56. id:10
  57. },{
  58. analysisName:'学校准考证',
  59. id:11
  60. },{
  61. analysisName:'只显示在籍生',
  62. id:12
  63. },{
  64. analysisName:'身份证',
  65. id:13
  66. }]
  67. this.examSel = [];
  68. this.analysisSel = []
  69. },
  70. renderPage:function(){
  71. this.renderScore();
  72. this.renderExamClass();
  73. },
  74. renderScore:function(){
  75. var self = this;
  76. var scoreHtml = this.scorePart.reduce(function(scorePartHtml,score,index){
  77. scorePartHtml += self.tpls.scorePartTpl.substitute({score:score,index:index})
  78. return scorePartHtml;
  79. },'')
  80. $('#scoreList').html(scoreHtml+self.tpls.scorePartZeroTpl)
  81. },
  82. renderExamClass:function(){
  83. var self = this;
  84. var examClassHtml = self.examClassCanSel.reduce(function(examHtml,item,index){
  85. var obj = $.extend(item,{index:index})
  86. examHtml+=self.tpls.examItemTpl.substitute(obj);
  87. return examHtml;
  88. },self.tpls.examAllClassTpl)
  89. $('#examCanSelClass').html(examClassHtml);
  90. var examNoSelHtml = self.examClassNoSel.reduce(function(htmlStr,item){
  91. htmlStr += self.tpls.examNoSelTpl.substitute(item);
  92. return htmlStr;
  93. },'')
  94. $('#examNoSelClass').html(examNoSelHtml)
  95. },
  96. reduceScorePart:function(){
  97. var self = this;
  98. var scorePartLength = self.scorePart.length;
  99. if(scorePartLength <= 2)return;
  100. self.scorePart = self.scorePart.splice(0,self.scorePart.length-1);
  101. self.renderScore()
  102. },
  103. addScorePart:function(){
  104. var self = this;
  105. var scorePartLength = self.scorePart.length;
  106. if(scorePartLength >= 10)return;
  107. self.scorePart.push('');
  108. self.renderScore()
  109. },
  110. clearScroePart:function(){
  111. var self = this;
  112. self.scorePart = self.scorePart.map(function(){
  113. return '';
  114. })
  115. self.renderScore()
  116. },
  117. bindEvent:function(){
  118. var self = this;
  119. //选择考试名称对应生成不同的表格
  120. var studyAnalysisEl = $('#fieldItemEW');
  121. var scoreAnalysisEL = $('#fieldItemE');
  122. scoreAnalysisEL.hide();
  123. $('#reportList li').click(function () {
  124. var fieldItem = $(this).attr('data-item');
  125. this.downType = $(this).index();
  126. //教师讲案 错题文档,没有学情分析和分段人数分析
  127. if(~'error|teacher'.indexOf(fieldItem)){
  128. studyAnalysisEl.hide();
  129. scoreAnalysisEL.hide();
  130. }
  131. //word
  132. if(fieldItem === 'word'){
  133. scoreAnalysisEL.hide()
  134. }
  135. //excel
  136. if(fieldItem === 'excel'){
  137. studyAnalysisEl.show();
  138. scoreAnalysisEL.show()
  139. }
  140. })
  141. //选择 全选-单选
  142. $('.checkList').on('click','.checkItem',function(){
  143. var checkListEl = $(this).parent();
  144. var checkIputList = checkListEl.find('input');
  145. var checkStatus = $(this).find('input').prop('checked');
  146. //是否为选择班级模块
  147. var isExam = $(this).hasClass('exam');
  148. if($(this).hasClass('checkAll')){
  149. //通过全部控制单个
  150. checkIputList.prop('checked',checkStatus);
  151. if(isExam){
  152. self.examSel = checkStatus?self.examClassCanSel:[];
  153. }else{
  154. self.analysisSel = checkStatus?self.analysisData:[];
  155. }
  156. }else{
  157. var checkedCount = 0;
  158. var _index = +$(this).attr('data-index');
  159. checkIputList.each(function(index,el){
  160. if(!$(el).parent().hasClass('checkAll') && $(el).prop('checked')){
  161. checkedCount+=1;
  162. }
  163. })
  164. var isAllChecked = checkedCount >= checkIputList.length-1;
  165. //通过单个控制全部
  166. checkListEl.find('.checkAll input').prop('checked',isAllChecked)
  167. if(checkStatus){
  168. self[isExam?'examSel':'analysisSel'].push(self[isExam?'examClassCanSel':'analysisData'][_index]);
  169. }else{
  170. var index = self[isExam?'examSel':'analysisSel'].filter(function(item,index){
  171. if(item.id === self[isExam?'examClassCanSel':'analysisData'][_index].id){
  172. return index;
  173. }
  174. })[0];
  175. self[isExam?'examSel':'analysisSel'].splice(index,1);
  176. }
  177. }
  178. })
  179. //分段人数分析
  180. //点击操作按钮
  181. $('.scoreOperator .operator .btn').click(function(){
  182. if($(this).hasClass('btnReduce')){
  183. self.reduceScorePart()
  184. }else if($(this).hasClass('btnAdd')){
  185. self.addScorePart()
  186. }else{
  187. self.clearScroePart()
  188. }
  189. })
  190. //文本框操作
  191. $('#scoreList').on('blur','input',function(){
  192. var _index = +$(this).attr('data-index');
  193. var val = +$(this).val();
  194. if(
  195. val <= 0 ||
  196. (self.scorePart[_index+1] && val <= self.scorePart[_index+1]) ||
  197. (self.scorePart[_index-1] && val >= self.scorePart[_index-1])
  198. )
  199. {
  200. $(this).val(self.scorePart[_index]);
  201. }else{
  202. self.scorePart[_index] = val;
  203. }
  204. })
  205. //提交操作
  206. $('#submitBtns .submitBtn').click(function(){
  207. if($(this).hasClass('ensure')){
  208. self.cb(self.downType,self.examSel,self.analysisSel,self.scorePart)
  209. }
  210. })
  211. }
  212. }
  213. $(function () {
  214. window.hgc_downLoadModel.init({
  215. class:{
  216. canSel:[{
  217. className:'班级1',
  218. id:11
  219. },{
  220. className:'班级2',
  221. id:12
  222. },{
  223. className:'班级3',
  224. id:13
  225. }],
  226. noSel:[{
  227. className:'班级4',
  228. id:14
  229. },{
  230. className:'班级5',
  231. id:15
  232. },{
  233. className:'班级6',
  234. id:16
  235. }]
  236. },
  237. analysis:[
  238. {
  239. className:'班级8',
  240. id:18
  241. },{
  242. className:'班级9',
  243. id:19
  244. },{
  245. className:'班级10',
  246. id:100
  247. }
  248. ],
  249. scorePart:[105,95,85,75,65,55,45,35,25,15,0]
  250. },function(downType,examSel,analysisSel,scorePart){
  251. /**
  252. * downType 报表类型
  253. * examSel 选择可下载的考试班级
  254. * analysisSel选择的学情报告数据分析
  255. * scorePart 总分段人数分析表
  256. */
  257. console.log(scorePart)
  258. console.log(examSel)
  259. console.log(analysisSel)
  260. })
  261. })