<%@ 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">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <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="layui-this"><a href="${ctx}/traderEmploye/traderEmployeeList">员工信息</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" >
            <form class="layui-form layui-card" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">名称：</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" class="layui-input" id="name" >
                        </div>
                    </div>
                    <div class="layui-col-md2 layui-col-sm3">
                        <label class="layui-form-label">联系电话：</label>
                        <div class="layui-input-block">
                            <input type="text" name="mobile" class="layui-input" id="mobile" >
                        </div>
                    </div>
                </div>
            </form>
        </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">
   <button class="layui-btn layui-btn-sm" id="addBtn" lay-event="addEmploye"><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 upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
        table = layui.table;
        tableExt.render({
            elem: '#test'
            , height: 'full-130'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/traderEmploye/getTraderEmployeeData'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
            , toolbar:"#toolbarDemo"
            , method:"post"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {type: 'numbers',title:'序号'}
                ,{field :'user_id',hide:true }
                , {field: 'moble', title: '操作', width: 250, align: 'center',
                    templet: function (d) {
                        var add='';

                        add += '<a class="layui-table-opt-link" lay-event="edit">编辑</a>';
                        add += '<a class="layui-table-opt-link ml-15" lay-event="delete">删除</a>'
                        add += '<a class="layui-table-opt-link ml-15" lay-event="dateRight">数据权限</a>'
                        if(isBlank(add)){
                            add+='--';
                        }
                        return add;
                    },
                }
                ,{field:'name', title: '姓名',align: 'center'}
                ,{field:'login_name', title: '登录帐号',align: 'center'}
                ,{field:'mobile', title: '联系电话',align: 'center'}
                ,{field:'role_name', title: '角色',align: 'center'}
                ,{field:'job_number', title: '工号',align: 'center'}
                ,{field:'hiredate', title: '入职时间',align: 'center'}
            ]]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '员工信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '员工信息',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)',function(obj) {
            if (obj.event === 'addEmploye') {
                layer.open({
                    type: 2,
                    title: '添加员工',
                    content: '${ctx}/traderEmploye/addEmployee',
                    area: ['100%', '100%']
                });
            }
        });

        //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {//编辑地址
                var id = data.id;
                layer.open({type: 2,
                    title: '编辑员工',
                    content: '${ctx}/traderEmploye/addEmployee?id='+id,
                    area: ['100%', '100%']
                });
            }else if(obj.event === 'dateRight'){
                var id = data.id;
                layer.open({
                    type: 2
                    , title: '数据权限'
                    , area: ['40%', '30%']
                    , content: '${ctx}/member/rightsForm?type=1&id='+id
                })
            }else if (obj.event === 'delete') {//删除工程师
                var id = data.id;
                var indexla = layer.confirm('您确定要删除员工吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/traderEmploye/delEmployee",
                        data: {
                            id: id
                        },
                        success: function (result) {
                            if (result.code == '200') {
                                layer.msg('删除成功！', {icon: 1, time: 1000}, function () {
                                    window.location.reload();
                                });
                            } else if (result.code == '501') {
                                layer.msg('该工程师有未完成工单，无法删除！', {icon: 2});
                            } else {
                                layer.msg('删除失败！', {icon: 2});
                            }
                        },
                        error: {}
                    })
                }, function () {
                    layer.close(indexla);
                });
            }
        });


        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                reload();
            }
        };
    });

    function reload(){
        table.reload('test', {
            where: {
                name: $('#name').val().trim(),
                mobile:$("#mobile").val().trim()
            }
        });
    }


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