/** * 添加或修改菜单 * */ $(function() { autosize($('textarea')); var isEdit = helper.request.queryString("isEdit"); var mid = helper.request.queryString("mid"); var txt = helper.request.queryString("txt"); txt = decodeURIComponent(txt); var pid = helper.request.queryString("pid"); var pTxt = helper.request.queryString("pTxt"); pTxt = decodeURIComponent(pTxt); //菜单下拉数据 getMenuLists(); if(isEdit) { //修改 if(pid == "000000000000000000000000" || pid == "undefined") { $('#menus').val("顶级分类"); $('#menus').attr('data-id', '000000000000000000000000'); } else { $('#menus').val(pTxt); $('#menus').attr('data-id', pid); } getMenusInfo(); $('#save_btns').on('click', saveEditAccount); } else { //添加 if(mid == "undefined") { $('#menus').val("顶级分类"); $('#menus').attr('data-id', '000000000000000000000000'); } else { $('#menus').val(txt); $('#menus').attr('data-id', mid); } $('#save_btns').on('click', saveAccount); } $('#menus').on('focus click', function() { $('#menusTreeView').removeClass('hidden').addClass('show'); }); $('#menus').on('keyup', function() { if($(this).val() == '') { $('menusTreeView').treeview('uncheckAll', { silent: true }); $(this).attr('data-id', '000000000000000000000000'); } }); $('#menus + .caret').on('click', function() { $('#menusTreeView').removeClass('hidden').addClass('show'); }); $('#menusTreeView').mouseleave(function() { $(this).removeClass('show').addClass('hidden'); }); }); //获取菜单信息 function getMenusInfo() { var mid = helper.request.queryString("mid"); $.getJSON(huayi.config.callcenter_url + "configurationapi/api/moduleinfo/getModule", { mid: mid, }, function(data) { if(data.state == "success") { var res = data.data; $('#menusName').val(res.name); $('#menusCode').val(res.code); $('#menusUrl').val(res.url); $('#menusSort').val(res.sort); $('#menusIcons').val(res.imgUrl); $('#menusIcons').trigger('change'); $('#menusType').selectpicker('val', res.target).trigger('change'); $('#menusEabled').find("input[type='radio'][value= " + res.enable + "]").attr("checked", true); $('#menusRemark').val(res.remark); } }); } //添加保存菜单信息 function saveAccount() { if(!$.trim($('#menusName').val())) { layer.confirm('菜单名称不允许为空!', { icon: 2, btn: ['确定'] //按钮 }); return; } if(!$.trim($('#menusCode').val())) { layer.confirm('菜单代码不允许为空!', { icon: 2, btn: ['确定'] //按钮 }); return; } if(!$.trim($('#menusUrl').val())) { layer.confirm('菜单链接地址不允许为空!', { icon: 2, btn: ['确定'] //按钮 }); return; } if(!regexs.integerReg.test($.trim($('#menusSort').val()))) { layer.confirm('请输入有效的排序编号(正整数、负整数、0)', { icon: 2, btn: ['确定'] //按钮 }); return; } $.post(huayi.config.callcenter_url + "configurationapi/api/moduleinfo/addModule", { parentid: $('#menus').attr('data-id'), //当前选择节点ID父级ID,无父级ID为'000000000000000000000000' code: $('#menusCode').val(), name: $('#menusName').val(), //菜单名称 url: $("#menusUrl").val(), target: $('#menusType').val(), flag: $('#menusEabled').find('input[type="radio"]:checked').val(), //1为启用,0不启用 sort: $('#menusSort').val(), //排列序号 imgUrl: encodeURIComponent($('#menusIcons').val()), remark: $('#menusRemark').val(), }, function(data) { var data = JSON.parse(data); if(data.state == "success") { var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); parent.$("#gridList").resetSelection(); parent.$("#gridList").trigger("reloadGrid"); parent.layer.msg("添加成功"); } }); } //修改保存菜单信息 function saveEditAccount() { var mid = helper.request.queryString("mid"); if(!$.trim($('#menusName').val())) { layer.confirm('菜单名称不允许为空!', { icon: 2, btn: ['确定'] //按钮 }); return; } if(!$.trim($('#menusCode').val())) { layer.confirm('菜单代码不允许为空!', { icon: 2, btn: ['确定'] //按钮 }); return; } if(!$.trim($('#menusUrl').val())) { layer.confirm('菜单链接地址不允许为空!', { icon: 2, btn: ['确定'] //按钮 }); return; } if(!regexs.integerReg.test($.trim($('#menusSort').val()))) { layer.confirm('请输入有效的排序编号(正整数、负整数、0)', { icon: 2, btn: ['确定'] //按钮 }); return; } $.post(huayi.config.callcenter_url + "configurationapi/api/moduleinfo/editmodule", { id: mid, //当前选择节点ID parentid: $('#menus').attr('data-id'), //父级ID,无父级ID为'000000000000000000000000' code: $('#menusCode').val(), //编码 name: $('#menusName').val(), //菜单名称 url: $("#menusUrl").val(), //链接地址 target: $('#menusType').val(), //目标 flag: $('#menusEabled').find('input[type="radio"]:checked').val(), //1为启用,0不启用 sort: $('#menusSort').val(), //排列序号 imgUrl: encodeURIComponent($('#menusIcons').val()), //图片 remark: $('#menusRemark').val(), //备注信息 }, function(data) { var data = JSON.parse(data); if(data.state == "success") { var index = parent.layer.getFrameIndex(window.name); parent.layer.close(index); parent.$("#gridList").resetSelection(); parent.$("#gridList").trigger("reloadGrid"); parent.layer.msg("修改成功"); } }); } //菜单下拉 function getMenuLists() { var pid = helper.request.queryString("pid"); $.getJSON(huayi.config.callcenter_url + 'configurationapi/api/moduleinfo/getall', { }, function(result) { if(result.state.toLowerCase() == "success") { var defaultDatas = result.data; var $sTree = $('#menusTreeView').treeview({ color: "#428bca", expandIcon: 'glyphicon glyphicon-chevron-right', collapseIcon: 'glyphicon glyphicon-chevron-down', nodeIcon: 'fa fa-folder-o', //selectedIcon: "glyphicon glyphicon-stop", //icon: "glyphicon glyphicon-stop", //emptyIcon: 'glyphicon', //showCheckbox: true, selectable: true, state: { selected: true }, data: defaultDatas, onNodeSelected: function(event, node) { $sTree.treeview('clearSearch'); $('#menus').val(node.text); $('#menus').attr('data-id', node.id); $('#menusTreeView').removeClass('show').addClass('hidden'); }, onNodeUnselected: function(event, node) { $('#menus').val('顶级分类'); $('#menus').attr('data-id', '000000000000000000000000'); } }); $('#menusTreeView').treeview('collapseAll', { silent: true }); var findSNodes = function() { return $sTree.treeview('search', [$('#menus').val(), { ignoreCase: false, exactMatch: false }]); }; $('#menus').on('keyup', function(e) { var selectableNodes = findSNodes(); // var m = $('#menusTreeView').treeview('getParent', selectableNodes); // $('#menusTreeView').treeview('selectNode', [ m, { silent: true } ]); }); } }) } //图标数据 var iconData = [{ "text": "默认图标", "id": "" }, { "text": "项目", "id": "" }, { "text": "项目管理", "id": "" }, { "text": "项目合同", "id": "" }, { "text": "项目类型", "id": "" }, { "text": "项目到期", "id": "" }, { "text": "项目申报", "id": "" }, { "text": "设备型号", "id": "" }, { "text": "设备配置", "id": "" }, { "text": "设备管理", "id": "" }, { "text": "设备管理01", "id": "" }, { "text": "设备管理02", "id": "" }, { "text": "设备清单", "id": "" }, { "text": "设备列表", "id": "" }, { "text": "设备", "id": "" }, { "text": "设备审核", "id": "" }, { "text": "设备01", "id": "" }, { "text": "网站程序", "id": "" }, { "text": "网站", "id": "" }, { "text": "网站01", "id": "" }, { "text": "系统安全", "id": "" }, { "text": "系统设置", "id": "" }, { "text": "系统服务", "id": "" }, { "text": "运维管理", "id": "" }, { "text": "运维管理01", "id": "" }, { "text": "系统管理", "id": "" }, { "text": "网站02", "id": "" }, { "text": "网站管理", "id": "" }, { "text": "网站设置", "id": "" }, { "text": "数据", "id": "" }, { "text": "数据01", "id": "" }, { "text": "数据02", "id": "" }, { "text": "报表管理", "id": "" }, { "text": "统计分析", "id": "" }, { "text": "分析", "id": "" }, { "text": "数据分析", "id": "" }, { "text": "报表分析", "id": "" }, { "text": "报表分析01", "id": "" }, { "text": "统计分析01", "id": "" }, { "text": "知识库", "id": "" }, { "text": "知识库01", "id": "" }, { "text": "知识库02", "id": "" }, { "text": "调查问卷", "id": "" }, { "text": "调查问卷01", "id": "" }, { "text": "问卷管理", "id": "" }, { "text": "问卷调查", "id": "" }, { "text": "问卷分析", "id": "" }, { "text": "运维管理", "id": "" }, { "text": "运维报表", "id": "" }, { "text": "运维设置", "id": "" }, { "text": "运维申请", "id": "" }, { "text": "运维支持", "id": "" }, { "text": "系统运维", "id": "" }, { "text": "运维管理01", "id": "" }, { "text": "软件开发", "id": "" }, { "text": "已报修", "id": "" }, { "text": "报修", "id": "" }, { "text": "维修申请", "id": "" }, { "text": "维修", "id": "" }, { "text": "正在维修的工单", "id": "" }, { "text": "路径分析", "id": "" }, { "text": "质检", "id": "" }, { "text": "质检01", "id": "" }, { "text": "app", "id": "" }, { "text": "app01", "id": "" }, { "text": "版本更新", "id": "" }, { "text": "app03", "id": "" }, { "text": "版本更新01", "id": "" }, { "text": "版本更新02", "id": "" }, { "text": "app升级", "id": "" }, { "text": "管理员", "id": "" }, { "text": "用户", "id": "" }, { "text": "维修工管理", "id": "" }, { "text": "维修工", "id": "" }, { "text": "维修工01", "id": "" }, { "text": "用户01", "id": "" }, { "text": "用户02", "id": "" }, { "text": "管理员02", "id": "" }, { "text": "管理员03", "id": "" }, { "text": "项目成员", "id": "" }, { "text": "项目成员01", "id": "" }, { "text": "正在拨号", "id": "" }, { "text": "通话", "id": "" }, { "text": "电话", "id": "" }, { "text": "电话01", "id": "" }, { "text": "通话记录", "id": "" }, { "text": "多方通话", "id": "" }, { "text": "电话未接", "id": "" }, { "text": "电话02", "id": "" }, { "text": "通话时间", "id": "" }, { "text": "通话记录", "id": "" }, { "text": "忙碌", "id": "" }, { "text": "忙碌01", "id": "" }, { "text": "客服", "id": "" }, { "text": "客服01", "id": "" }, { "text": "客服02", "id": "" }, { "text": "客服03", "id": "" }, { "text": "客服04", "id": "" }, { "text": "客服05", "id": "" }, { "text": "客服06", "id": "" }] $("#menusIcons").select2({ minimumResultsForSearch: -1, data: iconData, templateResult: formatState }); //格式化图标下拉 function formatState(state) { if(!state.id) { return state.text; } var $state = $( '' + state.id + '' + state.text + '' ); return $state; };