Files
pear-admin-flask/templates/admin/department/main.html
T

257 lines
7.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>部门新增</title>
{% include 'admin/common/header.html' %}
</head>
{#pear 后台边框#}
<body class="pear-container">
{#搜索框布局#}
<div class="layui-card">
<div class="layui-card-body">
<form class="layui-form" action="">
<div class="layui-form-item">
<label class="layui-form-label">部门名称</label>
<div class="layui-input-inline">
{#部门信息搜索字段#}
<input type="text" name="deptName" placeholder="" class="layui-input">
</div>
{#查询按钮--需要触发layui事件#}
<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="form_search">
<i class="layui-icon layui-icon-search"></i>
查询
</button>
{#重置按钮#}
<button type="reset" class="pear-btn pear-btn-md">
<i class="layui-icon layui-icon-refresh"></i>
重置
</button>
</div>
</form>
</div>
</div>
<div class="layui-card">
<div class="layui-card-body">
{#表格字段渲染#}
<table id="tables" lay-filter="tables"></table>
</div>
</div>
{#表格工具栏,需要在表格中绑定,且需要自定义事件#}
<script type="text/html" id="toolbaes">
{% if authorize("admin:dept:edit") %}
<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add_toggle">
<i class="layui-icon layui-icon-add-1"></i>
新增
</button>
{% endif %}
{% if authorize("admin:dept:remove") %}
<button class="pear-btn pear-btn-md" lay-event="batch_remove">
<i class="layui-icon layui-icon-delete"></i>
删除
</button>
{% endif %}
</script>
{#操作字段,需要在表格中使用#}
<script type="text/html" id="tools">
<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="tools_edit">
<i class="layui-icon layui-icon-edit"></i>
</button>
<button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="tools_remove">
<i class="layui-icon layui-icon-delete"></i>
</button>
</script>
{#表格内的切换按钮#}
<script type="text/html" id="dept-status">
<input type="checkbox"
name="status"
value="{{ "{{ d.deptId }}" }}"
lay-skin="switch"
lay-text="启用|禁用"
lay-filter="dept_enable"
{{ "{{# if(d.status==1){ }} checked {{# } }}" }}>
</script>
</body>
{% include 'admin/common/footer.html' %}
<script type="module">
import { DEPARTMENT_API } from '/static/api/http.js'
layui.use(['table', 'form', 'jquery', 'treetable', 'popup'], function () {
let table = layui.table
let form = layui.form
let $ = layui.jquery
let treetable = layui.treetable
let popup = layui.popup
let MODULE_PATH = '/dept/'
{#定义表格渲染函数#}
window.render = function () {
/*树形表格渲染*/
treetable.render({
treeColIndex: 1,
treeSpid: 0,
treeIdName: 'deptId', /*表格的顶级字段*/
treePidName: 'parentId', /*父级id选项*/
skin: 'line',
method: 'post', /**/
treeDefaultClose: false,
toolbar: '#toolbaes', /*表格的工具栏*/
elem: '#tables', /*表格挂载的对象*/
url: DEPARTMENT_API.DEPARTMENTS(), /*数据来源接口*/
page: false,
cols: [
[
{ type: 'checkbox' },
{ field: 'deptName', minWidth: 200, title: '部门名称' },
{ field: 'leader', title: '负责人' },
{ field: 'phone', title: '联系方式' },
{ field: 'email', title: '邮箱' },
{ field: 'address', title: '详细地址' },
{ field: 'status', title: '状态', templet: '#dept-status' },
{ field: 'sort', title: '排序', width: 100 },
{ title: '操作', templet: '#tools', width: 120, align: 'center' }
]
]/*表格渲染的数据*/
})
}
/*查询表单按钮被点击的事件*/
form.on('submit(form_search)', function (data) {
let keyword = $.trim(data.field.deptName)
/*获取所有的公司节点*/
let $tds = $('#tables').next('.treeTable').find('.layui-table-body tbody tr td')
if (!keyword) {
$tds.css('background-color', 'transparent')
layer.msg('请输入关键字', { icon: 5 })
return false
}
/*本地查询并且标注高亮*/
let searchCount = 0
$tds.each(function () {
$(this).css('background-color', 'transparent')
if ($(this).text().indexOf(keyword) >= 0) {
$(this).css('background-color', 'rgba(250,230,160,0.5)')
if (searchCount === 0) {
$('body,html').stop(true)
$('body,html').animate({ scrollTop: $(this).offset().top - 150 }, 500)
}
searchCount++
}
})
if (searchCount === 0) {
layer.msg('没有匹配结果', { icon: 5 })
} else {
treetable.expandAll('#tables')
}
return false
})
render()
/*表格的操作栏*/
table.on('tool(tables)', function (obj) {
if (obj.event === 'tools_remove') {
/*移出事件*/
window.tools_remove(obj)
} else if (obj.event === 'tools_edit') {
/*编辑事件*/
window.tools_edit(obj)
}
})
/*表格的工具栏*/
table.on('toolbar(tables)', function (obj) {
{#console.log(obj)#}
if (obj.event === 'add_toggle') {
window.add_toggle()
} else if (obj.event === 'refresh') {
window.refresh()
} else if (obj.event === 'batch_remove') {
{#window.batch_remove(obj)#}
layer.msg('禁止批量删除')
return false
{#console.log(table.checkStatus(obj.config.id).data)#}
}
})
/*切换选择状态*/
form.on('switch(dept_enable)', function (obj) {
let operate
if (obj.elem.checked) {
operate = 1
} else {
operate = 0
}
let loading = layer.load()
$.ajax({
url: DEPARTMENT_API.DEPARTMENT_STATUS(this.value),
data: JSON.stringify({ deptId: this.value, operate: operate }),
dataType: 'json',
contentType: 'application/json',
type: 'put',
success: function (result) {
layer.close(loading)
if (result.success) {
popup.success(result.msg)
} else {
popup.failure(result.msg)
}
}
})
})
window.add_toggle = function () {
layer.open({
type: 2,
title: '新增',
shade: 0.1,
area: ['450px', '500px'], /*新增窗口的大小*/
content: MODULE_PATH + 'add' /*新增窗口从那里来*/
})
}
window.tools_edit = function (obj) {
layer.open({
type: 2,
title: '修改',
shade: 0.1,
area: ['450px', '500px'],
content: MODULE_PATH + 'edit?deptId=' + obj.data['deptId'] /*编辑修改窗口从那里来*/
})
}
window.tools_remove = function (obj) {
layer.confirm('确定要删除该部门', { icon: 3, title: '提示' }, function (index) {
layer.close(index)
let loading = layer.load()
$.ajax({
url: DEPARTMENT_API.DEPARTMENT(obj.data['deptId']),
dataType: 'json',
type: 'delete',
success: function (result) {
layer.close(loading)
if (result.success) {
popup.success(result.msg, function () {
obj.del()
})
} else {
popup.failure(result.msg)
}
}
})
})
}
})
</script>
</html>