123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- {extend name="common/base"/}
- <!-- 主体 -->
- {block name="body"}
- <div class="p-3">
- <div class="gg-form-bar border-t border-x" style="padding-bottom:10px;">
- <button class="layui-btn layui-btn-sm add-menu">+ 添加部门</button>
- </div>
- <div>
- <table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
- </div>
- </div>
- {/block}
- <!-- /主体 -->
- <!-- 脚本 -->
- {block name="script"}
- <script>
- const moduleInit = ['tool', 'treeGrid'];
- function gouguInit() {
- var treeGrid = layui.treeGrid,table = layui.table, tool = layui.tool;
- var allcount;
- var pageTable = treeGrid.render({
- id: 'treeTable'
- , elem: '#treeTable'
- , idField: 'id'
- , url: "/admin/department/index"
- , cellMinWidth: 80
- , treeId: 'id'//树形id字段名称
- , treeUpId: 'pid'//树形父id字段名称
- , treeShowName: 'title'//以树形式显示的字段
- , height: 'full-0'
- ,isOpenDefault:true
- ,parseData: function(res) { // 数据解析回调函数
- // 在这里可以获取数据总数
- allcount = res.data.length;
- console.log(res.data.length)
- return {
- code: res.code, // 数据状态码
- msg: res.msg, // 状态信息
- count: res.count, // 数据总数
- data: res.data // 当前页数据
- };
- },
- cols: [[
- {fixed: 'left', field: 'id', title: '编号', align: 'center', width: 80,
- templet: function(d){
- console.log(d)
- return allcount - (d.LAY_INDEX-1);
- }
- }, { field: 'pid', title: '上级部门ID',width: 120, align: 'center'}
- , { field: 'title', title: '部门名称'}
- , { field: 'leader', title: '部门负责人',width: 120, align: 'center'}
- , { field: 'phone', title: '部门电话',width: 160,}
- , { width:180, title: '操作', align: 'center', templet: function (d) {
- var html = '<span class="layui-btn-group"><button class="layui-btn layui-btn-xs" lay-event="add">添加下级部门</button><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></span>';
- return html;
- }
- }
- ]]
- , page: false
- });
-
- //表头工具栏事件
- $('body').on('click','.add-menu', function(){
- tool.side("/admin/department/add");
- return;
- });
- //操作按钮
- treeGrid.on('tool(treeTable)', function (obj) {
- if (obj.event === 'add') {
- tool.side("/admin/department/add?pid="+obj.data.id);
- return;
- }
- if (obj.event === 'edit') {
- tool.side("/admin/department/add?id="+obj.data.id);
- return;
- }
- if (obj.event === 'del') {
- layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
- let callback = function (e) {
- layer.msg(e.msg);
- if (e.code == 0) {
- obj.del();
- }
- }
- tool.delete("/admin/department/delete", { id: obj.data.id }, callback);
- layer.close(index);
- });
- }
- });
- }
- </script>
- {/block}
- <!-- /脚本 -->
|