<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <title>作家管理系统-小说精品屋</title>
        <link rel="stylesheet" href="/css/base.css?v=1"/>
        <link rel="stylesheet" href="/css/user.css"/>
        <style type="text/css">
            .redBtn {
                padding: 5px;
                border-radius: 20px;
                border: 1px solid #3eaf7c;
                background: #3eaf7c;
                color: #fff;
            }

            a.redBtn:hover {

                color: #fff;
            }
        </style>
    </head>
</head>
<body class="">

<div class="header">
    <div class="mainNav" id="mainNav">
        <div class="box_center cf"
             style="text-align: center;height: 44px;line-height: 48px;color: #fff;font-size: 16px;">

            小说精品屋作家管理

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

<div class="main box_center cf">
    <div class="userBox cf">
        <div class="my_l">

            <ul class="log_list">
                <li><a class="link_4 on" href="/author/index.html">作品管理</a></li>
                <li><a class="link_2 " href="/author/author_income_detail.html">稿费收入</a></li>
            </ul>

        </div>
        <div class="my_r">
            <div id="noContentDiv">
                <div class="tc" style="margin-top: 200px"><a href="javascript:addContent()" class="btn_red">新建章节</a>
                </div>

            </div>
            <div class="my_bookshelf" id="hasContentDiv" style="display: none">
                <div class="title cf">
                    <h2 class="fl">章节列表</h2>
                    <div class="fr"><a href="javascript:addContent()" class="btn_red">新建章节</a></div>
                </div>

                <div id="divData" class="updateTable">
                    <table cellpadding="0" cellspacing="0">
                        <thead>
                        <tr>
                            <!-- <th class="style">
                                 序号
                             </th>-->
                            <th class="name">
                                章节名
                            </th>
                            <th class="goread">
                                更新时间
                            </th>
                            <th class="goread">
                                是否收费
                            </th>
                            <th class="goread">
                                操作
                            </th>
                        </tr>
                        </thead>
                        <tbody id="bookList">


                        </tbody>
                    </table>
                    <div class="pageBox cf" id="shellPage">
                    </div>
                </div>
                <!--<div id="divData" class="updateTable">
                    <table cellpadding="0" cellspacing="0">
                        <thead>
                        <tr>

                            <th class="name">
                                爬虫源(已开启的爬虫源)
                            </th>
                            <th class="chapter">
                                成功爬取数量(websocket实现)
                            </th>
                            <th class="time">
                            目标爬取数量
                            </th>
                            <th class="goread">
                                状态(正在运行,已停止)(一次只能运行一个爬虫源)
                            </th>
                            <th class="goread">
                                操作(启动,停止)
                            </th>
                        </tr>
                        </thead>
                        <tbody id="bookShelfList">



                        </tbody>
                    </table>
                    <div class="pageBox cf" id="shellPage">
                    </div>
                </div>-->
            </div>
        </div>
    </div>
</div>


</body>
<script src="/javascript/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="/layui/layui.all.js" type="text/javascript"></script>
<script src="/javascript/header.js" type="text/javascript"></script>
<script src="/javascript/user.js" type="text/javascript"></script>
<script src="/javascript/date.js" type="text/javascript"></script>
<script src="/javascript/common.js" type="text/javascript"></script>

<script language="javascript" type="text/javascript">

    var bookId = getSearchString("bookId");

    var indexCount = 0;

    search(1, 5);

    function search(curr, limit) {

        $.ajax({
            type: "get",
            url: "/book/queryIndexList",
            data: {'bookId': bookId, 'curr': curr, 'limit': limit, 'orderBy': 'index_num desc'},
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    var bookList = data.data.list;
                    if (bookList.length > 0) {
                        indexCount = bookList.length;
                        $("#hasContentDiv").css("display", "block");
                        $("#noContentDiv").css("display", "none");
                        var bookListHtml = "";
                        for (var i = 0; i < bookList.length; i++) {
                            var book = bookList[i];
                            bookListHtml += (" <tr class=\"book_list\" vals=\"291\">\n" +
                                /*  "                            <td class=\"style bookclass\">\n" +
                                  "                                ["+(i+1)+"]\n" +
                                  "                            </td>\n" +*/

                                "                            <td id='name" + book.id + "' class=\"name\">\n" +
                                "                                " + book.indexName + "</td>\n" +


                                "                            <td class=\"goread\">\n" +
                                "                                " + new Date(Date.parse(book.updateTime)).Format("yyyy-MM-dd hh:mm") + "<br/>更新\n" +
                                "                            </td>\n" +

                                "                            <td class=\"goread\" valsc=\"291|2037554|1\">"
                                + (book.isVip == 1 ? '收费' : '免费') + "</td>\n" +

                                " <td class=\"goread\" id='opt" + book.id + "'>" +
                                "<a  class='redBtn' href='javascript:updateIndex(\"" + book.id + "\"," + book.isVip + ")'>修改  </a><br/>" +
                                "<a  href='javascript:deleteIndex(\"" + book.id + "\")'>删除  </a><br/>" +
                                "</td>                     </tr>");
                        }
                        $("#bookList").html(bookListHtml);

                        layui.use('laypage', function () {
                            var laypage = layui.laypage;

                            //执行一个laypage实例
                            laypage.render({
                                elem: 'shellPage' //注意,这里的 test1 是 ID,不用加 # 号
                                , count: data.data.total //数据总数,从服务端得到,
                                , curr: data.data.pageNum
                                , limit: data.data.pageSize
                                , jump: function (obj, first) {


                                    //obj包含了当前分页的所有参数,比如:
                                    console.log(obj.curr); //得到当前页,以便向服务端请求对应页的数据。
                                    console.log(obj.limit); //得到每页显示的条数


                                    //首次不执行
                                    if (!first) {
                                        search(obj.curr, obj.limit);
                                    } else {

                                    }
                                }
                            });
                        });

                    }


                } else if (data.code == 1001) {
                    //未登录
                    location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                } else {
                    layer.alert(data.msg);
                }

            },
            error: function () {
                layer.alert('网络异常');
            }
        })

    }

    function addContent() {
        location.href = "/author/content_add.html?indexCount=" + indexCount + "&bookId=" + bookId;

    }

    function updateIndex(indexId, isVip) {

        var indexName = $.trim($("#name" + indexId).text());


        location.href = "/author/content_update.html?bookId=" + bookId
            + "&indexId=" + indexId
            + "&indexName=" + encodeURI(encodeURI(indexName))
            + "&isVip=" + isVip;


        /*
                var indexName = $("#name"+indexId).text();

                var htmlStr = "<input type=\"text\" value=\""+$.trim(indexName)+"\">";

                $("#name"+indexId).html(htmlStr);
                $("#name"+indexId).find("input").focus();
                $("#name"+indexId).find("input").select();

                $("#name"+indexId).find("input").keyup(function(event){
                    if(event.keyCode ==13){
                        $(this).blur();
                    }
                });

                $("#name"+indexId).find("input").blur(function () {
                    var indexName = $(this).val();
                    $.ajax({
                        type: "POST",
                        url: "/author/updateIndexName",
                        data: {'indexId':indexId,'indexName':indexName},
                        dataType: "json",
                        success: function (data) {
                            if (data.code == 200) {

                                $("#name"+indexId).html(indexName);


                            } else if (data.code == 1001) {
                                //未登录
                                location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                            }else {
                                layer.alert(data.msg);
                            }

                        },
                        error: function () {
                            layer.alert('网络异常');
                        }
                    })

                });*/


    }


    function deleteIndex(indexId) {

        layer.confirm('确认要删除吗?删除后数据无法找回!', {
            btn: ['确定', '取消']//按钮
        }, function (index) {

            layer.close(index);
            $.ajax({
                type: "delete",
                url: "/author/deleteIndex/"+indexId,
                data: {},
                dataType: "json",
                success: function (data) {
                    if (data.code == 200) {

                        location.reload();


                    } else if (data.code == 1001) {
                        //未登录
                        location.href = '/user/login.html?originUrl=' + decodeURIComponent(location.href);

                    } else {
                        layer.alert(data.msg);
                    }

                },
                error: function () {
                    layer.alert('网络异常');
                }
            })
        });


    }
</script>
</html>