/**
* 调用组件
*/
var KS_Components = new KS_GetCompoents()
var getUserInfo = KS_Components.getUserInfo;
var addToCourseCart = KS_Components.addToCourseCart;
var gotozan = KS_Components.gotozan;
var getzan = KS_Components.getzan;
var getcollect = KS_Components.getcollect;
var collect = KS_Components.collect;
var replaceDefaultImg = KS_Components.replaceDefaultImg;
var imagesZoomIn = KS_Components.imagesZoomIn;
var getArtTemplate = KS_Components.getArtTemplate;
var popup = KS_Components.popup;
/**
* 兼容处理
*/
if (typeof replaceDefaultImgArray === 'object') {
replaceDefaultImgArray.map(function (img) {
replaceDefaultImg(img)
})
}
$(function () {
$('body').addClass('wWidth1200');
if ($.trim($('#other').find('.header-nav-sub').html()) == '') {
$('#other').hide()
} else {
$('#other').show()
}
/**获取用户登录信息 */
getUserInfo(function (res) {
var messageNum = ''
if(res.message != 0){
messageNum = res.message.toString()>99 ? '99+' : '' + res.message + '';
}
var userLink = ''
if((res.groupid == 3 || res.groupid == 4) && res.version!='saas'){
if(res.url_home.indexOf('?')>-1){
userLink = '
我是会员'
}else{
userLink = '我是会员'
}
}else{
userLink = ''
}
// var userLink = (res.groupid == 3 || res.groupid == 4) ? '我是会员' : '';
var messageUrl = (res.groupid == 3 || res.groupid == 4) ? res.url_home + '#/institutionMessage/InSiteNews' : res.url_home + '#/user/message';
var userNav = (res.groupid == 3 || res.groupid == 4) ? '' : '我的学习我的考试';
var distribution = ''
if (res.model.courseagent && !res.model.coursefx) {
distribution = '< a href="' + res.url_ag + '" target="_blank">代理合作 a>'
}
// else if (!res.model.courseagent && res.model.coursefx) {
// distribution = '< a href="' + res.url_fx + '" target="_blank">分程 a>'
// }
else if (res.model.courseagent && res.model.coursefx) {
distribution = '< a href="' + res.url_fx + '" target="_blank">分销课程 a>< a href="' + res.url_ag +
'" target="_blank">代理合作 a>'
} else {
distribution = ''
}
var str = '
' + (res.realname || res.username) + ' ';
$("#nologin").html(str);
$('.haed-user').hover(function () {
$(this).find('.u-navdropmenu').show();
}, function () {
$(this).find('.u-navdropmenu').hide();
});
var navhtml = '个人中心'
$('.header-nav ul li:last').after(navhtml)
if (typeof onGetUserInfoSuccess === 'function') {
onGetUserInfoSuccess(res)
}
}, function (res) {
var distribution = ''
if(res.model.courseagent && !res.model.coursefx){
distribution = ''
}else if(!res.model.courseagent && res.model.coursefx){
distribution = ''
}else if(res.model.courseagent && res.model.coursefx){
distribution = ''
}else{
distribution = ''
}
//用户未登录
var str = '';
$("#nologin").html(str);
var navhtml = '个人中心'
$('.header-nav ul li:last').after(navhtml)
if (typeof onGetUserInfoSuccess === 'function') {
onGetUserInfoSuccess(res)
}
});
/**
* 侧栏
*/
var asideSpeed = 200;
$(window).scroll(function () {
if ($(window).scrollTop() > 250) {
$('.aside-operate').fadeIn(asideSpeed);
} else {
$('.aside-operate').fadeOut(asideSpeed);
}
});
/**总页数未0时,隐藏分页 */
if ($('#totalrecord').text() == 0) {
$('.fenye,.paging').hide();
}
/**执行页面动画 */
pageAnimate('.page-animate')
});
//获取分类信息
var $courseTopClassbox = $('.course-top-classbox');
var $courseTopClassify = $('.course-top-classify');
$courseTopClassbox.find('.inner:first').addClass('class-show');
var classStr = '';
$courseTopClassbox.find('.inner').each(function () {
var index = $(this).index();
var title = $(this).find('.inner-title:first').text();
var childClass = ''
$(this).find('.inner-child li').each(function () {
var childText = $(this).find('.childs-title').text()
var childUrl = $(this).find('.childs-title').attr('data-url')
childClass += '' + childText + ''
});
var url = $(this).find('.inner-title').attr('data-url');
if (index == 0) {
classStr += '' + title + '' + childClass + '
';
} else {
if(index<7){
classStr += '' + title + '' + childClass + '
';
}
};
});
classStr = '';
$courseTopClassify.html(classStr);
$courseTopClassify.find('li').hover(function () {
var index = $(this).index();
$courseTopClassbox.show().find('.inner').eq(index).addClass('class-show').siblings('.inner').removeClass('class-show');
$(this).addClass('active').siblings('li').removeClass('active');
}, function () {
$courseTopClassbox.hide();
$courseTopClassify.find('li').removeClass('active');
});
$courseTopClassbox.hover(function () {
var index = $(this).find('.class-show').index();
$courseTopClassify.find('li').eq(index).addClass('active').siblings('li').removeClass('active');
$(this).show();
}, function () {
$(this).hide();
$courseTopClassify.find('li').removeClass('active');
});
//分类
var navFlag = 1;
$(".head-nav-allbtn,.course-top-classbox,.course-top-classify").mouseover(function () {
$courseTopClassify.show();
}).mouseout(function () {
if (navFlag != 0) {
$courseTopClassify.hide();
};
});
//首页课程分类
$('.content-cnt-tit').each(function () {
var $cntTitList = $(this).find('.cnt-tit-list');
var $otherList = $(this).find('.other-list');
var classStr = '';
$cntTitList.find('a').each(function () {
var index = $(this).index();
var title = $(this).find('span').text();
var url = $(this).find('span').attr('data-url');
classStr += '' + title + '';
});
classStr = '' + classStr + '
';
$otherList.html(classStr);
})
//$(window).resize(function(){
// var windowWidth = $(window).innerWidth()
// if(windowWidth <= 1600){
// $('body').removeClass('wWidth1500');
// $('body').addClass('wWidth1200');
// $('.content_outer .content_1').width(959);
// }else{
// $('body').removeClass('wWidth1200');
// $('body').addClass('wWidth1500');
// $('.content_outer .content_1').width(1259);
// }
//}).resize();
function setNavFlag(i) {
$courseTopClassify.show();
navFlag = i;
};
//评分计算
function coursePfCount(obj) {
$(obj).each(function () {
var pfVal = $(this).attr('data-pf');
var starWidth = $(this).find('.star').width();
var mean = starWidth / 5;
var scoreWidth = mean * pfVal;
$(this).find('.star-on').width(scoreWidth);
});
};
//得到event事件
function getEvent() {
if (window.event) { return window.event; }
func = getEvent.caller;
while (func != null) {
var arg0 = func.arguments[0];
if (arg0) {
if ((arg0.constructor == Event || arg0.constructor == MouseEvent
|| arg0.constructor == KeyboardEvent)
|| (typeof (arg0) == "object" && arg0.preventDefault
&& arg0.stopPropagation)) {
return arg0;
}
}
func = func.caller;
}
return null;
};
//阻止冒泡
function cancelBubble() {
var e = getEvent();
if (window.event) {
//e.returnValue=false;//阻止自身行为
e.cancelBubble = true;//阻止冒泡
} else if (e.preventDefault) {
//e.preventDefault();//阻止自身行为
e.stopPropagation();//阻止冒泡
}
};
function goTop() {
$('html,body').animate({ scrollTop: 0 }, 300);
};
/**
* 执行页面动画
* @param el dom对象
*/
function pageAnimate(el) {
$(el).each(function () {
var ofTop = $(this).offset().top - $(window).height();
var maxTop = $(this).offset().top + $(this).outerHeight();
var type = $(this).attr('data-type') || 'fadeInUp';
var $that = $(this);
var delay = $that.attr('data-delay');
if (delay) {
$that.css({ animationDelay: delay + 's' });
};
$(window).scroll(function () {
if ($(window).scrollTop() > ofTop && $(window).scrollTop() < maxTop) {
$that.removeClass('page-animate').addClass('animated ' + type);
if ($that.find('.page-timer').length != 0) {
$that.find('.page-timer').each(count);
}
}
}).scroll();
});
}
/**
* 获取个性化兴趣标签列表
* @param myLabel 我选择的兴趣标签
*/
function getLableList(myLabel) {
myLabel = myLabel || []
var getUrl = '/webapi/user/GetLable'
var LableListHtml = ''
$.ajax({
type: 'get',
dataType: 'json',
url: getUrl,
success: function (res) {
if (res.list && res.list.length) {
res.list.map(function (item) {
var selected = '';
myLabel.map(function (label) {
if (label.TagsID == item.TagsID) {
selected = ' class="curr"'
}
})
LableListHtml += '' + item.KeyText + ''
})
}
var selected = '';
myLabel.map(function (label) {
selected += '' + label.KeyText + '×';
});
$('.selected-class').html(selected);
$('.all-class-select ul').html(LableListHtml);
$('.all-class-select li').click(function () {
$(this).toggleClass('curr');
var class_text = $(this).text();
var tagsID = $(this).attr('data-id');
if ($(this).attr('class') == 'curr') {
$('.selected-class').append('' + class_text + '×')
} else {
closeSelectClass(tagsID)
}
countClassNum()
});
countClassNum()
},
error: function () {
var msg = '数据请求失败了,程序员正在抢修中...';
$('.all-class-select ul').html('' + msg + '
')
}
});
}
/**
* 重新计算兴趣标签数量
*/
function countClassNum() {
var num = $('.selected-class a').length
$('.selected-num font').text(num)
if (num == 0) {
$('.selected-button').removeClass('curr')
} else {
$('.selected-button').addClass('curr')
}
}
/**
* 删除标签
* @param tagsID 标签id
*/
function closeSelectClass(tagsID) {
$('.selected-class a').each(function () {
if ($(this).attr('data-id') == tagsID) {
$(this).remove()
}
});
$('.all-class-select li').each(function () {
if ($(this).attr('data-id') == tagsID) {
$(this).removeClass('curr')
}
});
countClassNum()
}
/**
* 更新我兴趣的标签
*/
function updateInterestTags(el) {
KS_Utils.getUserAppToken(function (apptoken) {
var $el = $(el);
var $selected = $el.find('li.curr');
var ids = [];
$selected.each(function () {
ids.push($(this).attr('data-id'));
});
ids = ids.join();
$.post('/webapi/user/UpdateLable', {
apptoken: apptoken,
tagsids: ids
}, function (res) {
if (res.result) {
closeClass();
getInterestCourse();
} else {
KesionJS.Alert(res.msg)
}
}, 'json')
})
}
/**
* 打开兴趣课程选择窗口
*/
function selectClass() {
$('body').addClass('no-scroll')
$('.all-class').fadeIn()
$('.all-class-bg').fadeIn()
}
/**
* 关闭兴趣课程选择窗口
*/
function closeClass() {
$('body').removeClass('no-scroll')
$('.all-class').fadeOut()
$('.all-class-bg').fadeOut()
}
/**
* 获取我的兴趣课程
*/
function getInterestCourse(isLoadLabelList) {
KS_Utils.getUserAppToken(function (apptoken) {
$('#my-interest-course').html('
');
$.post('/webapi/user/GetUserLable', {
apptoken: apptoken
}, function (res) {
if (res.result) {
if(isLoadLabelList){
getLableList(res.Lablelist);
}
getArtTemplate(function (template) {
var templateStr = '{{each Lablelist label i}}' +
' {{if(label.Couselist && label.Couselist.length)}}' +
' ' +
'
{{label.KeyText}}more >
' +
'
' +
' {{each label.Couselist item index}}' +
' {{if index < 4}}' +
' - ' +
'
' +
' {{if(item.Promotion_Text)}}'+
'
{{item.Promotion_Text}}' +
' {{/if}}'+
'
' +
'

' +
'
' +
'
' +
'
{{item.Name}}
' +
'
{{item.Intro}}
' +
'
' +
' {{if(item.Price_Member == \'0.00\')}}'+
' 免费' +
' {{else}}'+
' ¥{{item.Price_Member}}'+
' {{/if}}'+
' {{item.StudentNum}}人学习' +
'
' +
'
' +
'
' +
' ' +
' {{/if}}' +
' {{/each}}' +
'
' +
'
' +
'{{/if}}' +
'{{/each}}';
var render = template.compile(templateStr);
res.Lablelist.map(function (item) {
if (item.Couselist && item.Couselist.length) {
item.Couselist.map(function (cos) {
if(cos.Intro){
cos.Intro = cos.Intro.replace(/\<[^>]+\>/g,'')
}
switch(Number(cos.Promotion)){
case 1:
cos.Promotion_Text = '限时抢购';
break
case 2:
cos.Promotion_Text = '课程团购';
break
case 3:
cos.Promotion_Text = '积分兑换';
break
case 4:
cos.Promotion_Text = '混合课程';
break
}
cos.Price_Member = Number(cos.Price_Member).toFixed(2)
})
}
})
var list = render(res);
$('#my-interest-course').html(list);
})
}else{
$('#my-interest-course').html('');
if(isLoadLabelList){
getLableList();
}
}
if(res.Lablelist && res.Lablelist.length){
$('#select-tag').html('');
}else{
$('#my-interest-course').parent('.floor').remove();
$('#select-tag').html('');
}
})
})
}