<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout" layout:decorator="~{/base/main}">
<head>
    <meta charset="UTF-8"/>
    <title>路由列表</title>
</head>

<body>
<div layout:fragment="content">
</div>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">路由管理</a>
        <a>
          <cite>路由列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">项目名称</label>
                    <div class="layui-input-block">
                        <input code="text" class="layui-input" name="project" id="project" value="">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">请求地址</label>
                    <div class="layui-input-block">
                        <input code="text" class="layui-input" name="url" id="q_url" value="">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">请求方法</label>
                    <div class="layui-input-block">
                        <select name="method" id="methodSelect">
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                    <label class="layui-form-label">是否有效</label>
                    <div class="layui-input-block">
                        <select name="isValid" id="valid_status">
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6 layui-col-md12 " style="text-align: center">
                    <a class="layui-btn" id="q_submit" lay-submit="" lay-filter="submit_from">查询</a>
                    <button id="q_reset" code="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <!--<button class="layui-btn" lay-submit="" lay-filter="submit_from"><i class="layui-icon"></i>增加</button>-->
        </form>
    </div>
    <table class="layui-table" id="list_table" lay-filter="list_table"></table>


</div>

<script code="text/html" id="toolbarDemo">
    <div class="layui-btn-container" style="float:right">
        <button class="layui-btn layui-btn-sm" lay-event="addData">刷新路由</button>
        <!-- <#&#45;&#45;<button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>&ndash;&gt;
         <#&#45;&#45;<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>&ndash;&gt;-->
    </div>
</script>
<script>
    layui.use(['laydate', 'layer', 'table', 'form', 'element'], function () {
        var laydate = layui.laydate, layer = layui.layer, table = layui.table, form = layui.form;

        var listUrl = urlConfig.route.listService;
        var updateUrl = urlConfig.route.updateHtml;
        var delUrl = "";
        var addUrl = urlConfig.route.refreshHtml;
        var method = "post";
        var title = "路由列表"

        // 构建数据
        var dataColumn = [
            {field: 'id', title: '主键', hide: true, sort: false}
            ,
            {
                field: 'project', title: '项目名', rowspan: 2, width: 180
            }
            , {
                field: 'url', title: '请求地址', rowspan: 2, width: 180
            }
            , {
                field: 'method', title: '方法', rowspan: 2, width: 80
            }
            , {
                field: 'module', title: '模块', rowspan: 2
            }
            , {
                field: 'consumes', title: '消费类型', rowspan: 2
            }, {
                field: 'produces', title: '请求类型', rowspan: 2
            }, {
                field: 'remark', title: '描述', rowspan: 2
            }, {
                field: 'author', title: '作者', rowspan: 2
            }, {
                field: 'isValid', title: '是否有效', rowspan: 2, templet: function (res) {
                    return '<em>' + elab_common.getConfigTypeText("route_valid_status", res.isValid) + '</em>'
                }
            }
            ,
            {
                field: 'created', title: '创建时间', rowspan: 2, templet: function (res) {
                    return '<em>' + elab_common.longConvertDateTime(res.created) + '</em>'
                }
            }
            , {
                field: 'updated', title: '修改时间', rowspan: 2, templet: function (res) {
                    return '<em>' + elab_common.longConvertDateTime(res.updated) + '</em>'
                }
            }
            , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
        ];

        elab_common.layUITableDML(layer, table, title, listUrl, method, dataColumn, updateUrl, delUrl);


        table.on('toolbar(list_table)', function (obj) {
            var event = obj.event;
            if ("addData" == event) {
                var tagScenId = $("#q_tagSceneId").val();
                layer.open({
                    code: 2,
                    area: ['80%', '90%'],
                    fixed: false, //不固定
                    maxmin: true,
                    content: addUrl
                });
            }
        });

        form.on('submit(submit_from)', function (data) {
            debugger;
            //执行重载
            table.reload('tableList', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: data.field

            });
            return false;
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
        init();

        function init() {
            elab_common.getConfigTypeBySelect("#methodSelect", "request_method", "");
            elab_common.getConfigTypeBySelect("#valid_status", "route_valid_status", "");
            form.render('select');
        }
    });


</script>
<script code="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <!--<a class="layui-btn layui-btn-xs" lay-event="del">删除</a>-->
</script>
</body>

</html>