190 lines
9.1 KiB
HTML
190 lines
9.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-cn">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>科室管理</title>
|
|
<link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" />
|
|
<link rel="stylesheet" href="/app/admin/admin/css/reset.css" />
|
|
</head>
|
|
<body class="pear-container">
|
|
|
|
<div class="layui-card">
|
|
<div class="layui-card-body">
|
|
<form class="layui-form top-search-from">
|
|
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">所属医院</label>
|
|
<div class="layui-input-block">
|
|
<div id="hospitalSelect"></div>
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item">
|
|
<label class="layui-form-label">科室名称</label>
|
|
<div class="layui-input-block">
|
|
<input type="text" name="dept_name" placeholder="请输入" class="layui-input" lay-affix="clear">
|
|
</div>
|
|
</div>
|
|
<div class="layui-form-item layui-inline">
|
|
<label class="layui-form-label"></label>
|
|
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
|
|
<i class="layui-icon layui-icon-search"></i>查询
|
|
</button>
|
|
<button type="reset" class="pear-btn pear-btn-md" lay-submit lay-filter="table-reset">
|
|
<i class="layui-icon layui-icon-refresh"></i>重置
|
|
</button>
|
|
</div>
|
|
<div class="toggle-btn">
|
|
<a class="layui-hide">展开<i class="layui-icon layui-icon-down"></i></a>
|
|
<a class="layui-hide">收起<i class="layui-icon layui-icon-up"></i></a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="layui-card">
|
|
<div class="layui-card-body">
|
|
<table id="data-table" lay-filter="data-table"></table>
|
|
</div>
|
|
</div>
|
|
|
|
<script type="text/html" id="table-toolbar">
|
|
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
|
|
<i class="layui-icon layui-icon-add-1"></i>新增
|
|
</button>
|
|
<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
|
|
<i class="layui-icon layui-icon-delete"></i>删除
|
|
</button>
|
|
</script>
|
|
|
|
<script type="text/html" id="table-bar">
|
|
<button class="pear-btn pear-btn-xs tool-btn" lay-event="edit">编辑</button>
|
|
<button class="pear-btn pear-btn-xs tool-btn" lay-event="remove">删除</button>
|
|
</script>
|
|
|
|
<script src="/app/admin/component/layui/layui.js?v=2.8.12"></script>
|
|
<script src="/app/admin/component/pear/pear.js"></script>
|
|
<script src="/app/admin/admin/js/permission.js"></script>
|
|
<script src="/app/admin/admin/js/common.js"></script>
|
|
|
|
<script>
|
|
const PRIMARY_KEY = "id";
|
|
const SELECT_API = "/app/admin/department/select";
|
|
const DELETE_API = "/app/admin/department/delete";
|
|
const INSERT_URL = "/app/admin/department/insert";
|
|
const UPDATE_URL = "/app/admin/department/update";
|
|
const HOSPITAL_OPTIONS_API = "/app/admin/hospital/options";
|
|
|
|
layui.use(["table", "form", "common", "popup", "xmSelect"], function() {
|
|
let table = layui.table, form = layui.form, $ = layui.$, common = layui.common;
|
|
|
|
// 医院多选下拉
|
|
let hospitalSelect = null;
|
|
$.ajax({
|
|
url: HOSPITAL_OPTIONS_API, dataType: "json", type: "get",
|
|
success: function(res) {
|
|
hospitalSelect = layui.xmSelect.render({
|
|
el: "#hospitalSelect",
|
|
name: "organ_id",
|
|
tips: "全部医院",
|
|
filterable: true,
|
|
searchTips: "搜索医院",
|
|
data: res.data || []
|
|
});
|
|
}
|
|
});
|
|
|
|
let cols = [
|
|
{ type: "checkbox", align: "center" },
|
|
{ title: "ID", field: "id", align: "center", width: 80, sort: true },
|
|
{ title: "所属医院", field: "hospital_name", align: "center", minWidth: 200 },
|
|
{ title: "科室名称", field: "dept_name", align: "center", minWidth: 150 },
|
|
{ title: "科室编码", field: "dept_code", align: "center", width: 120 },
|
|
{ title: "创建时间", field: "created_at", align: "center", width: 170, sort: true },
|
|
{ title: "操作", toolbar: "#table-bar", align: "center", fixed: "right", width: 150 }
|
|
];
|
|
|
|
table.render({
|
|
elem: "#data-table", url: SELECT_API, page: true, cols: [cols],
|
|
skin: "line", size: "lg", toolbar: "#table-toolbar", autoSort: false,
|
|
defaultToolbar: [{ title: "刷新", layEvent: "refresh", icon: "layui-icon-refresh" }, "filter", "print", "exports"]
|
|
});
|
|
|
|
table.on("tool(data-table)", function(obj) {
|
|
if (obj.event === "remove") doRemove(obj.data[PRIMARY_KEY]);
|
|
else if (obj.event === "edit") edit(obj);
|
|
});
|
|
table.on("toolbar(data-table)", function(obj) {
|
|
if (obj.event === "add") add();
|
|
else if (obj.event === "refresh") refreshTable();
|
|
else if (obj.event === "batchRemove") batchRemove(obj);
|
|
});
|
|
|
|
form.on("submit(table-query)", function(data) {
|
|
let where = data.field;
|
|
// 处理医院多选
|
|
if (hospitalSelect) {
|
|
let vals = hospitalSelect.getValue("value");
|
|
if (vals.length > 0) {
|
|
where["organ_id[0]"] = "in";
|
|
where["organ_id[1]"] = vals.join(",");
|
|
}
|
|
}
|
|
delete where.organ_id;
|
|
table.reload("data-table", { page: { curr: 1 }, where: where });
|
|
return false;
|
|
});
|
|
|
|
form.on("submit(table-reset)", function() {
|
|
if (hospitalSelect) hospitalSelect.setValue([]);
|
|
table.reload("data-table", { where: [] });
|
|
});
|
|
|
|
table.on("sort(data-table)", function(obj) {
|
|
table.reload("data-table", { initSort: obj, scrollPos: "fixed", where: { field: obj.field, order: obj.type } });
|
|
});
|
|
|
|
let add = function() {
|
|
layer.open({
|
|
type: 2, title: "新增科室", shade: 0.1, maxmin: true,
|
|
area: [common.isModile() ? "100%" : "500px", common.isModile() ? "100%" : "450px"],
|
|
content: INSERT_URL
|
|
});
|
|
}
|
|
let edit = function(obj) {
|
|
layer.open({
|
|
type: 2, title: "编辑科室", shade: 0.1, maxmin: true,
|
|
area: [common.isModile() ? "100%" : "500px", common.isModile() ? "100%" : "450px"],
|
|
content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + obj.data[PRIMARY_KEY]
|
|
});
|
|
}
|
|
let batchRemove = function(obj) {
|
|
let checkIds = common.checkField(obj, PRIMARY_KEY);
|
|
if (checkIds === "") { layui.popup.warning("未选中数据"); return false; }
|
|
doRemove(checkIds.split(","));
|
|
}
|
|
let doRemove = function(ids) {
|
|
let data = {}; data[PRIMARY_KEY] = ids;
|
|
layer.confirm("确定删除?", { icon: 3, title: "提示" }, function(index) {
|
|
layer.close(index);
|
|
let loading = layer.load();
|
|
$.ajax({ url: DELETE_API, data: data, dataType: "json", type: "post",
|
|
success: function(res) {
|
|
layer.close(loading);
|
|
if (res.code) return layui.popup.failure(res.msg);
|
|
return layui.popup.success("操作成功", refreshTable);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
window.refreshTable = function() {
|
|
table.reloadData("data-table", { scrollPos: "fixed",
|
|
done: function(res, curr) {
|
|
if (curr > 1 && res.data && !res.data.length) table.reloadData("data-table", { page: { curr: curr - 1 } });
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|