yn_img_tool/target/classes/static/js/system/sysOrgMge.js

188 lines
5.7 KiB
JavaScript
Raw 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.

let form, layer, treeTable, treemenu;
layui.config({
base: "../../js/", //此处路径请自行处理, 可以使用绝对路径
}).extend({
treeTable: 'treeTable'
}).use(['form', 'layer', 'treeTable'], function () {
form = layui.form;
layer = layui.layer;
treeTable = layui.treeTable;
layui.form.render();
getOrgTreeTable(1);
form.on('switch(is-state)', function (obj) {
console.log(obj);
let url = dataUrl + "/sys/org/updateEnableState";
let params = {
'id': this.value,
'state': obj.elem.checked ? 1 : 0
}
params={
encryptedData:encryptCBC(JSON.stringify(params))
}
ajaxRequest(url, "POST", params, true, function () {}, function (result) {
console.log(result)
reloadData();
if (result.status === 200) {
parent.layer.msg(result.data, {icon: 1})
} else if (result.status === 204) {
parent.layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
});
})
// 渲染表格
treemenu = {
reload: function (data) {
treeTable.render({
elem: '#dt-table',
data: data,
height: 'full-50',
tree: {
iconIndex: 0,
isPidData: true,
id: 'id',//父ID
pidName: 'parentId',//子ID
openName: 'open',// 是否默认展开的字段名
},
cols: [[
{field: 'orgName', title: '组织名称', width: '20%'},
{field: 'name', title: '联系人', width: '10%',align: "center"},
{field: 'phone', title: '联系电话', width: '10%',align: "center"},
{field: "state", title: "状态",width: '10%', align: "center",templet: '#is-state'},
{field: 'orgSort', title: '排序', width: '8%',align: "center"},
{field: 'remarks', title: '备注信息', width: '15%',align: "center"},
{toolbar: '#menusState', width: '10%', align: 'center', title: '操作'}
]],
style: 'margin-top:0;'
});
treeTable.on('tool(dt-table)', function (obj) {
console.log(obj)
let data = obj.data;
let layEvent = obj.event;
if (layEvent === 'edit') {
addData(data.id, data.parentId);
} else if (layEvent === 'del') {
delData(data.id);
}
});
form.render();
}
}
// 获取组织机构treeTable
function getOrgTreeTable(type) {
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
let params = getReqParams(type);
let url = dataUrl + "/sys/org/getOrgList";
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
layer.close(loadingMsg);
if (result.status === 200) {
treemenu.reload(result.data);
} else if (result.status === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
layer.close(loadingMsg);
});
}
// 获取参数
function getReqParams(type) {
let obj = {};
if (!type) {
obj = {
orgName: $('#orgName').val(),
abbName: $('#abbName').val(),
orgCode: $('#orgCode').val()
};
} else {
obj = {
orgName: '',
abbName: '',
orgCode: ''
};
}
obj = {
encryptedData: encryptCBC(JSON.stringify(obj))
}
return obj;
}
// 查询/重置
function query() {
let pattern = new RegExp("[%<>]");
if (pattern.test($("#orgName").val())) {
$("#orgName").val('');
return layer.msg('组织机构名称查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
if (pattern.test($("#abbName").val())) {
$("#abbName").val('');
return layer.msg('组织机构简称查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
if (pattern.test($("#orgCode").val())) {
$("#orgCode").val('');
return layer.msg('机构编码查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
getOrgTreeTable();
}
function reloadData() {
getOrgTreeTable();
}
// 新增/修改平台用户
function addData(id, pId) {
let title = '新增组织'
if (id) {
title = '修改组织';
}
let param = {
'id': id,
'pId': pId
}
openIframe2("addOrEditOrg", title, "child/sysOrgForm.html", '875px', '625px', param);
}
/*删除组织机构*/
function delData(id) {
layer.confirm("确定删除吗?", {
move: false
}, function () {
let loadingMsg = layer.msg('数据删除中,请稍候...', {icon: 16, scrollbar: false, time: 0});
let url = dataUrl + "/sys/org/delSysOrg"
let obj = {'id': id}
let params = {
encryptedData: encryptCBC(JSON.stringify(obj))
}
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
layer.close(loadingMsg); // 关闭提示层
if (result.status === 200) {
parent.layer.msg(result.msg, {icon: 1})
query()
} else if (result.status === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
});
})
}