<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <title>能辉光伏</title>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card{box-shadow: none;}
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
               <%-- <sfTags:pagePermission authFlag="XTSZ_YGSZ_JSGL_T" html='<li class="sf-tab"><a href="${ctx}/member/setRole">角色管理</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_YGSZ_QXKZ_T" html='<li class="sf-tab"><a href="${ctx}/member/roleIndex">权限设置</a></li>'/>
                <sfTags:pagePermission authFlag="XTSZ_YGSZ_YGSZ_T" html='<li class="layui-this sf-tab"><a href="${ctx}/member/index">人员管理</a></li>'/>
--%>
                <c:if test="${user.userType eq '6' || user.userType eq '7'}">
                    <sfTags:pagePermission authFlag="XTSZFWS_YGSZ_JSGL_T" html='<li class="sf-tab"><a href="${ctx}/member/setRole">角色管理</a></li>'/>
                    <sfTags:pagePermission authFlag="XTSZFWS_YGSZ_QXKZ_T" html='<li class="sf-tab"><a href="${ctx}/member/roleIndex">权限设置</a></li>'/>
                    <sfTags:pagePermission authFlag="SIT_XTSZ_YGSZ_YGXX_T" html='<li class="sf-tab layui-this"><a href="${ctx}/traderEmploye/traderEmployeeList">员工信息</a></li>'/>
                </c:if>

                <c:if test="${user.userType ne '6' && user.userType ne '7'}">
                    <sfTags:pagePermission authFlag="XTSZ_YGSZ_JSGL_T" html='<li class="sf-tab"><a href="${ctx}/member/setRole">角色管理</a></li>'/>
                    <sfTags:pagePermission authFlag="XTSZ_YGSZ_QXKZ_T" html='<li class="sf-tab"><a href="${ctx}/member/roleIndex">权限设置</a></li>'/>
                    <sfTags:pagePermission authFlag="XTSZ_YGSZ_YGSZ_T" html='<li class="sf-tab layui-this"><a href="${ctx}/member/index">人员管理</a></li>'/>
                </c:if>
                <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" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" id="form-name" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">手机号：</label>
                    <div class="layui-input-block">
                        <input type="text" id="form-mobile" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">角色：</label>
                    <div class="layui-input-block">
                        <select name="roleIds" id="roleIds" lay-search >
                            <option value="">请选择</option>
                            <c:forEach items="${roles}" var="role">
                                <option value="${role.columns.id}" >${role.columns.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test-table-reload" lay-filter="table-toolbar"></table>
            <script type="text/html" id="toolbarDemo">
                <sfTags:pagePermission authFlag="YGSZ_TJYG_B" html='<button class="layui-btn layui-btn-sm" id="addEmployeeBtn" lay-event="addEmployeeBtn"><i class="layui-icon layui-icon-add-1"></i>添加人员</button>'/>
            </script>
        </div>
    </div>

</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/html" id="table-toolbar">
    <sfTags:pagePermission authFlag="YGSZ_BJ_B" html='<a href="#" class="layui-table-link" lay-event="edit">编辑</a>'/>
    <sfTags:pagePermission authFlag="YGSZ_SC_B" html='<a href="#" class="layui-table-link ml-20" lay-event="del">删除</a>'/>
    <sfTags:pagePermission authFlag="YGSZ_JSGL_SC_B" html='<a href="#" class="layui-table-link ml-20" lay-event="rights">数据权限</a>'/>
</script>

<script type="text/javascript">
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer'], function(){
        var tableExt = layui.tableExt;
        var layer = layui.layer;
         $ = layui.jquery;
        tableExt.render({
            elem: '#test-table-reload'
            ,toolbar : '#toolbarDemo'
            , height: 'full-150'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/member/getMemberData'
            ,cols: [[
                {type: 'numbers',title:'序号'}
                ,{field:'id', title: '操作',toolbar: '#table-toolbar',align: 'center',minWidth: 280, }
                /*,{field:'status', title: '状态',
                    templet: function(d){
                        return d.status == '0' ? '正常' : '';
                    },
                    exportable:true,            //开启导出功能
                    expFormat: function(data){  //格式导出的化字段
                        console.log("expFormat:", data);
                        return "哈哈";
                    }
                }*/
                ,{field:'login_name', title: '账号',align: 'center'}
                ,{field:'name', title: '姓名',align: 'center'}
                ,{field:'roles', title: '角色',align: 'center'}
                ,{field:'gsname', title: '部门名称',align: 'center'}
                ,{field:'mobile', title: '手机号',align: 'center'}
                ,{field:'hiredate', title: '入职时间',align: 'center'}
                ,{field:'create_time', title: '创建时间',align: 'center'}
            ]]
            ,done: function(res, curr, count){
             //   console.log("customer done", res);
            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '员工列表',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '员工导出',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    var ret = {};
                    ret.name= $("#form-name").val();
                    ret.mobile= $("#form-mobile").val();
                    ret.roleIds=$("#roleIds").val();
                    return ret;
                }
            }
        });

         table = tableExt.getLayTable();

        //监听行工具事件
        table.on('tool(table-toolbar)', function(obj){
            var data = obj.data;
            var memberId = data.id;
            if(obj.event === 'del'){
                layer.confirm('真的删除所选人员吗？',{
                    btn: ['确定', '取消'],
                    success: function (layero, index) {
                        this.enterEsc = function (event) {
                            if (event.keyCode == 13 ) {
                                //确认  执行的代码
                                deleteEmp(memberId);
                                //关闭弹窗
                                layer.close(index);
                                console.log("回车确认时事件")
                                //取消连续回车键，导致不断弹出询问框
                                $(':focus').blur();
                            }
                        };
                        //监听键盘事件
                        $(document).on('keydown', this.enterEsc);
                        //esc键触发取消
                        this.escQuit = (ev) => {
                            let code_val = ev.which;
                            if(code_val == 0x1B){
                                $('.layui-layer-btn1').click();
                                return false;
                            }
                        };
                        $(document).on('keydown', this.escQuit);
                    },
                    end: function () {
                        //取消键盘监听事件
                        $(document).off('keydown', this.enterEsc);
                        $(document).off('keydown', this.escQuit);
                    },
                    yes: function () {
                        //确认执行的代码
                        deleteEmp(memberId);
                    },
                    no: function () {

                    }
                });
            } else if(obj.event === 'edit'){
                goMemberform('编辑员工信息', '${ctx}/member/memberFormNew?id=' + memberId);
            } else if(obj.event === 'rights'){

                layer.open({
                    type: 2
                    , title: '编辑数据权限'
                    , area: ['70%', '100%']
                    , content: '${ctx}/member/rightsForm?id='+memberId
                })
            }
        });

        var active = {
            reload: function(){
                table.reload('test-table-reload', {
                    where: {
                        name: $('#form-name').val(),
                        mobile: $("#form-mobile").val(),
                        roleIds:$("#roleIds").val()
                    }
                });
            }
        };

        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

      /*  $("#addEmployeeBtn").on('click', function(){
            goMemberform('添加员工', '${ctx}/member/memberForm');
        });*/

        table.on('toolbar(table-toolbar)', function(obj) {
            switch (obj.event) {
                case 'addEmployeeBtn':
                    goMemberform('添加员工', '${ctx}/member/memberForm');
                    break;
            }
        })

    });

    function deleteEmp(memberId){
        $.post('${ctx}/member/delMember', {id: memberId}, function(result){
            if("ok" == result){
                layer.msg('操作成功', {time: 2000}, function () {
                    reload();
                });
            }else{
                layer.msg("删除失败");
            }
        });
    }

    function reload(){
        table.reload('test-table-reload', {
            page:{
                curr:1
            }
        });
    }


    function goMemberform(title, url){
        layer.open({
            title:title,
            type: 2,
            area: ["55%", "60%"],
            fixed: false,
            content: url
        })
    }

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