基础管理

This commit is contained in:
jjLv 2024-07-25 15:53:25 +08:00
parent a0385f5fd6
commit d8f85ef539
1 changed files with 229 additions and 0 deletions

View File

@ -0,0 +1,229 @@
let form, layer, table, tableIns;
let pageNum = 1, limitSize = 10; // 默认第一页分页数量为10
let deptPid = null
function setParams(params) {
deptPid = JSON.parse(params).pid;
layui.use(['form', 'layer', 'table', 'laydate'], function () {
form = layui.form;
layer = layui.layer;
table = layui.table;
layui.form.render();
// getDevSelected();
pages(1, 10, 1);
})
}
function pages(pageNum, pageSize, typeNum) {
let params = getReqParams(pageNum, pageSize, typeNum);
console.log(params)
let url = dataUrl + "/customs/getListDept"
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
console.log(result);
if (result.code === 200) {
if (result.data) {
initTable(result.data, result.limit, result.curr)
laypages(result.count, result.curr, result.limit)
}
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
}
function laypages(total, page, limit) {
layui.use(['laypage'], function () {
let laypage = layui.laypage;
laypage.render({
elem: 'voi-page',
count: total,
curr: page,
limit: limit,
limits: [10, 20, 50, 100, 200, 500],
layout: ['prev', 'page', 'next', 'skip', 'count', 'limit'],
groups: 5,
jump: function (obj, first) {
if (!first) {
pageNum = obj.curr, limitSize = obj.limit;
pages(obj.curr, obj.limit, null);
}
}
});
})
}
/*初始化表格*/
function initTable(dataList, limit, page) {
let loadingMsg = layer.msg("数据加载中,请稍候...", {icon: 16, scrollbar: false, time: 0,});
tableIns = table.render({
elem: "#table_data",
height: "full-130",
data: dataList,
limit: limit,
cols: [
[
//表头
{title: "序号", width: 80, unresize: true, align: "center",
templet: function (d) {
return (page - 1) * limit + d.LAY_INDEX;
}
},
{field: "customId", title: "ID", unresize: true, align: "center",hide:true},
{field: "customName", title: "部门名称", unresize: true, align: "center"},
{field: "deptId", title: "组织类型", unresize: true, align: "center",hide:true,
templet: function (d) {
if (d.deptId == 0) {
return "单位";
} else if (d.deptId == 1) {
return "部门";
}
}
},
{field: "pid", title: "上级单位", unresize: true, align: "center",hide:true},
{field: "customType", title: "客户类型", unresize: true, align: "center"},
{field: "customUser", title: "联系人", unresize: true, align: "center"},
{field: "customPhone", title: "联系方式", unresize: true, align: "center"},
// {field: "customStatus", title: "状态", align: "center",templet: '#is-state'},
{title: "操作", unresize: true, width: 300, align: "center",
templet: function (d) {
let html = '';
let del="<a class=\"layui-icon layui-icon-delete\" style='cursor:pointer;' title='删除' onclick=\"delData('" + d.customId + "')\"></a>"
let edit="<a class=\"layui-icon layui-icon-edit\" style='cursor:pointer;' title='修改' onclick=\"addData('" + d.customId + "')\"></a>";
html=edit+del;
return html;
}
},
],
],
done: function (res, curr, count) {
layer.close(loadingMsg);
table.resize("table_data");
count || this.elem.next(".layui-table-view").find(".layui-table-header").css("display", "inline-block");
count || this.elem.next(".layui-table-view").find(".layui-table-box").css("overflow", "auto");
},
});
}
// 获取参数
function getReqParams(page, limit, type) {
let obj = {};
if (!type) {
obj = {
page: page + "",
limit: limit + "",
customName: $('#customName').val(),
pid:deptPid
};
} else {
obj = {
page: '1',
limit: '10',
customName: '',
pid:deptPid
};
}
console.log(obj)
obj={
encryptedData:encryptCBC(JSON.stringify(obj))
}
return obj;
}
// 查询/重置
function query() {
let pattern = new RegExp("[%_<>]");
if (pattern.test($("#loginName").val())) {
$("#loginName").val('');
return layer.msg('用户名查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
if (pattern.test($("#phone").val())) {
$("#phone").val('');
return layer.msg('手机号查询包含特殊字符,请重新输入', {
icon: 2,
time: 2000 //2秒关闭如果不配置默认是3秒
});
}
pageNum = 1;
pages(1, limitSize);
}
function reloadData() {
pages(pageNum, limitSize);
}
// 新增/修改平台用户
function addData(customId) {
console.log()
let title = '新增单位客户'
if (customId) {
title = '修改单位客户';
}
let param = {
'customId': customId,
'pid': deptPid
}
openIframe2("addOrEditFormUser", title, "customAddDeptForm.html", '800px', '500px', param);
}
/*删除用户*/
function delData(customId) {
layer.confirm("确定删除吗?", {
move: false
}, function () {
let loadingMsg = layer.msg('数据删除中,请稍候...', {icon: 16, scrollbar: false, time: 0});
let url = dataUrl + "/customs/delById";
let params = {
'customId': customId
}
params={
encryptedData:encryptCBC(JSON.stringify(params))
}
ajaxRequest(url, "POST", params, true, function () {
}, function (result) {
layer.close(loadingMsg); // 关闭提示层
if (result.code === 200) {
parent.layer.msg(result.msg, {icon: 1})
query()
} else if (result.code === 500) {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
layer.close(loadingMsg); // 关闭提示层
error(xhr)
});
})
}
function getRoleSelected() {
let url = dataUrl + '/roles/all';
ajaxRequest(url, "POST", null, true, function () {
}, function (result) {
if (result.code === 200) {
setSelectValue(result.data, 'roleId');
} else {
layer.alert(result.msg, {icon: 2})
}
}, function (xhr) {
error(xhr)
});
}
/*下拉选表单赋值*/
function setSelectValue(list, selectName) {
let html = '<option value="" selected>请选择角色</option>';
$.each(list, function (index, item) {
html += '<option value="' + item.id + '">' + item.name + '</option>';
})
$('#' + selectName).empty().append(html);
layui.form.render();
}