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:'
\
\
\
',
scorePartZeroTpl:'\
\
',
examAllClassTpl:'\
\
\
',
examItemTpl:'\
\
\
',
examNoSelTpl:'\
\
\
'
},
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:'\
\
{examName}
\
\
{downFormat}:\
\
{completedStatus}({count}个)\
\
{classList}\
\
\
\
\
{itemRight}\
',
examItemRightTpl:'\
\
{examName}
\
\
{downFormat}:\
\
{completedStatus}({count}个)\
\
{classList}\
\
\
\
\
\
',
emptyDownloadTaskTpl:'暂无下载任务
'
},
formatData:function(data){
var resultData = []
for(var i=0,ilen=data.length;i= 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);
// });
})