<!DOCTYPE html>
<html lang="en">
<head>
    <%include("/common/_head.html"){}%>
    <title> API 接口文档 -飞趣</title>
    <link rel="stylesheet" href="${ctxPath}/css/api-doc.css?v=${VERSION}">
</head>
<body>
<%
var user = c.currentUser(request, servlet.response);
var isLogin = false;
if(user != null){
isLogin=true;
}
include("/common/_headwithlogin.html",{user:user,isLogin:isLogin}){}
%>
<div class="api-doc-nav api-doc-index layui-container">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md3">
            <%include("/common/_api_doc_menu.html",{user:user}){}%>
        </div>
        <div class="layui-col-md9">
            <div class="c-panel">
                <div class="c-panel-body">
                    <div>
                        <form class="layui-form layui-form-pane" action="">
                        <div class="layui-form-item">
                            <label class="layui-form-label">项目</label>
                            <div class="layui-input-inline" style="width: 200px;">
                                <select name="projectId" lay-verify="required">
                                    <%for(var p in projects){%>
                                    <option value="${p.key}">${p.value}</option>
                                    <%}%>
                                </select>
                            </div>
                        </div>
                        </form>
                    </div>

                    <div class="searchTable">
                        <button class="layui-btn" data-type="reload">搜索</button>
                    </div>
                    <table class="layui-hide" id="apiDocInterfaceManage" lay-filter="apiDocInterface"></table>
                    <script type="text/html" id="bar">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="debug">调试</a>
                    </script>
                    <script type="text/html" id="headToolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm" lay-event="add">新增接口</button>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<%include("/common/_footor.html"){}%>
</body>
<%include("/common/_scripts.html",{user:user}){}%>
<script>
    var condition = ${condition!''};
    layui.use(['fly','table'], function(){
        var fly=layui.fly,table=layui.table,device=layui.device,form=layui.form,$project = $('select[name="projectId"]');
        if(condition && condition.projectId){
            $project.val(condition.projectId);
        }
        form.render('select')
        var active = {
            reload: function(){
                table.reload('apiDocInterfaceReload', {
                    page: {
                        curr: 1
                    }
                    ,where: {
                        projectId:$project.val()
                    }
                });
            }
        }
        $('.searchTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        table.render({
            elem: '#apiDocInterfaceManage'
            ,url:'/apiDocInterface/list'
            ,where: {projectId:$project.val()}
            ,toolbar: '#headToolbar'
            ,title: '接口数据表'
            ,totalRow: true
            ,cols: [[
                {field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'interfacename', title:'接口名', width:150, fixed: 'left', unresize: true, sort: true},
                {field:'projectid', title:'项目ID', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'fullurl', title:'完整url', width:100, fixed: 'left', unresize: true, sort: true},
                {field:'version', title:'版本', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'sequence', title:'排序', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'createtime', title:'创建时间', width:160, fixed: 'left', unresize: false, sort: true},
                {fixed: 'right', width:200, align:'center', toolbar: '#bar'}
            ]]
            ,page: true
            ,response: {
                statusCode: '0000',
                msgName: 'message'
            }
            ,id: 'apiDocInterfaceReload'
            ,parseData: function(res){
                return {
                    "code": res.code,
                    "msg": res.message,
                    "count": res.data.total,
                    "data": res.data.list
                };
            }
        });
        table.on('toolbar(apiDocInterface)', function(obj){
            switch(obj.event){
                case 'add':
                    location.href = '/apiDocInterface/apiDocInterfaceAdd/?projectId='+$project.val()
                    break;
            };
        });
        table.on('tool(apiDocInterface)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除这个接口么', function(index){
                    fly.json('/apiDocInterface/delete?id='+data.id,{},function (res) {
                        layer.msg('删除成功！');
                        table.reload('apiDocInterfaceReload', {
                            page: {
                                curr: 1
                            }
                        });
                    });
                    layer.close(index);
                });
            }else if(obj.event === 'edit'){
                location.href = '/apiDocInterface/edit/'+data.id;
            }else if(obj.event === 'debug'){
                location.href = '/apiDocInterface/debug/'+data.id;
            }
        });
    });
</script>
</html>