require([‘jquery’, ‘cookies’, ‘common/alertLogin’, ‘common/ficfn’, ‘urlUtil’, ‘common/utils/request’], function($, cookies, alertLogin, ficfn, urlUtil, loadAjax) {
/阻止内部元素的鼠标滚动事件冒泡/
$.fn.preventScroll = function () {
var _this = this.get(0);
if (typeof _this.onmousewheel === “undefined”) {
_this.addEventListener(‘DOMMouseScroll’, function (e) {
_this.scrollTop += e.detail > 0 ? 60 : -60;
e.preventDefault();
}, false);
} else if(typeof _this.onmousewheel === “object”){
_this.onmousewheel = function (e) {
e = e || window.event;
_this.scrollTop += e.wheelDelta > 0 ? -60 : 60;
e.preventDefault ? e.preventDefault() : e.returnValue = false;
};
}
return this;
};
/**END/
$.fn.loadHeader = function(options) {
var defaults = {
loadUrl: ‘/trans/page/base/top-header.html?t’ + (new Date()).getTime()
};
var settings = $.extend({}, defaults, options);
var topHeader = new TopHeader(settings);
topHeader.init();
createLink();
}
var TopHeader = function(settings) {
function init() {
$("#topHeader").load(settings.loadUrl, function() {
bindEvents();
loadNav();
});
}
function loadNav() {
var tabmodule = urlUtil.getParameter("tabmodule");
var pathName = window.location.pathname;
var NEED_SUBHEADER_ARR = ['trans', 'fof', 'bill'];
if(NEED_SUBHEADER_ARR.indexOf(pathName.split('/')[1]) > -1 || pathName.indexOf('/insuranceStreet/') > -1) {
$('.sub_header').show();
}
var timer = setInterval(function() {
if(cookies.get('username')) {
clearInterval(timer);
$('#topUserName').html(cookies.get('username'));
$('#toplogin, #topRegister').hide();
$('#toploginOut, #toplogined').show();
/**金融MALL,且已开店,且是管理员或者店铺运营人员,展示商家后台下拉选项**/
pathName.indexOf('/web/') > -1 && queryShopExist();
}
}, 500)
if (pathName.indexOf('/trans/') > -1 && pathName.indexOf('/lobby/') > -1) {
$('#toplobbyAcct').show();
$('.sub_header').addClass('lobby_sub_header');
if (tabmodule === 'quotation') {//报价大厅头
$('#toplobbyAcct a').html('报价大厅账户管理');
$('.header_nav li').removeClass('current');
$('.header_nav li.quotation').addClass('current');
} else {//产品大厅头
$('#toplobbyAcct a').html('产品大厅账户管理');
$('.header_nav li').removeClass('current');
$('.header_nav li.product').addClass('current');
}
}
if (pathName.indexOf('/fof/') > -1) {//fof定位到产品大厅高亮
$('.sub_header').addClass('lobby_sub_header');
$('.header_nav li').removeClass('current');
$('.header_nav li.product').addClass('current');
}
if (pathName.indexOf('/insuranceStreet/') > -1) {//金融MALL首页定位到金融MALL高亮
$('.header_nav li').removeClass('current');
$('.header_nav li.mall').addClass('current');
}
if (pathName.indexOf('/web/') > -1 && pathName.indexOf('/insuranceStreet/') == -1) {//金融MALL的显示“金融MALL首页”
$('#topmall').show();
}
}
function bindEvents() {
$('#toplogin').on('click', function () {
alertLogin();
// window.location = window.ssoOprUrl.loginUrl;
});
$('#toploginOut').on('click', function () {
loginout();
});
$('#topSearchBtn').on('click', function () {
var searchInput = $("#topSearchInput").val();
window.location = window.yztDomain + "/portal/searchresult?keyWords=" + searchInput;
}).on('mouseenter', function () {
$('#topSearchInput').css('width', '245px');
});
$('#topSearchInput').hover(function () {
$(this).css('width', '245px');
}, function () {
!$(this).val().trim() && $(this).css('width', '94px');
}).focus(function () {
$(this).css('width', '245px');
}).blur(function () {
$(this).css('width', '94px');
});
$('#topRegister').on('click', function () {
window.location = window.ssoOprUrl.registerUrl;
});
/**左侧导航锁屏滚动**/
$('#topHeader .menu-group').preventScroll();
$('#topHeader .submenu-group').each(function(k,el){
$(el).preventScroll();
});
}
return {
init: init
};
}
function loginout() {
loadAjax({
url: "/user/logout",
needCache: false,
success: function(result) {
if(result && result.rtnCode == "000") {
location.href = ssoOprUrl.logoutUrl
}
}
})
}
function createLink() {
var cssURL = '/trans/css/base/top-header.css',
linkTag = $('<link href="' + cssURL + '" rel="stylesheet" type="text/css"/>');
$($('head')[0]).append(linkTag);
}
function queryShopExist() {
loadAjax({
url: "/yztShop/queryShopExist",
data: JSON.stringify({}),
needCache: false,
contentType: "application/x-www-form-urlencoded;charset=utf-8",
success: function (res) {
if (res.data && res.data == "1") {
var userroles = cookies.get('userRoles');
var isMonitor = userroles.indexOf('monitor') >= 0 ? true : false;
if (cookies.get("yztType") == "0" || isMonitor) {
$('#topmallAcct').show();
}
}
}
});
}
$('body').loadHeader();
if(typeof define === "function" && define.amd) {
define("topHeader", [], function() {});
}
})