<!DOCTYPE html>
<html lang="en">
<head>
<%include("/common/_head.html"){}%>
    <title>文章管理 -飞趣</title>
<style>
</style>
</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="layui-container fly-marginTop topToFix c-user-main">
    <%include("/common/_user_menu.html",{user:user}){}%>
        <div class="c-panel fly-panel-user detail-box">
            <div class="layui-row layui-col-space20">
                <div class="layui-col-md12">
                    <table class="layui-hide" id="articleManage" lay-filter="article"></table>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="examine">审核</a>
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="htmlUnescape">反转义</a>
                        <a class="layui-btn layui-btn-xs" lay-event="recommend">推荐</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                    </script>
                </div>
            </div>
        </div>
</div>
<%include("/common/_footor.html"){}%>
</body>
<%include("/common/_scripts.html",{user:user}){}%>
<script>
    layui.use(['table','fly'], function() {
        var table=layui.table
            ,fly=layui.fly;
        table.render({
            elem: '#articleManage'
            ,url:'/article/manage/list'
            ,toolbar: true
            ,title: '文章数据表'
            ,totalRow: true
            ,cols: [[
                {field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'articleTitle', title:'标题', width:200, fixed: 'left', unresize: true, sort: true},
                {field:'userId', title:'用户id', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'createTime', title:'创建时间', width:160, fixed: 'left', unresize: false, sort: true},
                {field:'delFlag', title:'标志', width:80, fixed: 'left', unresize: true, sort: true},
                {field:'isRecommend', title:'推荐', width:80, fixed: 'left', unresize: false, sort: true},
                {fixed: 'right', width:200, align:'center', toolbar: '#barDemo',unresize: false}
            ]]
            ,page: true
            ,response: {
                statusCode: '0000', //重新规定成功的状态码为 200，table 组件默认为 0
                msgName: 'message' //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,id: 'articleReload'
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
        });
        //监听工具条
        table.on('tool(article)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                location.href = '/article/'+data.id;
            } else if(obj.event === 'examine'){
                fly.json('/article/manage/examine?articleId='+data.id,{},function (res) {
                    layer.msg('审核通过！');
                    table.reload('articleReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                });
            } else if(obj.event === 'del'){
                layer.confirm('真的删除这篇文章么', function(index){
                    fly.json('/article/delete?articleId='+data.id,{},function (res) {
                        layer.msg('删除成功！');
                        table.reload('articleReload', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'recommend'){
                layer.confirm('真的推荐这篇文章么', function(index){
                    fly.json('/article/manage/recommend/'+data.id,function (res) {
                        layer.msg('推荐成功！');
                        table.reload('articleReload', {
                            page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                    });
                    layer.close(index);
                });
            }else if(obj.event === 'htmlUnescape'){
                layer.confirm('真的反转义这篇文章的内容么', function(index){
                    fly.json('/article/manage/htmlUnescape/'+data.id,function (res) {
                        layer.msg('转义成功！');
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

</html>