<!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">
    <style type="text/css">
        .seach_items {
            float: right;
            margin-left: 10px;
        }
    </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-md5">
                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <div class="layui-col-xs2">
                            <button class="layui-btn" id="school_add" data-permission="option.add_school"><i
                                    class="layui-icon layui-icon-add-circle"></i>添加学校
                            </button>
                        </div>
                        <form class="layui-form" lay-filter="query-form-element1">
                            <div class="seach_items">
                                <button class="layui-btn" lay-submit lay-filter="query-form-element1"><i
                                        class="layui-icon layui-icon-search"></i>查询
                                </button>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="name" autocomplete="off" class="layui-input"
                                       placeholder="学校名称"/>
                            </div>
                        </form>
                        <div style="clear: both;"></div>
                    </div>
                    <table class="layui-hide" id="school_datagrid" lay-filter="school-operate"></table>

                    <script type="text/html" id="school-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="school_edit" data-permission="option.add_school"
                            >修改</a>
                        </div>
                    </script>
                </div>

                <div class="layui-col-md7">
                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <div class="layui-col-xs2">
                            <button class="layui-btn" id="grade_add" data-permission="option.add_school"><i
                                    class="layui-icon layui-icon-add-circle"></i>添加年级
                            </button>
                        </div>

                        <form class="layui-form" lay-filter="query-form-element2">
                            <div class="seach_items">
                                <button class="layui-btn" lay-submit lay-filter="query-form-element2"><i
                                        class="layui-icon layui-icon-search"></i>查询
                                </button>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="school_name" autocomplete="off" class="layui-input"
                                       placeholder="学校名称"/>
                            </div>
                            <div class="seach_items">
                                <input type="text" name="name" autocomplete="off" class="layui-input"
                                       placeholder="年级名称"/>
                            </div>
                        </form>
                        <div style="clear: both;"></div>
                    </div>

                    <table class="layui-hide" id="grade_datagrid" lay-filter="grade-operate"></table>

                    <script type="text/html" id="grade-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" lay-event="grade_edit" data-permission="option.add_school"
                            >修改</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' //主入口模块
    }).use(['index', 'table', 'form'], function () {
        var $ = layui.$;
        var table = layui.table
            , form = layui.form
            , admin = layui.admin;
        //品牌
        table.render({
            elem: '#school_datagrid'
            , url: '/option/school/'
            , cols: [[
                {field: 'name', title: '名称', width: 200}
                , {field: 'enable_text', title: '在用', width: 80}
                , {field: 'notes', title: '备注', minWwidth: 80}
                , {width: 110, align: 'center', fixed: 'right', toolbar: '#school-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
            , done: function () {
                layui.index.removeNoPermButtons()
            }
        });
        //车系
        table.render({
            elem: '#grade_datagrid'
            , url: '/option/grade/'
            , cols: [[
                {field: 'school_text', title: '学校名称', width: 200}
                , {field: 'name', title: '年级名称', width: 200}
                , {field: 'count', title: '班级数量', width: 100}
                , {field: 'notes', title: '备注'}
                , {width: 110, align: 'center', fixed: 'right', toolbar: '#grade-operate-bar'}
            ]]
            , page: true
            , height: 'full-108'
            , done: function () {
                layui.index.removeNoPermButtons()
            }
        });

        //监听品牌工具条
        table.on('tool(school-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'school_edit') {
                table.editdata = data;
                layer.open({
                    type: 2,
                    title: '修改',
                    shadeClose: false,
                    area: ['40%', '70%'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitChild = function (data) {
                            layer.close(index);
                            table.reload('school_datagrid', {});
                            table.reload('grade_datagrid', {});
                        };
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'school_edit.html?id=' + data.id
                });
            }
        });
        //监听车系工具条
        table.on('tool(grade-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'grade_edit') {
                table.editdata = data;
                layer.open({
                    type: 2,
                    title: '修改',
                    area: ['500px', '500px'],
                    btn: ['保存', '取消'],
                    yes: function (index, dom) {
                        layui.onSubmitChild = function (data) {
                            layer.close(index);
                            table.reload('school_datagrid', {});
                            table.reload('grade_datagrid', {});
                        };
                        layui.submitChild();
                    },
                    btn2: function (index, layero) {
                        layer.close(index);//关闭当前按钮
                    },
                    content: 'grade_edit.html?id=' + data.id
                });
            }
        });
        form.on('submit(query-form-element1)', function (data) {
            table.reload('school_datagrid', {
                where: data.field
                , page: {curr: 1}
            });
            layer.closeAll();
            return false
        });
        form.on('submit(query-form-element2)', function (data) {
            table.reload('grade_datagrid', {
                where: data.field
                , page: {curr: 1}
            });
            layer.closeAll();
            return false
        });
        $('#school_add').on('click', function () {
            layer.open({
                type: 2,
                title: '添加',
                area: ['40%', '70%'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('school_datagrid', {});
                        table.reload('grade_datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'school_edit.html'
            });
        });
        $('#grade_add').on('click', function () {
            layer.open({
                type: 2,
                title: '添加',
                area: ['500px', '500px'],
                btn: ['保存', '取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('school_datagrid', {});
                        table.reload('grade_datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                },
                content: 'grade_edit.html'
            });
        });
    });

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