///
function viewModel() {
//编辑时所需要的ID
this.id = "";
//加载上级目录
this.loadmenus = function () {
//验证名称是否重复
$('#name').textbox({
delay: 3000,
validateOnBlur: true,
validType: "remote['/SysManager/CheckModuleNameExists?id=0','name']",
invalidMessage: '请重新填写该名称,已重复'
});
$('#parentid').combotree({
url: '/SysManager/GetModuleTree',
method: 'GET'
});
//绑定清空事件
$('#clear').click(function () {
$('#parentid').combotree('clear');
});
}
//初始化(主界面列表)
this.init = function () {
$('#treegrid').treegrid({
url: '/SysManager/ModuleQueryList',
idField: 'ID',
treeField: '名称',
method: 'GET',
fit: true,
toolbar: '#toolbar',
rownumbers: true,
columns: [[
{ field: '名称', title: '名称', width: 180 },
{ field: '图标', title: '图标', width: 40, align: 'center', formatter: function (value, row, index) { return ZLPMS.SetIcons(row.图标, '#000') } },
{ field: '地址', title: '地址', width: 200 },
{ field: '启用', title: '启用', align: 'center', width: 80, formatter: function (value, row, index) { return ZLPMS.SetIsActiveIcon(row.启用); } },
{ field: '首页', title: '首页', align: 'center', width: 80, formatter: function (value, row, index) { return ZLPMS.SetIsActiveIcon(row.首页); } },
{ field: '序号', title: '序号', align: 'center', width: 60 },
{ field: '备注', title: '备注', width: 350 }
]]
});
//增加
$('#btn-add').click(function () {
//top.PublicFun.OpenWindow('新建模块', '/SysManager/ModuleInfo', ['500px', '400px']);
top.ZLPMS.OpenWindow({
title: '新建模块',
url: '/SysManager/ModuleInfo',
area: ['650px', '500px'],
yes: function (index, layero) {
Forms.Submit(index, layero);
},
});
});
//修改
$('#btn-edit').click(function () {
var row = $('#treegrid').treegrid('getSelected');
if (row != null) {
//打开编辑窗口
top.ZLPMS.OpenWindow({
title: '修改模块',
url: '/SysManager/ModuleInfo/' + row.ID,
area: ['650px', '500px'],
yes: function (index, layero) {
Forms.Submit(index, layero);
//刷新
List.Reload();
},
});
} else {
top.ZLPMS.Msg("请选择一行操作的记录", 2);
}
});
$('#btn-ref').click(function () {
//刷新
List.Reload();
});
//删除
$('#btn-del').click(function () {
var t = $('#treegrid');
var row = t.treegrid('getSelected');
if (row != null) {
//检查是否有子级节点,如果有子级节点,则禁止删除
var child = row.children;
if (child != undefined && child.length > 0) {
//包含子节点,不能删除
top.ZLPMS.Msg('包含子节点,无法直接删除,请先删除子节点!', 0);
return;
}
//确认删除对话框
var idx = top.ZLPMS.Confirm('您确定要删除选择的记录吗?删除后不可还原,如果不使用建议禁用模块', 3, function () {
//执行删除
List.Del(row.ID);
//刷新
List.Reload();
//关闭弹出窗口
top.ZLPMS.CloseWindow(idx);
});
} else {
top.ZLPMS.Msg("请选择一行记录后执行操作", 0);
}
});
//分配按钮
$('#btn-fun').click(function () {
var t = $('#treegrid');
var row = t.treegrid('getSelected');
if (row != null) {
//打开编辑窗口
top.ZLPMS.OpenWindow({
title: '分配模块功能',
url: '/SysManager/ModuleButtonList/' + row.ID,
area: ['680px', '550px'],
yes: function (index, layero) {
top.ZLPMS.CloseWindow(index);
},
});
} else {
top.ZLPMS.Msg("请选择一行记录后执行操作", 0);
}
});
}
//加载功能列表
this.initfuns = function (mid) {
var that = this;
this.id = mid;
//加载功能列表(清单)
$('#dgfuns').datagrid({
url: '/SysManager/ButtonListActive/0',
rownumbers: true,
method: 'get',
fit: true,
border: false,
columns: [[
{ checkbox: true, field: 'ID', width: 20 },
{
field: '图标', title: '图标', width: 40, align: 'center', formatter: function (value, row, index) {
return "";
}
},
{ field: '名称', title: '名称', width: 80 },
{ field: '标识', title: '标识', width: 80 }
]],
toolbar: [{
iconCls: 'fa fa-hand-stop-o',
text: '分配功能',
handler: function () { that.authbutton(); }
},
{
iconCls: 'fa fa-refresh',
text: '刷新',
handler: function () { $('#dgfuns').datagrid('reload', {}); }
}],
})
//加载已授权的功能列表
$('#dgmodulefuns').datagrid({
url: '/SysManager/ButtonListActive/' + mid,
rownumbers: true,
method: 'get',
fit: true,
border: false,
columns: [[
{ checkbox: true, field: 'ID', width: 20 },
{ field: '分组名', title: '分组名', width: 70 },
{
field: '图标', title: '图标', width: 40, align: 'center', formatter: function (value, row, index) {
return "";
}
},
{ field: '名称', title: '名称', width: 80 },
{ field: '标识', title: '标识', width: 80 },
{ field: '序号', title: '序号', width: 40 }
]],
toolbar: [{
iconCls: 'fa fa-hand-stop-o',
text: '移除功能',
handler: function () { that.removeAuthButton(); }
},
{
iconCls: 'fa fa-refresh',
text: '刷新',
handler: function () { that.refreshModulefuns(); }
}, {
text: '上移',
handler: function () { }
}, {
text: '下移',
handler: function () { }
}],
})
}
//绑定数据
this.bindData = function (id) {
this.id = id;
//验证防止名称重复
$('#name').textbox({
validType: "remote['/SysManager/CheckModuleNameExists?id=" + id + "','name']"
});
//加载修改内容
$.ajax({
url: '/SysManager/GetModuleInfo/' + id,
method: 'GET',
success: function (data) {
if (data.code == 200) {
$('#id').val(id);
$('#parentid').combotree('setValue', data.obj[0].上级ID);
$('#name').textbox('setValue', data.obj[0].名称);
$('#address').textbox('setValue', data.obj[0].地址);
$('#icons').textbox('setValue', data.obj[0].图标);
$('#ordnum').numberspinner('setValue', data.obj[0].序号);
$('#remark').textbox('setValue', data.obj[0].备注);
//设置值
ZLPMS.SetFormVal('ff', { "isactive": data.obj[0].启用 == 1 ? true : false, "ishome": data.obj[0].首页 == 1 ? true : false });
} else {
//弹出错误消息
ZLPMS.Alert(data.msg, 1);
}
}
})
}
//授权已选择的记录
this.authbutton = function () {
var that = this;
var rows = $('#dgfuns').datagrid('getSelections');
if (rows.length > 0) {
//获取到选择的ID列表
var bids = '';//授权按钮集合,多个使用','号分离
for (var i = 0; i < rows.length; i++) {
bids += ',' + rows[i].ID;
}
ZLPMS.Prompt('请录入一个分组名称', 0, function (text) {
$.ajax({
url: '/SysManager/PostAuthButtons/',
method: 'post',
data: { id: this.id, buttonids: bids, group: text },
success: function (data) {
if (data.code == 200) {
//提交成功,刷新已授权的目录
that.refreshModulefuns();
}
else {//分配失败
ZLPMS.Msg(data.msg, 0);
}
}
});
});
} else {
ZLPMS.Msg('请选择一个功能后进行授权到该模块', 0);
}
}
//移除选择的授权
this.removeAuthButton = function () {
var that = this;
var rows = $('#dgmodulefuns').datagrid('getSelections');
if (rows.length > 0) {
var idx = ZLPMS.Confirm('您确定要移除该功能吗?', 3, function (index) {
var ids = '';
for (var i = 0; i < rows.length; i++) {
ids += ',' + rows[i].ID;
}//end for get ids
$.ajax({
url: '/SysManager/PostRemoveAuthButtons',
method: 'post',
data: { ids: ids },
success: function (data) {
if (data.code == 200) {
//提交成功,刷新已授权的目录
that.refreshModulefuns();
ZLPMS.CloseWindow(idx);
}
else {//分配失败
ZLPMS.Msg(data.msg, 0);
}
}
});
});
} else {
ZLPMS.Msg('请选择一个需要移除的功能', 0);
}
}
//刷新已授权的模块
this.refreshModulefuns = function () {
$('#dgmodulefuns').datagrid('reload');
}
//加载工具栏,参数(toolbar:查询返回的json数组,groupname加载对象)
//this.loadToolbars = function (tools, groupname) {
// if (tools.length > 0) {
// //读取所有按钮
// for (var i = 0; i < tools.length; i++) {
// var tool = tools[i];
// var id = tool.标识;
// var name = tool.名称;
// var icons = tool.图标;
// var colors = tool.颜色;
// var iconhtml = "" + " " + name + ""
// var html = "" + iconhtml + "";
// $('#' + groupname).append(html);
// }//end for
// }
//}
}
//表单操作
var Forms = {
//表单提交
Submit: function (index, layero) {
var iframeWin = top.window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法:
iframeWin.Forms.PostData(index);//调用子页面的方法,得到子页面返回的ids
},
//加载数据(测试)
Load: function (data) {
$('#ff').form('load', data);
},
//读取数据
PostData: function (index) {
//执行提交验证
var r = $('#ff').form('validate');
if (r) {//post到后台
var url = '/SysManager/PostSaveModule';
var param = ZLPMS.FormToObject('ff');
//复选框
//var ck = $("[id='isactive']:checked").val();
$.post(url, param, function (data) {
if (data.code == 200) {
top.ZLPMS.CloseWindow(index);
top.ZLPMS.Msg(data.msg);
} else {
ZLPMS.Msg(data.msg, 2);
}
});
}
return null;
}
};
var List = {
Reload: function () {
$('#treegrid').treegrid('reload');
},
//根据ID删除模块
Del: function (id) {
$.ajax({
url: '/SysManager/DeleteModule',
data: { id: id },
method: 'post',
success: function (data) {
if (data.code != 200) {
ZLPMS.Alert(data.msg, 0);
}
}
});
}
};