/**
* 系统管理--用户管理的单例对象
*/
var MgrUser = {
id: "managerTable",//表格id
seItem: null, //选中的条目
table: null,
layerIndex: -1,
deptid:0
};
/**
* 初始化表格的列
*/
MgrUser.initColumn = function () {
var columns = [
{field: 'selectItem', radio: true},
{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
{title: '账号', field: 'account', align: 'center', valign: 'middle','class': 'uitd_showTip',},
{title: '姓名', field: 'name', align: 'center', valign: 'middle','class': 'uitd_showTip',},
{title: '性别', field: 'sexName', align: 'center', valign: 'middle'},
{title: '账号类型', field: 'type', align: 'center', valign: 'middle','class': 'uitd_showTip',
formatter: function (value, row, index) {
if (value == 1) {
return "晋江市现代产业体系人才";
}else if (value == 2) {
return "集成电路优秀人才";
}else if (value == 3) {
return "海峡计划申报";
}else if (value == 4) {
return "super";
}
}
},
{title: '角色', field: 'roleName', align: 'center', valign: 'middle','class': 'uitd_showTip',},
{title: '单位', field: 'companyName', align: 'center', valign: 'middle','class': 'uitd_showTip',},
{title: '邮箱', field: 'email', align: 'center', valign: 'middle','class': 'uitd_showTip',},
{title: '电话', field: 'phone', align: 'center', valign: 'middle', sortable: false,'class': 'uitd_showTip',},
{title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true,'class': 'uitd_showTip',},
{title: '状态', field: 'status', align: 'center', valign: 'middle', sortable: true,
formatter: function (value, row, index) {
if (value == 1) {
return "";
}if (value == 2) {
return "";
}if (value == 3) {
return "";
}
}
}];
return columns;
};
/**
* 检查是否选中
*/
MgrUser.check = function () {
var selected = $('#' + this.id).bootstrapTable('getSelections');
if (selected.length == 0) {
Feng.info("请先选中表格中的某一记录!");
return false;
} else {
MgrUser.seItem = selected[0];
return true;
}
};
/**
* 点击添加管理员
*/
MgrUser.openAddMgr = function () {
var index = layer.open({
type: 2,
title: '添加管理员',
area: ['1000px', '560px'], //宽高
fix: false, //不固定
maxmin: true,
content: Feng.ctxPath + '/mgr/user_add'
});
MgrUser.layerIndex = index;
};
/**
* 点击修改按钮时
* @param userId 管理员id
*/
MgrUser.openChangeUser = function () {
if (this.check()) {
var index = layer.open({
type: 2,
title: '编辑管理员',
area: ['1000px', '450px'], //宽高
fix: false, //不固定
maxmin: true,
content: Feng.ctxPath + '/mgr/user_edit/' + this.seItem.id
});
MgrUser.layerIndex = index;
}
};
/**
* 点击角色分配
* @param
*/
MgrUser.roleAssign = function () {
if (this.check()) {
var index = layer.open({
type: 2,
title: '角色分配',
area: ['300px', '400px'], //宽高
fix: false, //不固定
maxmin: true,
content: Feng.ctxPath + '/mgr/role_assign/' + this.seItem.id
});
MgrUser.layerIndex = index;
}
};
/**
* 删除用户
*/
MgrUser.delMgrUser = function () {
if (this.check()) {
var operation = function(){
var userId = MgrUser.seItem.id;
var ajax = new $ax(Feng.ctxPath + "/mgr/delete", function () {
Feng.success("删除成功!");
MgrUser.table.refresh();
}, function (data) {
Feng.error("删除失败!" + data.responseJSON.message + "!");
});
ajax.set("userId", userId);
ajax.start();
};
Feng.confirm("是否删除用户" + MgrUser.seItem.account + "?",operation);
}
};
/**
* 冻结用户账户
* @param userId
*/
MgrUser.freezeAccount = function () {
if (this.check()) {
var userId = this.seItem.id;
var ajax = new $ax(Feng.ctxPath + "/mgr/freeze", function (data) {
Feng.success("冻结成功!");
MgrUser.table.refresh();
}, function (data) {
Feng.error("冻结失败!" + data.responseJSON.message + "!");
});
ajax.set("userId", userId);
ajax.start();
}
};
/**
* 解除冻结用户账户
* @param userId
*/
MgrUser.unfreeze = function () {
if (this.check()) {
var userId = this.seItem.id;
var ajax = new $ax(Feng.ctxPath + "/mgr/unfreeze", function (data) {
Feng.success("解除冻结成功!");
MgrUser.table.refresh();
}, function (data) {
Feng.error("解除冻结失败!");
});
ajax.set("userId", userId);
ajax.start();
}
}
/**
* 重置密码
*/
MgrUser.resetPwd = function () {
if (this.check()) {
var userId = this.seItem.id;
parent.layer.confirm('确定重置吗?', {
btn: ['确定', '取消'],
shade: false //不显示遮罩
}, function () {
var ajax = new $ax(Feng.ctxPath + "/mgr/reset", function (data) {
Feng.success("重置密码成功!");
}, function (data) {
Feng.error("重置密码失败!");
});
ajax.set("userId", userId);
ajax.start();
});
}
};
MgrUser.resetSearch = function () {
$("#name").val("");
$("#account").val("");
$("#status").val("");
$("#sex").val("");
$("#phone").val("");
$("#companyId").val("");
MgrUser.search();
}
MgrUser.search = function () {
MgrUser.table.refresh({query: MgrUser.formParams()});
}
/**
* 查询表单提交参数对象
* @returns {{}}
*/
MgrUser.formParams = function () {
var queryData = {};
queryData['name'] = $("#name").val();
queryData['account'] = $("#account").val();
queryData['sex'] = $("#sex").val();
queryData['phone'] = $("#phone").val();
queryData['status'] = $("#status").val();
queryData['companyId'] = $("#companyId").val();
return queryData;
}
MgrUser.onClickDept = function (e, treeId, treeNode) {
MgrUser.deptid = treeNode.id;
MgrUser.search();
};
$(function () {
var defaultColunms = MgrUser.initColumn();
var table = new BSTable("managerTable", "/mgr/list", defaultColunms);
table.setPaginationType("client");
table.setQueryParams(MgrUser.formParams());
MgrUser.table = table.init();
//初始化单位下拉框
Feng.addAjaxSelect({
"id": "companyId",
"displayCode": "id",
"displayName": "name",
"type": "GET",
"url": Feng.ctxPath + "/company/selectAll"
});
});