/**
* getDictionaryList-请求对应字典值公共方法:
* @param {String} codeNo 字典编号
* @param {String} windowName window.变量名
* @param {Boolean} async 是否异步
*
* 用法:common_getDictionaryList(字典编号, window.变量名, 是否异步);
*/
// function common_getDictionaryList(codeNo, windowName, async) {
// $.ajax({
// type: 'POST',
// async: async ? async : false,
// url: base_url+"/rlc-cts/server/getDictionaryList",
// data: JSON.stringify({
// codeNo: codeNo
// }),
// dataType: 'json',
// contentType: "application/json",
// success: function (res) {
// if(res.code == '00'){
// // console.log('common_getDictionaryList请求字典值为:'+codeNo+'时成功,并赋值给window.'+windowName);
// window[windowName] = res;
// }else{
// layer.msg(res.msg);
// }
// }
// });
// // console.log('获取', windowName, ': ', window[windowName]);
// }
// 查询用户信息
$.ajax({
url: base_url + "/sso-portal/user/getUserInfo",
dataType: 'json',
contentType: "application/json",
type: 'POST',
success: function (res) {
if (res.resultCode == 1) {
$("#user_name").text(res.data.userName);
usre_info = res.data
localStorage.setItem("userInfo",JSON.stringify(usre_info))
} else {
layer.msg(res.errorDesc);
}
}
});
// 查询菜单
$.ajax({
url: base_url + "/sso-portal/menu/getUserMenu",
dataType: 'json',
contentType: "application/json",
type: 'POST',
success: function (res) {
if (res.resultCode == 1) {
$('#left-navwrap').html(template('left-navtpl', res.data));
$('#fold_side_bar_wrap').html(template('fold_side_bar_tpl', res.data));
//JavaScript代码区域
layui.use('element', function () {
var element = layui.element;
element.init();
/* 新增一个Tab项 */
element.tabAdd('content_tab_filter', {
title: '首页'
, content: ""
, id: '0'
});
element.tabChange('content_tab_filter', '0');
$("#tab_content_wrap").find(".layui-tab-item").append($(""));
// if(usre_info.orgCode == '1114' || usre_info.orgCode == '1115' || usre_info.orgCode == '1117' || usre_info.orgCode == '002') {
// // 避免访问首页的信息
// $("#tab_content_wrap").find(".layui-tab-item").find("iframe").attr("src", base_url+'/iPortal/notfund.html');
// } else {
$("#tab_content_wrap").find(".layui-tab-item").find("iframe").attr("src", base_url+'/cts-web/#/home');
// }
});
} else {
layer.msg(res.errorDesc);
}
}
});
// 注销
$("#log_out_btn").click(function () {
$.ajax({
url: base_url + "/sso-portal/logout",
dataType: 'json',
contentType: "application/json",
type: 'POST',
success: function (res) {
if (res.resultCode == 1) {
location.href = "login.html";
} else {
layer.msg(res.errorDesc);
}
}
});
});
// 修改密码
$("#change_pwd_btn").click(function () {
$.get('views/jurisdiction/user_change_pwd_modal.html', function(str){
window.user_reset_pwd_modal_index = layer.open({
type: 1
,title :'修改密码'
,content: str //注意,如果str是object,那么需要字符拼接。
,maxmin: true
,area: ['360px','300px']
});
});
});
$("#side_bar_wrap_toggle_btn").click(function () {
if ($(this).attr("src") == "image/toggle_left.png") {
$(this).attr("src", "image/toggle_right.png");
$(this).attr("title", "展开菜单");
$("#side_bar_wrap").css("width", 68);
$("#company_logo_area").css("width", 68);
$("#view_container").css("left", 68);
$("#lateral_nav_wrap").css("left", 68);
$("#side_bar_inner_wrap").hide();
$("#company_name").hide();
$("#fold_side_bar_wrap").show();
} else if ($(this).attr("src") == "image/toggle_right.png") {
layer.closeAll('tips'); //关闭所有的tips层
$(this).attr("src", "image/toggle_left.png");
$(this).attr("title", "收起菜单");
$("#side_bar_wrap").css("width", 200);
$("#company_logo_area").css("width", 200);
$("#view_container").css("left", 200);
$("#lateral_nav_wrap").css("left", 200);
$("#side_bar_inner_wrap").show();
$("#company_name").show();
$("#fold_side_bar_wrap").hide();
}
});
$("body").on('click', '.operation_left_tree_img', function () {
if ($(this).attr("src") == "image/hide_left_tree.png") {
$(this).attr("src", "image/show_left_tree.png");
$(this).parent(".folding_partition_line").css("border-right", "none").siblings(".left_tree_wrap").hide();
$(this).parent(".folding_partition_line").siblings(".form_and_table_wrap").addClass("tree_hide_table_width");
} else {
$(this).attr("src", "image/hide_left_tree.png");
$(this).parent(".folding_partition_line").css("border-right", "1px solid #e6e6e6").siblings(".left_tree_wrap").show();
$(this).parent(".folding_partition_line").siblings(".form_and_table_wrap").removeClass("tree_hide_table_width");
}
});
$("body").on('click', '.fold_side_bar_unit', function () {
$("#side_bar_wrap_toggle_btn").click();
});
// 搜索条件展开折叠逻辑
$("body").on('click', '.search_field_spread_toggle_btn', function () {
if ($(this).find(".spread__toggle_inner_text").text() == "展开") {
$(this).find(".spread__toggle_inner_text").text("收起");
$(this).find(".search_field_spread_toggle_icon1").hide();
$(this).find(".search_field_spread_toggle_icon2").show();
$(this).parent(".layui-inline").siblings(".form_toggle_search_field_unit").removeClass("hide");
} else {
$(this).find(".spread__toggle_inner_text").text("展开");
$(this).find(".search_field_spread_toggle_icon1").show();
$(this).find(".search_field_spread_toggle_icon2").hide();
$(this).parent(".layui-inline").siblings(".form_toggle_search_field_unit").addClass("hide");
}
});
// 搜索条件展开折叠逻辑
$("body").on('click', '.search_field_spread_toggle_btn2', function () {
if ($(this).find(".spread__toggle_inner_text").text() == "展开") {
$(this).find(".spread__toggle_inner_text").text("收起");
$(this).find(".search_field_spread_toggle_icon1").hide();
$(this).find(".search_field_spread_toggle_icon2").show();
} else {
$(this).find(".spread__toggle_inner_text").text("展开");
$(this).find(".search_field_spread_toggle_icon1").show();
$(this).find(".search_field_spread_toggle_icon2").hide();
}
$(this).parent(".top_progress_bar_area").siblings(".right_fixed_progress_bar_area").toggle();
});
$("body").on('mouseenter', '.link_btn:has(.expand_three_level_icon)', function () {
if($(window).height() - $(this).offset().top > $(this).children(".three_level_nav_wrap").height()){
$(this).children(".three_level_nav_wrap").css("top", $(this).offset().top).show();
}else if($(this).offset().top > $(this).children(".three_level_nav_wrap").height()){
$(this).children(".three_level_nav_wrap").css("top", $(this).offset().top - $(this).children(".three_level_nav_wrap").height() + 44).show();
}else{
$(this).children(".three_level_nav_wrap").css({
"top": $(this).offset().top,
"height": "176px",
"overflow": "hidden scroll",
}).show();
}
});
$("body").on('mouseleave', '.link_btn:has(.expand_three_level_icon),#three_level_nav_wrap', function () {
$(".three_level_nav_wrap").css({
"height": "auto",
"overflow": "hidden"
}).hide();
});
$("#three_level_nav_wrap").on('mouseenter', function () {
$(this).show();
});
$("body").on('mouseenter', '.fold_side_bar_unit img', function () {
var that = this;
layer.tips($(that).attr("data-title"), that, {
tips: 2
});
});
layui.use('element', function () {
var element = layui.element;
$("body").on('click', '.link_btn:not(:has(.expand_three_level_icon)),.three_level_nav', function () {
var _length = $("#content_tab_header").find("li").length;
var _that = this;
window.g_menu_id = $(_that).attr("data-menuid");
// 设置全局ajax
$.ajaxSetup({
xhrFields: {
withCredentials: true
},
beforeSend: function(jqXHR, settings) {
//在请求前给修改url(增加一个时间戳参数)
settings.url += settings.url.match(/\?/) ? "&" : "?";
settings.url += "menuId=" + window.g_menu_id;
},
cache: false, //关闭AJAX相应的缓存
dataFilter : function(res, type){
if(type == "json"){
var res2 = JSON.parse(res);
if(res2.errorCode == "003"){
location.href = res2.data.loginUrl;
}
}
return res;
}
});
if (_length == 0) {
$.when(
// 获取页面元素权限
getFunctionByMenuCode(_that)
).done(function () {
/* 新增一个Tab项 */
element.tabAdd('content_tab_filter', {
title: $(_that).attr("data-name")
, content: ""
, id: $(_that).attr("data-menuid")
});
if ($(_that).attr("data-pagetype") == 0) {
$("#tab_content_wrap").find(".layui-tab-item").load($(_that).attr("data-url") + ".html");
} else if ($(_that).attr("data-pagetype") == 1) {
var url = $(_that).attr('data-url').replace(/&+$/, '');
var menuId = $(_that).attr("data-menuid")
url = url.indexOf('?') > -1 ? url + '&menuId=' + menuId : url + '?menuId=' + menuId;
$("#tab_content_wrap").find(".layui-tab-item").append($(""));
$("#tab_content_wrap").find(".layui-tab-item").find("iframe").attr("src", url);
}
$("#content_tab_header").find("li").trigger("click");
});
} else if (_length >= 1 && _length < 15) {
var _is_in_tab_list = false;
$("#content_tab_header").find("li").each(function () {
if ($(this).attr("lay-id") == $(_that).attr("data-menuid")) {
$(this).trigger("click");
_is_in_tab_list = true;
} else {
}
});
if (_is_in_tab_list) {
} else {
$.when(
// 获取页面元素权限
getFunctionByMenuCode(_that)
).done(function () {
/* 新增一个Tab项 */
element.tabAdd('content_tab_filter', {
title: $(_that).attr("data-name")
, content: ""
, id: $(_that).attr("data-menuid")
});
if ($(_that).attr("data-pagetype") == 0) {
$("#tab_content_wrap").find(".layui-tab-item:last").load($(_that).attr("data-url") + ".html");
} else if ($(_that).attr("data-pagetype") == 1) {
$("#tab_content_wrap").find(".layui-tab-item:last").append($(""));
$("#tab_content_wrap").find(".layui-tab-item:last").find("iframe").attr("src", $(_that).attr("data-url"));
}
/* 切换到指定Tab项 */
element.tabChange('content_tab_filter', $(_that).attr("data-menuid"));
});
}
} else if (_length >= 15) {
var _is_in_tab_list = false;
$("#content_tab_header").find("li").each(function () {
if ($(this).attr("lay-id") == $(_that).attr("data-menuid")) {
$(this).trigger("click");
_is_in_tab_list = true;
} else {
}
});
if (_is_in_tab_list) {
} else {
layer.msg("最多只能打开15个页签,如要打开更多,请先关闭部分不使用的页签");
}
}
});
function getFunctionByMenuCode(_that){
// 获取页面元素权限
$.ajax({
url: base_url + "/sso-portal/menu/getFunctionByMenuCode",
dataType: 'json',
contentType: "application/json",
type: 'POST',
data: JSON.stringify({
params: {
"resourceCode": $(_that).attr("data-id")
}
}),
success: function (res) {
if (res.resultCode == 1) {
if (!res.data) {
} else {
delete window['_server_queryApplyTabTree']
$.each(res.data, function (i, n) {
if (n == true) {
//调用接口成功后删除部分重复的字段
window[i] = true;
}
});
}
} else {
layer.msg(res.errorDesc);
}
}
})
}
//监听Tab切换,以改变地址hash值
element.on('tab(content_tab_filter)', function(){
window.g_menu_id = this.getAttribute('lay-id');
$('#left-navwrap li').each(function () {
$(this).find('dd').each(function () {
$(this).removeClass('layui-this');
if($(this).children('a').attr('data-menuid') == window.g_menu_id){
$(this).parents('.layui-nav-item').addClass('layui-nav-itemed').siblings().removeClass('layui-nav-itemed')
$(this).addClass('layui-this')
getFunctionByMenuCode($(this).children('a'))
}else{
$(this).find('.three_level_nav').each(function() {
if($(this).attr('data-menuid') == window.g_menu_id){
$(this).parents('.layui-nav-item').addClass('layui-nav-itemed').siblings().removeClass('layui-nav-itemed')
$(this).parents('dd').addClass('layui-this')
getFunctionByMenuCode($(this))
}
})
}
})
})
if($('.other_system_iframe')[0]&&$(this).text().indexOf('首页')!=-1){
// $('.other_system_iframe')[0].contentWindow.refreshChart()
}
// 设置全局ajax
$.ajaxSetup({
xhrFields: {
withCredentials: true
},
beforeSend: function(jqXHR, settings) {
//在请求前给修改url(增加一个时间戳参数)
settings.url += settings.url.match(/\?/) ? "&" : "?";
settings.url += "menuId=" + window.g_menu_id;
},
cache: false, //关闭AJAX相应的缓存
dataFilter : function(res, type){
if(type == "json"){
var res2 = JSON.parse(res);
if(res2.errorCode == "003"){
location.href = res2.data.loginUrl;
}
}
return res;
}
});
});
if($(window).width() <= '1280'){
$("#side_bar_wrap_toggle_btn").attr("src", "image/toggle_right.png");
$('#side_bar_wrap_toggle_btn').attr("title", "展开菜单");
$("#side_bar_wrap").css("width", 68);
$("#company_logo_area").css("width", 68);
$("#view_container").css("left", 68);
$("#lateral_nav_wrap").css("left", 68);
$("#side_bar_inner_wrap").hide();
$("#company_name").hide();
$("#fold_side_bar_wrap").show();
}else{
$("#side_bar_wrap_toggle_btn").attr("src", "image/toggle_left.png");
$('#side_bar_wrap_toggle_btn').attr("title", "收起菜单");
layer.closeAll('tips'); //关闭所有的tips层
$("#side_bar_wrap").css("width", 200);
$("#company_logo_area").css("width", 200);
$("#view_container").css("left", 200);
$("#lateral_nav_wrap").css("left", 200);
$("#side_bar_inner_wrap").show();
$("#company_name").show();
$("#fold_side_bar_wrap").hide();
}
});
//提供给vue页面删除已打开窗口的方法
function tabDelete(name) {
/* 删除指定Tab项 */
layui.use('element', function () {
var element = layui.element;
$('#content_tab_header li').each(function () {
if($(this).text().indexOf(name) != -1){
element.tabDelete('content_tab_filter', $(this).attr('lay-id'));
}
})
});
};
//提供给vue页面打开新窗口的方法
function getMenuByParent(firstMenu,secondMenu,thirdMenu){
var isHaveMenu = false
$('#left-navwrap li').each(function () {
if($(this).children('a').text() == firstMenu){
$(this).find('dd').each(function () {
if($(this).children('a').attr('data-name') == secondMenu){
isHaveMenu = true
if(thirdMenu){
$(this).find('.three_level_nav').each(function() {
if($(this).attr('data-name') == thirdMenu){
$(this).trigger("click");
}
})
}else{
$(this).children('a').trigger("click");
}
}
})
}else{
}
})
if(!isHaveMenu){
layer.msg('当前用户无权限查看,请联系管理员');
}
}
//根据菜单id来打开新窗口
function getMenuIdByParent(secMenuId,menuId){
$('#left-navwrap li').each(function () {
$(this).find('dd').each(function () {
if(secMenuId && $(this).children('a').attr('data-menuid') == secMenuId){
if(secMenuId == menuId){
$(this).children('a').trigger("click");
}else{
$(this).find('.three_level_nav').each(function() {
if($(this).attr('data-menuid') == menuId){
$(this).trigger("click");
}
})
}
}
if(!secMenuId && $(this).children('a').attr('data-menuid') == menuId){
$(this).children('a').trigger("click");
}
})
})
}
/**
* 下拉框子元素替换
*
* @param tpl 字符串模板
* 1.清空下拉框素有子元素
* 2.向头部追加 默认模板
* 3.追加新增模板
*/
$.fn.extend({
_take_place: function (tpl) {
this.empty()
this.prepend('')
this.append(tpl)
}
})
/**
* 拓展jq ajax方法
* @param config jq的ajax配置
* @returns _Promise 对象
*/
$.extend({
_ajax: function (config) {
return new _Promise(function (resolve, reject) {
config.success = function (res) {
resolve(res)
}
config.fail = function (err) {
reject(err)
}
$.ajax(config)
})
}
})
/**
*layui表格无数据且表头列宽过长时,导致表头显示不全的问题
*
* @param {*} table layui-table类
* @param {*} config render方法需要的表格配置
* @returns table实例
*/
function _table_render(table, config) {
// 渲染图表
var instance = table.render(config)
var id = instance.config.id
var container = $("div[lay-id='" + id + "']")
var isNoData = container.find(".layui-none").length
// 无数据且容器宽度小于表头宽度时,动态设置无数据容器宽度为表头宽度,使其能够出现滚动条
if (isNoData) {
var tableHeadWidth = $(container.find(".layui-table")[0]).outerWidth()
var containerWidth = $(container.find(".layui-table-main")[0]).outerWidth()
containerWidth < tableHeadWidth && $(container.find(".layui-none")[0]).outerWidth(tableHeadWidth)
}
return instance;
}
// 表格批量操作展开与搜索
$("body").on('click', '.table_batch_expand_btn', function () {
if ($(this).find(".table_batch_expand_btn_text").text() == "展开") {
$(this).find(".table_batch_expand_btn_text").text("收起");
$(this).find(".table_batch_expand_btn_icon1").hide();
$(this).find(".table_batch_expand_btn_icon2").show();
$(this).parent(".table_batch_inline").parent(".table_batch_btn_main").siblings(".table_batch_btn_other").find(".table_batch_inline").removeClass("hide");
} else {
$(this).find(".table_batch_expand_btn_text").text("展开");
$(this).find(".table_batch_expand_btn_icon1").show();
$(this).find(".table_batch_expand_btn_icon2").hide();
$(this).parent(".table_batch_inline").parent(".table_batch_btn_main").siblings(".table_batch_btn_other").find(".table_batch_inline").addClass("hide");
}
});
/**
*检测是否为数组或对象
*
* @param {*} obj 待检值
* @returns 数据类型
*/
function _check_type(obj, isValue) {
var _type = Object.prototype.toString.call(obj)
if (!isValue) {
switch (_type) {
case "[object Object]":
case "[object Array]":
return true;
default:
return false;
}
} else {
return _type;
}
}
/**
* 深拷贝
*
* @param {*} source 源对象
* @returns 新的对象
*/
function _assign(source) {
var cloneObj = Array.isArray(source) ? [] : {}
try {
if (typeof source === 'object') {
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (_check_type(source[key])) {
cloneObj[key] = _assign(source[key])
} else {
cloneObj[key] = source[key]
}
}
}
} else {
cloneObj = source
}
} catch (error) {
console.log(error)
}
return cloneObj
}
/**
*合并
*
* @param {*} target 目标对象
* @param {*} source 源对象
* @returns 返回合成对象
*/
function _merge(target, source) {
if (_check_type(target, true) !== '[object Object]' || _check_type(source, true) !== '[object Object]') throw Error("请确保传入两个对象参数");
try {
for (var key in source) {
if (source.hasOwnProperty(key)) {
if (_check_type(source[key]) && _check_type(target[key]) && _check_type(source[key], true) == _check_type(target[key], true)) {
if (_check_type(source[key], true) === '[object Array]') {
target[key] = target[key].concat(source[key])
} else {
target[key] = _merge(target[key], source[key])
}
} else {
target[key] = source[key]
}
}
}
} catch (error) {
console.log(error)
}
return target;
}
/**
*深拷贝且合并两个对象
*
* @param {*} target 目标对象
* @param {*} source 源对象
* @returns 合并后的新目标对象
*/
function _assign_merge(target, source) {
return _merge(_assign(target), source);
}
// 列表-申请管理:
// window.apply_manage_for_list = function() {
// var str = '{{# if(d.detailFlag == "1"){ }} 详情 {{# } }}' +
// '{{# if (d.updateFlag == "1"){ }} 修改 {{# } }}' +
// '{{# if (d.cancelFlag == "1"){ }} 取消申请 {{# } }}' +
// '{{# if (d.resetFlag == "1"){ }} 重新申请 {{# } }}' +
// '{{# if (d.supplyFlag == "1"){ }} 补充资料 {{# } }}' +
// '{{# if(d.immediateFlag == "1"){ }} 立即处理 {{# } }}' +
// '{{# if(d.continueFlag == "1"){ }} 继续处理 {{# } }}'
// return str;
// }
/***
* 关闭弹窗:
* @param event 事件对象
*/
function closeCurrentModal(event) {
layer.close(event.data.id);
}
/**
* 只作临时测试
* 用作提交成功或提交失败的弹窗页面,
* 正式使用时调整下弹窗位置即可。
*/
// // 引入提交失败2的弹窗:
// layui.use(['laypage'], function () {
// console.log('引入成功...');
// $.get('views/integrated_trading_system/loan_apply/submit_error.html', function(str){
// var submit_err_modal_id = layer.open({
// type: 10
// ,title : false
// ,content: str //注意,如果str是object,那么需要字符拼接。
// // ,area: ["850px","85%"]
// ,area: ["850px","auto"]
// ,closeBtn: 0
// ,offset: ['auto']
// });
// $('.submit_err .close_current_modal, .submit_err .confirm_btn').off().on('click', {id: submit_err_modal_id}, closeCurrentModal);
// });
// 引入提交成功的弹窗:~
// $.get('views/integrated_trading_system/loan_apply/submit_success.html', function(str){
// var submit_success_modal_id = layer.open({
// title: false
// , content: str
// , type: 1
// ,area: ["300px","255px"]
// , closeBtn: 0
// , offset: ['auto']
// });
// $('.submit_success .close_current_modal, .submit_success .confirm_btn').off().on('click', {id: submit_success_modal_id}, closeCurrentModal);
// });
// });