123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- String.prototype.substitute = function(data) {
- if (data && typeof(data) == 'object') {
- return this.replace(/\{([^{}]+)\}/g, function(match, key) {
- var value = data[key];
- return (value !== undefined) ? '' + value: '';
- });
- } else {
- return this.toString();
- }
- }
- window.hgc_downLoadModel = {
- /**
- *
- * @param {paramData} paramData
- * 考试名称
- * 可选择下载的班级数据 & 不可选择下载的班级数据
- * 学情分析报告数据
- * 总分段人数分析表数据
- */
- init:function(paramData){
- this.initData(paramData.renderData);
- this.renderPage();
- this.bindEvent();
- this.initPageBehavior();
- this.submitCb = paramData.submitCb;
- this.cancelCb = paramData.cancelCb;
- this.closeCb = paramData.closeCb;
- },
- tpls:{
- scorePartTpl:'<li class="scoreItem">\
- <input type="number" value="{score}" data-index="{index}">\
- <label>-</label>\
- </li>',
- scorePartZeroTpl:'<li class="scoreItem last">\
- <input type="text" value="0" disabled>\
- </li>',
- examAllClassTpl:'<li class="checkItem checkAll exam">\
- <input type="checkbox" name="" id="downItem">\
- <label for="downItem">全部</label>\
- </li>',
- examItemTpl:'<li class="checkItem exam" data-index="{index}">\
- <input type="checkbox" name="" id="downItem{index}">\
- <label for="downItem{index}">{className}</label>\
- </li>',
- examNoSelTpl:'<li class="checkItem checkAll">\
- <input type="checkbox" name="" disabled>\
- <label>{className}</label>\
- </li>'
- },
- initData:function(data){
- this.$downLoadBg = $('.hgc_downLoadBg').show();
- //最大分数段
- this.maxScore = data.scorePart[0];
- this.examTitle = data.examTitle;
- //去除最后以为补0
- this.scorePart = data.scorePart.reverse().splice(1).reverse();
- //1 word 2excel 3 教师讲案 4 错题文档
- this.downType = 1;
- this.formatIsDownLoad(data.class);
-
- this.examClassCanSel = this.classReportDownLoadForType['word'].canSel || [];
- this.examClassNoSel = this.classReportDownLoadForType['word'].noSel || [];
- /**
- contain_student_card 系统准考证0否,1是
- contain_school_student_card 是否包含学校准考证:0否,1是',
- contain_id_card 是否包含身份证:0否,1是'
- filter_outer 过滤外校生:0不过滤,1过滤',
- */
-
- this.analysisData = {
- containStudentCard:0,
- containSchoolStudentSard:0,
- containIdCard:0,
- filterOuter:0
- }
- this.analysisKeyMap = {
- 0:'containStudentCard',
- 1:'containSchoolStudentSard',
- 2:'filterOuter',
- 3:'containIdCard'
- }
- this.examSel = [];
- this.analysisSel = []
- },
- //班级文档是否可以下载根据类型
- //word excel error teacher
- formatIsDownLoad:function(classList){
- var self = this;
- self.classReportDownLoadForType = {
- word:{
- canSel:[],
- noSel:[]
- },
- excel:{
- canSel:[],
- noSel:[]
- },
- error:{
- canSel:[],
- noSel:[]
- },
- teacher:{
- canSel:[],
- noSel:[]
- }
- };
- classList.forEach(function(curClass){
- for(var type in self.classReportDownLoadForType){
- if(curClass[type]){
- self.classReportDownLoadForType[type].canSel.push(curClass)
- }else{
- self.classReportDownLoadForType[type].noSel.push(curClass)
- }
- }
- })
- console.log(self.classReportDownLoadForType)
- },
- initPageBehavior:function(){
- //选择报表重置
- $('#reportList li').eq(0).children('input').trigger('click');
- //学情分析报告重置
- var analysis = $('.checkAll.analysis input');
- if(analysis.prop('checked')){
- analysis.trigger('click')
- }else{
- analysis.trigger('click').trigger('click');
- }
- },
- renderPage:function(){
- this.renderTitle()
- this.renderScore();
- this.renderExamClass();
- },
- renderTitle:function(){
- $('#hgc_examTitle').html(this.examTitle)
- },
- renderScore:function(){
- var self = this;
- var scoreHtml = this.scorePart.reduce(function(scorePartHtml,score,index){
- scorePartHtml += self.tpls.scorePartTpl.substitute({score:score,index:index})
- return scorePartHtml;
- },'')
- $('#scoreList').html(scoreHtml+self.tpls.scorePartZeroTpl)
- },
- renderExamClass:function(){
- var self = this;
- var examClassHtml = self.examClassCanSel.reduce(function(examHtml,item,index){
- var obj = $.extend(item,{index:index})
- examHtml+=self.tpls.examItemTpl.substitute(obj);
- return examHtml;
- },self.tpls.examAllClassTpl)
- $('#examCanSelClass').html(examClassHtml);
- var examNoSelHtml = self.examClassNoSel.reduce(function(htmlStr,item){
- htmlStr += self.tpls.examNoSelTpl.substitute(item);
- return htmlStr;
- },'')
- $('#examNoSelClass').html(examNoSelHtml)
- },
- reduceScorePart:function(){
- var self = this;
- var scorePartLength = self.scorePart.length;
- if(scorePartLength <= 2)return;
- self.scorePart = self.scorePart.splice(0,self.scorePart.length-1);
- self.renderScore()
- },
- addScorePart:function(){
- var self = this;
- var scorePartLength = self.scorePart.length;
- if(scorePartLength >= 10)return;
- self.scorePart.push('');
- self.renderScore()
- },
- clearScroePart:function(){
- var self = this;
- self.scorePart = self.scorePart.map(function(){
- return '';
- })
- self.renderScore()
- },
- hideModel:function(){
- this.$downLoadBg.hide()
- },
- //根据选择报表类型 更新选择考试班级模块
- updateCanSelExamClass:function(type){
- var self = this;
- self.examClassCanSel = self.classReportDownLoadForType[type].canSel || [];
- self.examClassNoSel = self.classReportDownLoadForType[type].noSel || [];
- self.examSel = [];
- self.renderExamClass();
- },
- bindEvent:function(){
- var self = this;
- //选择考试名称对应生成不同的表格
- var studyAnalysisEl = $('#fieldItemEW');
- var scoreAnalysisEL = $('#fieldItemE');
- scoreAnalysisEL.hide();
- $('#reportList li').unbind().click(function () {
- var fieldItem = $(this).attr('data-item');
- self.downType = $(this).index()+1;
- //更新考试班级模块
- self.updateCanSelExamClass(fieldItem)
- //教师讲案 错题文档,没有学情分析和分段人数分析
- if(~'error|teacher'.indexOf(fieldItem)){
- studyAnalysisEl.hide();
- scoreAnalysisEL.hide();
- }
- //word
- if(fieldItem === 'word'){
- scoreAnalysisEL.hide()
- studyAnalysisEl.show();
- }
- //excel
- if(fieldItem === 'excel'){
- studyAnalysisEl.show();
- scoreAnalysisEL.show();
- }
- })
- //选择 全选-单选
- $('.checkList').off('click').on('click','.checkItem',function(){
- var checkListEl = $(this).parent();
- var checkIputList = checkListEl.find('input');
- var checkStatus = $(this).find('input').prop('checked');
- //是否为选择班级模块
- var isExam = $(this).hasClass('exam');
- if($(this).hasClass('checkAll')){
- //通过全部控制单个
- checkIputList.prop('checked',checkStatus);
-
- if(isExam){
- self.examSel = checkStatus?self.examClassCanSel:[];
- }else{
- //改变所有选择学情分析报告数据的状态
- for(var key in self.analysisData){
- self.analysisData[key] = checkStatus?1:0;
- }
- }
- }else{
- var checkedCount = 0;
- var _index = +$(this).attr('data-index');
- checkIputList.each(function(index,el){
- if(!$(el).parent().hasClass('checkAll') && $(el).prop('checked')){
- checkedCount+=1;
- }
- })
- var isAllChecked = checkedCount >= checkIputList.length-1;
- //通过单个控制全部
- checkListEl.find('.checkAll input').prop('checked',isAllChecked)
- if(checkStatus){
- if(isExam){
- self.examSel.push(self.examClassCanSel[_index]);
- }else{
- self.analysisData[self.analysisKeyMap[_index]] = 1;
- }
- }else{
- if(isExam){
- var index = self.examSel.filter(function(item,index){
- if(item.id === self.examClassCanSel[_index].id){
- return index;
- }
- })[0];
- self.examSel.splice(index,1);
- }else{
- self.analysisData[self.analysisKeyMap[_index]] = 0;
- }
- }
- }
- })
- //分段人数分析
- //点击操作按钮
- $('.scoreOperator .operator .hBtn').unbind().click(function(){
- if($(this).hasClass('btnReduce')){
- self.reduceScorePart()
- }else if($(this).hasClass('btnAdd')){
- self.addScorePart()
- }else{
- self.clearScroePart()
- }
- })
- //文本框操作
- $('#scoreList').off('blur').on('blur','input',function(){
- var _index = +$(this).attr('data-index');
- var val = +$(this).val();
- if(
- val <= 0 ||
- (self.scorePart[_index+1] && val <= self.scorePart[_index+1]) ||
- (self.scorePart[_index-1] && val >= self.scorePart[_index-1]) ||
- val >= self.maxScore
- )
- {
- layer.msg('分段数值设置不正确,请重新输入')
- $(this).val(self.scorePart[_index]);
- }else{
- self.scorePart[_index] = val;
- }
- })
- //提交操作
- $('#submitBtns .submitBtn').unbind('click').click(function(){
- if($(this).hasClass('ensure')){
- var scorePart = $.extend([],self.scorePart,true)
- scorePart.push(0);
- self.submitCb(self.downType,self.examSel,self.analysisData,scorePart)
- }else{
- self.cancelCb && self.cancelCb();
- }
- })
- $('.hgc_downLoadBg .close').unbind('click').click(function(){
- self.closeCb && self.closeCb();
- })
- }
- }
- window.hgc_downProgress = {
- init:function(data,cb){
- /**
- * [{
- * examName:'fdasf',
- * task:[{
- *
- * }]
- *
- * }]
- *
- */
- this.listData = this.formatData(data.listData);
- this.cb = cb;
- this.render();
- this.initDom();
- this.bindEvent();
- },
- tpls:{
- examItemTpl:'<li class="examItem">\
- <div class="itemLeft">\
- <h3><input type="checkbox" data-index="{index}" /> {examName}</h3>\
- <div class="examProcess">\
- <em>{downFormat}:</em>\
- <strong>\
- {completedStatus}({count}个)\
- <span class="model">\
- <span class="modelContent">{classList}</span>\
- </span>\
- </strong>\
- </div>\
- </div>\
- {itemRight}\
- </li>',
- examItemRightTpl:'<li class="examItem">\
- <div class="itemLeft">\
- <h3><input type="checkbox" data-index="{index}" /> {examName}</h3>\
- <div class="examProcess">\
- <em>{downFormat}:</em>\
- <strong>\
- {completedStatus}({count}个)\
- <span class="model">\
- <span class="modelContent">{classList}</span>\
- </span>\
- </strong>\
- </div>\
- </div>\
- <div class="itemRight">\
- <a class="button" href="{zipUrl}">下载</a>\
- </div>\
- </li>',
- emptyDownloadTaskTpl:'<li class="emptyTask"><p>暂无下载任务</p></li>'
- },
- formatData:function(data){
- var resultData = []
- for(var i=0,ilen=data.length;i<ilen;i++){
- var examName = data[i].examName;
- var task = data[i].task;
- for(var j=0,jlen=task.length;j<jlen;j++){
- task[j].examName = examName;
- resultData.push(task[j])
- }
- }
- return resultData;
- },
- render(){
- //1word 2 excel 3教师讲案 4错题本
- var self = this;
- var data = self.listData;
- var downListHtml = '';
- //1word 2 excel 3教师讲案 4错题本
- var downloadTypeMap = {
- 1:'word',
- 2:'excel',
- 3:'教师讲案' ,
- 4:'错题前十'
- }
- var createStatusMap = {
- 1:'未生成',
- 2:'已生成',
- 3:'生成失败'
- }
- for(var i=0,ilen=data.length;i<ilen;i++){
- var item = data[i];
- var itemTpl = item.status == 2?self.tpls.examItemRightTpl:self.tpls.examItemTpl;
- item.completedStatus = createStatusMap[item.status];
- item.count = item.class.length;
- item.classList = item.class.toString();
- item.index = i;
- item.downFormat = downloadTypeMap[item.downloadType];
- downListHtml+=itemTpl.substitute(item)
- }
- if(!downListHtml)downListHtml = self.tpls.emptyDownloadTaskTpl;
- $('#hgc_examList').html(downListHtml);
-
- },
- initDom:function(){
- this.$processBg = $('.hgc_downProcessBg').show();
- this.$editBtnArea = $('#btnsEdit');
- this.$btnsOperatorArea = $('#btnsOperator')
- this.$checkBox = $('.hgc_downProcess .processContent input');
- },
- isAllChecked:function(){
- var self = this;
- var checkedCount = 0;
- self.$checkBox.each(function(index,el){
- if($(el).prop('checked')){
- checkedCount++;
- }
- })
- return checkedCount >= self.$checkBox.length;
- },
- refrush:function(ids){
- var self = this;
-
- ids.forEach(function(id){
- self.listData.forEach(function(item,index){
- if(item.id === id)self.listData.splice(index,1);
- })
-
- })
- $('#btnsOperator .return').click();
- self.render();
- self.initDom();
- self.bindEvent();
- },
- bindEvent:function(){
- var self = this;
- //开始默认是否全选
- var checkAllStatus = false;
- var selDownItem = [];
- //点击编辑按钮
- $('#btnsEdit button').unbind('click').click(function(){
- self.$editBtnArea.hide();
- self.$btnsOperatorArea.show();
- self.$checkBox.show();
- })
- //点击返回按钮
- $('#btnsOperator .return').unbind('click').click(function(){
- self.$editBtnArea.show();
- self.$btnsOperatorArea.hide();
- self.$checkBox.hide()
- })
- self.$checkBox.change(function(){
- var isChecked = $(this).prop('checked');
- var _index = +$(this).attr('data-index');
- checkAllStatus = self.isAllChecked();
- if(isChecked){
- //var selItem = JSON.parse(JSON.stringify(self.listData[_index]));
- selDownItem.push(self.listData[_index])
- }else{
- var $index;
- selDownItem.some(function(v,index){
- if(self.listData[_index].id === v.id){
- $index = index;
- return;
- }
- })
- selDownItem.splice($index,1);
- }
- })
- //全选
- $('#hgc_allCheck').unbind('click').click(function(event){
- event.preventDefault();
- checkAllStatus = !checkAllStatus;
- self.$checkBox.prop('checked',checkAllStatus)
- selDownItem = checkAllStatus?$.extend([],self.listData,true):[];
- })
- $('#hgc_downDelete').unbind('click').click(function(){
- var seledIds = selDownItem.map(function(v){return v.id});
- self.cb(seledIds)
- })
- $('.hgc_downProcess .close').unbind('click').click(function(){
- self.$processBg.hide()
- })
- }
- }
- $(function () {
- false && window.hgc_downLoadModel.init({
- renderData:{
- examTitle:'考试名称',
- //选择考试班级
- class:{
- //可以下载的班级
- canSel:[{
- className:'班级1',
- id:11
- }],
- //不可下载的班级
- noSel:[{
- className:'班级4',
- id:14
- }]
- },
- //分数段
- scorePart:[105,95,85,75,65,55,45,35,25,15,0]
- },
- submitCb:function(downType,examSel,analysisSel,scorePart){
- /*
- * downType 报表类型
- * examSel 选择可下载的考试班级
- * analysisSel 选择的学情报告数据分析
- * scorePart 总分段人数分析表
- */
- console.log(scorePart)
- console.log(examSel)
- console.log(analysisSel)
- window.hgc_downLoadModel.hideModel();
- },
- cancelCb:function(){},
- closeCb:function(){}
- })
- // window.hgc_downProgress.init({
- // listData:[{
- // examName:'考试',
- // task:[{
- // //1word 2 excel 3教师讲案 4错题本
- // downloadType:1,
- // id:1212,
- // //1 生成中 2已生成
- // status:3,
- // zipUrl:'http://baidu.com1',
- // class:['一班','二班','一班','二班','一班','二班','一班','二班','一班','二班','一班','二班','一班','二班']
- // }]
- // },{
- // examName:'考试',
- // task:[{
- // //1word 2 excel 3教师讲案 4错题本
- // downloadType:1,
- // id:121223,
- // //1 生成中 2已生成
- // status:3,
- // zipUrl:'http://baidu.com1',
- // class:['一班','二班']
- // },
- // {
- // //1word 2 excel 3教师讲案 4错题本
- // downloadType:1,
- // id:121223,
- // //1 生成中 2已生成
- // status:2,
- // zipUrl:'http://baidu.com1',
- // class:['一班','二班']
- // }
- // ]
- // }]
- // },function(dels){
- // //删除的数据
- // console.log(dels)
- // //刷新弹框下载项
- // //window.hgc_downLoadModel.refrush(seledIds);
- // });
-
- })
|