czl-web/js/work/user/UserManagementList.js

289 lines
10 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var oldKeyWord;
var oldDepartment;
var oldDepartmentId;
layui.use(['table', 'layer', 'laydate', 'jquery', 'form'], function () {
var table = layui.table;
var laydate = layui.laydate;
let form = layui.form;
//渲染table
table.render({
elem: '#demo'
, url: ctxPath + '/users/getMsgContent' //数据接口
, method: 'post' //方式默认是get
, toolbar: 'default' //开启工具栏,此处显示默认图标,可以自定义模板,详见文档
, where: {} //post请求必须加where post请求需要的参数
, cellMinWidth: 80
, cols: [[ //表头
{field: 'number', width:100,title: '序号', align: 'center', type: 'numbers'}
, {field: 'username',width:200, align: 'center', title: '用户名'}
, {field: 'phone', width: 150, align: 'center', title: '联系方式(登录名)'}
, {field: 'roleName', width: 200, align: 'center', title: '角色'}
, {field: 'orgName', width: 220, align: 'center', title: '组织机构'}
, {field: 'createTimes', width: 220, align: 'center', title: '创建时间'}
, {field: 'status', width: 200, align: 'center', title: '状态', id:'statusSwitch', templet: '#switchTpl'}
, {fixed: 'right', title: '操作', align: 'center', toolbar: '#toolsBar'}
]]
, id: 'menuTable'
, page: true //开启分页
, loading: true //数据加载中。。。
, limits: [10, 20, 50, 100] //一页选择显示3,5或10条数据
, limit: 10 //一页显示5条数据
, response: {
statusCode: 200 //规定成功的状态码默认0
}, parseData: function (res) { //将原始数据解析成 table 组件所规定的数据res为从url中get到的数据
let result;
if (res.data !== '' && res.data != null && res.data !== "null") {
if (this.page.curr) {
result = res.data.slice(this.limit * (this.page.curr - 1), this.limit * this.page.curr);
} else {
result = res.data.slice(0, this.limit);
}
}
return {
"code": res.code, //解析接口状态
"msg": res.msg, //解析提示文本
"count": res.count, //解析数据长度
"data": result, //解析数据列表
};
},
toolbar: "#toolbar"
});
form.on('switch(statusSwitch)', function(data){
var isChecked = data.elem.checked; // 获取复选框的当前状态
var value = data.value; // 获取复选框的值
let status = isChecked ? 1 : 0;
// if (isChecked) {
// console.log('复选框值为 ' + value + ' 被选中');
// // 执行其他操作,比如发送请求给后端
// } else {
// console.log('复选框值为 ' + value + ' 被取消选中');
// // 执行其他操作
// }
// 发送请求到后端更新数据库中的状态字段
$.ajax({
url: ctxPath + '/users/switchListen',
type: 'POST',
data: { id: value, status: status },
success: function(res) {
layer.msg('状态更新成功');
},
error: function() {
layer.msg('更新状态失败');
}
});
});
/**
* 部门下拉树
*/
loadOrgTree();
/**
* 点击除了部门输入框和下拉树范围之外的地方,关闭下拉树列表
*/
$(document).on('click',function(e){
if ($(e.target).closest('#orgContent').length == 0 && $(e.target).closest('#department').length == 0){
hideRole();
}
})
// 行工具事件
table.on('tool(test)', function (obj) {
var data = obj.data //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值
var id = data.id
if (layEvent === 'edit') {
openForm(id,'修改');
} else if (layEvent === 'del') {
delHospital(id);
} else if (layEvent === 'resetPassword'){
resetPassword(id);
}
});
//头监听事件 -- checkBox 选中行和选中条数
table.on('toolbar(test)', function (obj) {
// 获取当前表格被选中的记录对象,返回数据
table.checkStatus(obj.config.id);
//获取事件名,执行对应的代码
var eventName = obj.event;
console.log(eventName)
switch (eventName) {
case "searchBt":
oldKeyWord = $("#keyWord").val();
oldDepartment = $("#department").val();
oldDepartmentId = $("#departmentId").val();
table.reload('menuTable', {
url: ctxPath + '/users/getMsgContent'
, method: 'post' //方式默认是get
, page: true
, where: {
keyWord: oldKeyWord,
department: oldDepartment,
departmentId: oldDepartmentId
} //设定异步数据接口的额外参数
});
/**二次赋值-- 点击搜索按钮之后会进行一次刷新操作*/
loadOrgTree();
$("#keyWord").val(oldKeyWord);
$("#department").val(oldDepartment);
$("#departmentId").val(oldDepartmentId);
loadOrgTree();
break;
case "addBtn":
openForm("",'新增用户');
break;
case "resetBt":
oldKeyWord = "";
oldDepartment = "点击进行部门选择";
oldDepartmentId = "";
$("#keyWord").val("");
$("#department").val("点击进行部门选择");
$("#departmentId").val("");
table.reload('menuTable', {
url: ctxPath + '/users/getMsgContent'
, method: 'post' //方式默认是get
, page: true
, where: {
username: "",
idCard: "",
keyWord: "",
department: "",
departmentId: ""
} //设定异步数据接口的额外参数
});
loadOrgTree();
break;
case "exportBtn":
//导出
break;
}
});
});
/**
* 新增-修改功能
*/
function openForm(id,title){
localStorage.setItem("id",id);
localStorage.setItem("inType","personAdd")
layerOpenForm(title,"./addUserForm.html","70%","85%")
}
/**
* 删除功能
*/
function delHospital(id) {
layer.confirm('确定要删除吗?', {
btn : [ '确定', '取消' ]
}, function() {
ajaxCommonMethods('/users/delById',{'id': id},"删除成功","删除失败","1");
layer.close(1);
});
}
/**
* 重置密码
* @param id
*/
function resetPassword(id){
layer.prompt({
formType: 0,
value: '',
title: '请输入重置后密码',
btn:['确定','取消'],
btnAlign:'c',
}, function(value, index, elem){
if (!password_reg(value)){
layer.msg("您的密码复杂度太低(密码中必须包含大小字母、数字、特殊字符)!",{icon:0});
return false;
}
ajaxCommonMethods('/users/resetPassword',{'id': id,'password':value},"重置成功","重置失败","1");
});
}
/** 树的方法开始 */
var machines = new Set(); //专业容器
var size = 1; //序号
var map =[];
var mapinfo={};
function loadOrgTree(){
$.ajax({
type: "post",
url: ctxPath + "/users/getDepartmentTree",
data: {},
dataType: "json",
success: function(data) {
$.fn.zTree.init($("#departmentTree"),{view:{showIcon: false,dblClickExpand:true,selectedMulti:false,nameIsHTML:true},data:{simpleData:{enable: true}},
callback:{
onClick:clickRole
}},data.obj);
// 获取树对象
var treeObj = $.fn.zTree.getZTreeObj("departmentTree");
/* 获取所有树节点 */
var nodes = treeObj.transformToArray(treeObj.getNodes());
//展开第一级树
treeObj.expandNode(nodes[1], true);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("未连接到服务器,请检查网络!");
}
});
}
/**
* 专业的选择
*/
var preisShow=false;//窗口是否显示
function showRole() {
if(preisShow){
hideRole();
}else{
var obj = $("#department");
var offpos = $("#department").position();
$("#orgContent").css({width:offpos.width+"px",left:offpos.left+"px",top:offpos.top+obj.heigth+"px"}).slideDown("fast");
preisShow=true;
}
}
function hideRole(){
$("#orgContent").fadeOut("fast");
preisShow=false;
}
var isParent = null
var examPerfession = null;
var typeId = null;
function clickRole(e, treeId, treeNode) {
// if(!treeNode.isParent){
var check = (treeNode);
if(check){
var zTree = $.fn.zTree.getZTreeObj("departmentTree"),
nodes = zTree.getSelectedNodes(),v ="",n ="",o="",p="";
for (var i=0, l=nodes.length; i<l; i++) {
v += nodes[i].name + ",";//获取name值
n += nodes[i].id + ",";//获取id值
o += nodes[i].other + ",";//获取自定义值
var pathNodes=nodes[i].getPath();
for(var y=0;y<pathNodes.length;y++){
p+=pathNodes[y].name+"/";//获取path/name值
}
}
if (v.length > 0 ) v = v.substring(0, v.length-1);
if (n.length > 0 ) n = n.substring(0, n.length-1);
if (o.length > 0 ) o = o.substring(0, o.length-1);
if (p.length > 0 ) p = p.substring(0, p.length-1);
$("#departmentId").val(n);
$("#department").val(p);
// typeId = n;
examPerfession = n;
isParent = treeNode.isParent;
typeId = treeNode.type;
hideRole();
}
// }
}
/**树的方法结束*/