<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="${ctxPlugin}/static/element-ui/index.css">
    <!-- 引入组件库 -->
    <script src="${ctxPlugin}/static/element-ui/vue.min.js"></script>
    <script src="${ctxPlugin}/static/element-ui/index.js"></script>
    <style>
        .el-button--text{ color: #D9B589 !important}
    </style>
</head>
<body>

<div class="layui-fluid"  id="app">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="JXSGL_JXSGL_JXSGL_T" html='<li class="layui-this"><a href="${ctx}/departmentSetting/index">部门设置</a></li>'/>
             <%--   <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>查询
                </button>--%>
            </ul>
        </div>

        <div class="layui-card-body layuiadmin-card-header-auto">
            <div>
                <button class="layui-btn mt-10 mb-15  " data-type="reload" id="addBtn">
                    <i class="layui-icon layui-icon-add-1"></i>新增
                </button>
            </div>
            <el-table
                    :data="tableData"
                    style="width: 100%;margin-bottom: 20px;"
                    row-key="id"
                    border
                    default-expand-all
                    :height="tableHeight"
                    :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
                <el-table-column prop="name" label="部门编号"></el-table-column>
                <el-table-column prop="createTime" label="创建时间" width="280"></el-table-column>
                <el-table-column align="center" label="操作" class-name="small-padding fixed-width" fixed="right" width="100">
                    <template slot-scope="scope" v-if="scope.row.id !='d56d5797dd9049fead6bb4c19040d2f0'">

                        <el-button type="text" size="mini" @click="handleEdit(scope.row)" >编辑</el-button>
                        <el-button type="text" size="mini" @click="handleDelete(scope.row.id)">删除</el-button>

                    </template>
                </el-table-column>
            </el-table>
        </div>

        <div class="layui-card-body">
            <table class="layui-hide " id="test" lay-filter="test"></table>
        </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="FAGL_FAGL_FAGL_ADD_B" html='<button class="layui-btn layui-btn-sm" id="addBtn" lay-event="add"><i class="layui-icon layui-icon-add-1"></i>添加 </button>'/>

</div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>

<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var $;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'jquery', 'layer','form',], function(){
        $ = layui.$
            ,form = layui.form;

        new Vue({
            el: '#app',
            data: function() {
                return {
                    tableHeight: 10,
                    tableData: [],
                    dialogTitle: '1',
                    showDialog: false,
                }
            },
            mounted() {
                this.$nextTick(() => {
                    this.tableHeight = window.innerHeight - 168
                })
                getAjax('${ctx}/departmentSetting/getDepartList' , 'post' , {} , (res) => {
                    if(res){
                        setTimeout(()=>{
                            this.tableData = res;
                        },100);
                    }else{
                        console.log('出错了');
                    }
                })
            },
            methods:{
                handleEdit(row){
                    layer.open({
                        type: 2,
                        title: '编辑部门',
                        content: '${ctx}/departmentSetting/addDep?id='+row.id,
                        area: ['50%','52%'],
                        success: function(layero, index) {
                            childWin = window[layero.find('iframe')[0]['name']];
                        }
                    });
                },
                handleDelete(id){
                    layer.confirm('确认删除该部门？',{icon:3}, function(index){
                    $.post('${ctx}/departmentSetting/deleteDepartment', {id: id}, function(result){
                        if("200" == result.code){
                            layer.msg("删除成功", {icon:1});
                               setDep();
                        }else if("203"==result.code){
                            layer.msg(result.msg, {icon:2});
                        }else{
                            layer.msg("保存失败", {icon:2});
                        }
                    });
                    });
                }
            }
        })


        $('#addBtn').on('click', function(){
            layer.open({
                type: 2,
                title: '新增部门',
                content: '${ctx}/departmentSetting/addDep',
                area: ['50%','52%'],
                success: function(layero, index) {
                    childWin = window[layero.find('iframe')[0]['name']];
                }
            });
        });

    });

    function setDep(){
        window.location.reload();
    }
    //Ajax请求
    function getAjax( url , type , dataJson , callback ){``
        $.ajax({
            url: url,
            type: type,
            data: dataJson,
            dataType: "json",
            beforeSend:function(){
            },
            success: function (data) {
                callback(data);
            },
            error: function (data) {
                //getAjax(url , dataJson);
            }
        });
    }

</script>
</body>
</html>
