

//获取课时
function getCosKeshi(courseId,courseType){
    var $assignmentObj = $('#getCosKeshi');
    $.ajax({
        type:'get',
        dataType:'json',
        url:'/plus/ajaxs.ashx?a=getcosInfo&courseid='+courseId,
        success:function(obj){     

            //课程课时
            if(obj.Data){

                var column = obj.Data.Column;
                var columnLength = column.length;
                if(columnLength){
                    for(c=0;c<columnLength;c++){
                        var addtype = column[c].addtype;
                        //addtype 章:0  课时:1 节:2
                        var periodname = column[c].periodname;
                        var periodid = column[c].periodid;
                        var parentid = column[c].parentid;
                        var isfree = column[c].isfree;
                        var url = column[c].url.replace(new RegExp('#',"gm"),"&");
                        var zlurl = column[c].zlurl;
                        var ExamPaper = column[c].ExamPaper;
                        //章
                        if(addtype==0){
                            var result ='<div class="chapter"><div class="chapter-name">'+periodname+'</div><div class="chapter-box" data-periodid="'+periodid+'"></div></div>';

                            $assignmentObj.append(result);
                            
                        //节
                        }else if(addtype==2){
                            if(parentid!=0){
                                $assignmentObj.find('[data-periodid="'+parentid+'"]').append('<div class="section"><div class="section-name">'+periodname+'</div><div class="section-box" data-periodid="'+periodid+'"></div></div>');
                            }else{
                               
                                $assignmentObj.append('<div class="section section-z"><div class="section-name">'+periodname+'</div><div class="section-box" data-periodid="'+periodid+'"></div></div>');
                            };

                        //课时
                        }else if(addtype==1){

                            var timecount = column[c].timecount;
                            var zl = '';
                            var icon = '<i class="icon-13zhibo iconfont"></i>';
                            if(courseType=='live'){
                                icon = '<i class="icon-zhibo iconfont"></i>';
                            };
                            if(zlurl!=''){
                                zl = '<span class="zlicon"><i class="icon-jilu iconfont"></i></span><a href="'+zlurl+'" class="btn">讲义下载</a>';

                            };
                            var free = '';
                            if(isfree=='免费'){
                                free = '<span class="free">免费</span>'
                            };
                            var paperHtml = '';
                            if(ExamPaper!=null){
                                  var paperLength = ExamPaper.paper.length;
                                  for(p=0;p<paperLength;p++){
                                      var name = ExamPaper.paper[p].name;
                                      var url = ExamPaper.paper[p].url;
                                      paperHtml += '<div class="keshi-exam"><a href="'+url+'" target="_blank">【试卷】'+name+'</a></div>';
                                  };

                                  
                            };

                            if(parentid!=0){
                                $assignmentObj.find('[data-periodid="'+parentid+'"]').append('<div class="keshi">'+zl+'<a href="'+url+'" class="keshi-url" target="_blank">'+icon+''+periodname+'<span>('+timecount+')</span>'+free+'</a></div>'+paperHtml+'');
                            }else{
                                $assignmentObj.append('<div class="keshi keshi-z">'+zl+'<a href="'+url+'" class="keshi-url" target="_blank"><i class="icon-13zhibo iconfont"></i>'+periodname+'<span>('+timecount+')</span>'+free+'</a></div>'+paperHtml+'');
                            }; 

                        };

                    };
                   
                    $assignmentObj.find('.section-box').each(function(){
                        if($(this).find('.keshi').size()==0){
                            $(this).html('<div class="keshi-empty">该节下暂无课时</div>')
                        }
                    });
                }else{
                    var addtype = column.addtype;
                    //addtype 章:0  课时:1 节:2
                    var periodname = column.periodname;
                    var periodid = column.periodid;
                    var parentid = column.parentid;
                    var isfree = column.isfree;
                    var url = column.url.replace(new RegExp('#',"gm"),"&");
                    var zlurl = column.zlurl;
                    var ExamPaper = column.ExamPaper;
                    
                    //章
                    if(addtype==0){
                        var result ='<div class="chapter"><div class="chapter-name">'+periodname+'</div><div class="chapter-box" data-periodid="'+periodid+'"></div></div>';

                        $assignmentObj.append(result);
                        
                    //节
                    }else if(addtype==2){
                        
                        $assignmentObj.append('<div class="section section-z"><div class="section-name">'+periodname+'</div><div class="section-box" data-periodid="'+periodid+'"></div></div>');

                    //课时
                    }else if(addtype==1){

                        var timecount = column.timecount;
                        var zl = '';
                        var icon = '<i class="icon-13zhibo iconfont"></i>';
                        if(courseType=='live'){
                            icon = '<i class="icon-zhibo iconfont"></i>';
                        };
                        if(zlurl!=''){
                            zl = '<span class="zlicon"><i class="edufont e-icon-ziliao-copy"></i></span><a href="'+zlurl+'" class="btn">讲义下载</a>';

                        };
                        var free = '';
                        if(isfree=='免费'){
                            free = '<span class="free">免费</span>'
                        };
                        var paperHtml = '';
                        if(ExamPaper!=null){
                              var paperLength = ExamPaper.paper.length;
                              for(p=0;p<paperLength;p++){
                                  var name = ExamPaper.paper[p].name;
                                  var url = ExamPaper.paper[p].url;
                                  paperHtml += '<div class="keshi-exam"><a href="'+url+'" target="_blank">【试卷】'+name+'</a></div>';
                              };
          
                        };

                        $assignmentObj.append('<div class="keshi keshi-z">'+zl+'<a href="'+url+'" class="keshi-url" target="_blank"><i class="icon-13zhibo iconfont"></i>'+periodname+'<span>('+timecount+')</span>'+free+'</a></div>'+paperHtml+'');

                    };

                };

            }else{
                $assignmentObj.html('<div class="empty">该课程下暂无课时数据</div>');
            };
          
        },error:function(){
            $assignmentObj.find('.ajaxload').remove();
            $assignmentObj.html('<div class="empty">数据请求失败，建议重新生成课时数据</div>');
        }
    });

};