<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>员工管理</title>
    <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">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" type="text/css" href="../../layuiadmin/style/formSelects-v4.css"/>
    <style type="text/css">
        .seach_items {
            display: inline-block;
            margin-right: 5px;
            margin-top: 5px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <div style="float:left; margin-right: 5px; margin-top: 5px;">
                            <button class="layui-btn" id="btn_add" data-permission="account.add_user">
                                <i class="layui-icon layui-icon-add-circle"></i>添加
                            </button>
                        </div>

                        <div style="float:right;">
                            <form class="layui-form" lay-filter="query-form-element">
                                <div class="seach_items">
                                    <input type="text" name="name" autocomplete="off" class="layui-input"
                                           placeholder="姓名"/>
                                </div>
                                <div class="seach_items">
                                    <input type="text" name="tel" autocomplete="off" class="layui-input"
                                           placeholder="电话"/>
                                </div>
                                <div class="seach_items">
                                    <input type="text" name="username" autocomplete="off" class="layui-input"
                                           placeholder="账号"/>
                                </div>
                                <div class="seach_items">
                                    <button class="layui-btn" lay-submit lay-filter="query-form-element"><i
                                            class="layui-icon layui-icon-search"></i>查询
                                    </button>
                                </div>
                            </form>
                        </div>
                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>

                    <script type="text/html" id="datagrid-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="join"
                               data-permission="account.check_user">入职</a>
                        </div>
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="edit"
                               data-permission="account.add_user">修改</a>
                        </div>
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete"
                               data-permission="account.delete_user">删除</a>
                        </div>
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs layui-btn-warm"
                               data-permission="account.manager_store"
                               lay-event="manage_range">管理门店</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../../layuiadmin/layui/layui.js?t=1"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
        , formSelects: 'formSelects-v4'
    }).use(['index', 'table', 'form', 'formSelects'], function () {
        var $ = layui.$
            , table = layui.table
            , form = layui.form;
        table.render({
            elem: '#datagrid'
            , url: '/account/employee/'
            , cols: [[
                {field: 'name', title: '姓名', width: 120}
                , {field: 'gender_text', title: '性别', width: 80}
                , {field: 'tel', title: '电话', width: 120}
                , {field: 'username', title: '账号', width: 120}
                , {field: 'agent_text', title: '代理商', width: 150}
                , {field: 'store_text', title: '门店', width: 150}
                , {field: 'enable_text', title: '是否在用', width: 100}
                , {field: 'groups', title: '权限组', width: 200}
                , {field: 'manager_barnchs', title: '管理门店', width: 200}
                , {field: 'status_text', title: '状态', width: 80}
                , {field: 'check_user_text', title: '入职审核人', width: 120}
                , {field: 'date_joined', title: '入职时间', width: 180}
                , {width: 250, align: 'center', fixed: 'right', toolbar: '#datagrid-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
        });
        var _params;
        form.on('submit(query-form-element)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            _params = data.field;
            table.reload('datagrid', {
                where: data.field
                , page: {curr: 1}
            });
            layer.closeAll();
            return false;
        });
        //监听工具条
        table.on('tool(datagrid-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                table.editdata = data;
                layer.open({
                    type: 2,
                    title: '修改',
                    shadeClose: false,
                    area: ['50%', '80%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'edit.html?id=' + data.id
                });
            } else if (obj.event === 'delete') {
                if (data.status > 1) {
                    layer.msg('当前状态禁止删除！')
                    return false
                }
                layer.confirm('确定要删除吗？', function (index) {
                    layer.close(index);
                    layui.admin.req({
                        notice: true
                        , url: '/account/employee/' + data.id + '/'
                        , type: 'delete'
                        , done: function (res) {
                            table.reload('datagrid', {});
                        }
                    });
                });
            }
            else if (obj.event === 'join') {
                if (data.status > 1) {
                    layer.msg('该员工已入职！')
                    return false
                }
                layer.confirm('确定要入职该员工吗？', function (index) {
                    layer.close(index);
                    layui.admin.req({
                        url: '/account/employee/' + data.id + '/join/'
                        , type: 'post'
                        , done: function (res) {
                            table.reload('datagrid', {});
                        }
                    });
                });
            }
            else if (obj.event === 'manage_range') {
                layer.open({
                    type: 2,
                    title: '管理门店',
                    shadeClose: true,
                    area: ['650px', '80%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'manage_range.html?id=' + data.id
                });
            }
        });

        $('#btn_add').on('click', function () {
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: false,
                area: ['550px', '80%'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('datagrid', {});
                    };
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'edit.html'
            });
        });
    });
</script>
</body>
</html>

