<?php
use yii\helpers\Url;
?>
<div class="content">

    <!-- banner -->
    <div class="banner analysis-banner">
        <h2 class="main-title container"><?= !empty($data['article']['category_name']) ?  $data['article']['category_name'] : '' ?></h2>
    </div>
    <div class="container clearfix">
        <div class="analysis-aside">
            <div class="analysis-nav">
                <h3 class="title">
                    <span>最新活动</span>
                </h3>
                <ul id="new_article_list">
                </ul>
            </div>
           
        </div>

        <div class="analysis-main">
            <ol class="breadcrumb container">
                <li>
                    <a href="/">和隆首页</a>
                </li>
                <li>
                    <a href="<?php if ($data['article']['article_category_id'] == 1) { echo Url::to(['/about/public']); ?>
                    <?php } else if($data['article']['article_category_id'] == 3) { echo Url::to(['/activity/index']); ?>
                    <?php } else { ?><?= Url::to(['/article/list?id='.$data['article']['article_category_id']]) ?><?php } ?>">
                        <?= !empty($data['article']['category_name']) ?  $data['article']['category_name'] : '' ?></a>
                </li>
                <li class="active">正文</li>
            </ol>
            <div class="article" id="article_detail">

            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footer_script'); ?>
<script>
    // 获取链接参数
    function GeturlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
    $(function () {
        getNewArticleList()
        var id = GeturlParam('id');
        $.getJSON('/article/article-detail?id=' + id, function (data) {
            if (data.code !== 1) {
                layer.msg('文章获取失败')
                return
            }
            data = data.data
            var article = data.article
            if (article.title) {
                document.title = article.title
            }
            var articleHtml = '<h2 class="title">' + article.title + '</h2><div class="date">' + article.create_date + '</div><div class="article-main">' + article.content + '</div>';
            var nextArticle = data.nextArticle
            var nextArticleHtml = nextArticle ? '<a href="/article/detail?id=' + nextArticle.id +'" target="_blank">下一篇:' + nextArticle.title + '</a>' : '';

            var prevArticle = data.previousArticle
            var prevArticleHtml = prevArticle ? '<a href="/article/detail?id=' + prevArticle.id + '"  target="_blank">上一篇:' + prevArticle.title + '</a>' : ''
            articleHtml += ('<div class="article-bottom">' + (prevArticleHtml + nextArticleHtml) + '</div>');
            article_detail.innerHTML = articleHtml
        })
    })
</script>
<?php $this->endBlock(); ?>
