<?php
  require __DIR__.'/head.html';
  require __DIR__.'/header.html';
  $File_Ming = 'apilist';
  require __DIR__.'/nav.html';
  ?>
<!-- 主体 -->
<main class="app-content">
    <div class="app-title">
        <ul class="app-breadcrumb breadcrumb side">
            <li class="breadcrumb-item"><i class="fa fa-home fa-lg"></i></li>
            <li class="breadcrumb-item">接口列表</li>
        </ul>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="tile">
                <div class="tile-body">
                    <table class="table table-hover table-bordered" id="sampleTable">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>标题</th>
                                <th>简介</th>
                                <th>别名</th>
                                <th>地址</th>
                                <th>数据绑定</th>
                                <th>上架状态</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody class="table-space">
                            <?php if(!empty($data)):
                            foreach($data as $k=>$v):?>
                            <tr>
                                <td><?php echo $k+1;?></td>
                                <td><?php echo $v['l_title'];?></td>
                                <td><?php echo $v['l_desc'];?></td>
                                <td><?php echo $v['l_alias'];?></td>
                                <td><?php echo $v['l_address'];?></td>
                                <td><?php if($v['l_data']==1){echo "真";}else{echo "假";}?>
                                </td>
                                <td><?php if($v['l_show']>0){echo "已上架";}else{echo "未上架";}?></td>
                                <td><?php echo $v['l_found_time'];?></td>
                                <td class="api-list-cz">
                                    <a class="btn btn-primary btn-sm" onclick="editRow(this)"
                                        title="<?php echo $v['l_id'];?>">编辑</a>
                                    <a class="btn btn-primary btn-sm" onclick="delRow(this)"
                                        title="<?php echo $v['l_id'];?>">删除</a>
                                </td>
                            </tr>
                            <?php endforeach;
                            endif;?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <?php  require __DIR__.'/fooer.html'; ?>

    <script type="text/javascript">
        function editRow(_this) {
            layer.open({
                type: 2,
                title: '接口编辑',
                shadeClose: false,
                shade: true,
                maxmin: false, //开启最大化最小化按钮
                area: ['80%', '80%'],
                content: ['/<?php echo ADMIN_PATH;?>/editapi/' + _this.title]
            });
        }

        //删除
        function delRow(_this) {
            var td = _this.parentNode;
            var tr = td.parentNode;
            var tbody = tr.parentNode;
            //询问框
            layer.confirm('确定删除接口？', {
                title: "提示",
                btn: ['删除', '取消 '] //按钮
            }, function () {
                fd = new FormData();
                fd.append("id", _this.title);
                $.ajax({
                    url: '/admin/delapi',
                    type: "POST",
                    timeout: "3000",
                    dataType: "json",
                    contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                    data: fd,
                    contentType: false,
                    processData: false,
                    success: function (data) {
                        if (data.code == "200") {
                            layer.msg(data.msg);
                            tbody.removeChild(tr);
                        } else {
                            layer.msg(data.msg);
                        }
                    },
                    error: function (XMLResponse) {
                        layer.msg(XMLResponse.error);
                    }
                });
            });
        }

    </script>
    </body>

    </html>