{layout name="public/layout_main"}

<section class="wrapper">
    <h3><i class="fa fa-angle-right"></i> 美行攻略</h3>
    <!-- 分割线 -->
    <hr>

    <div class="row margin-bottom">
        <div class="col-md-12">
            <form class="form-inline pull-left" method="GET" action="<?php echo url('@admin/Guide/index')?>">
                 <div class="form-group margin-right">
                    <input class="form-control" type="text" name="title" id="title" value="<?php echo input('title');?>" placeholder="攻略标题"/>
                </div>
                <button type="submit" class="btn btn-primary">搜索</button>
            </form>
            <div class="pull-right">
                <a href='<?php echo url("@admin/Guide/create")?>' type="button" class="btn btn-success" style="margin-left:30px;">
                    发布攻略
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-md-12">
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>攻略标题</th>
                            <th>封面</th>
                            <th>发布时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($articles as $k => $article):?>
                            <tr id="tr_<?php echo $article->id;?>">
                                <td><?php echo $article->id;?></td>
                                <td style="max-width:450px;">
                                    {if condition="$article.type == 1"}
                                    <a href="<?php echo url('@mob/Guide/read', 'id='.$article->id);?>/" target='_blank'>
                                        <?php echo $article->title;?>
                                    </a>
                                    {else/}
                                        <a href="{$article->content}" target='_blank'>
                                            <?php echo $article->title;?>
                                        </a>
                                    {/if}
                                </td>
                                <td><img style="width: 90px" src="{$article->poster}" alt=""></td>
                                <td><?php echo $article->created_at;?></td>
                                <td style="min-width:100px;">
                                    <a href="<?php echo url('@admin/Guide/update', 'id='.$article->id);?>" type="button" class="btn btn-primary btn-xs" data-toggle="tooltip" data-placement="top" data-original-title="编辑">
                                        <i class="fa fa-pencil"></i>
                                    </a>
                                    <button oid="<?php echo $article->id;?>" type="button" class="btn btn-danger btn-xs btn-delete" data-toggle="tooltip" data-placement="top" data-original-title="删除">
                                        <i class="fa fa-trash-o"></i>
                                    </button>
                                </td>
                            </tr>
                        <?php endforeach;?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            {$articles->render()}
        </div>
    </div>

</section>

<script type="text/javascript">
    // 文档加载完毕之后，会进入该方法
    $(function(){
        $(".btn-delete").click(function(){
            var _this = $(this);
            var url = "delete";
            var oid = _this.attr('oid');
            showDialog("提示", "确定删除这篇文章吗？", function () {
                // ajax post 方法
                $.post(url, {id:oid}, function (res) {
                    var res = JSON.parse(res);
                    if (res.error == 1) {
                        // javascript 的默认弹出提示方法
                        alert(res.msg);
                    } else {
                        _this.remove();
                        $("#tr_"+oid).fadeOut();
                    }
                });
            });
        });
    });
</script>
