<!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"/>
    </head>
</head>
<body class="">

<div th:replace="crawl/header :: header">
</div>

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

            <ul class="log_list">
                <li><a class="link_1" href="/">爬虫源管理</a></li>
                <li><a class="link_1 on" href="/crawl/crawlSingleTask_list.html">单本采集管理</a></li>
                <li><a class="link_1" href="/crawl/crawlSource_test.html" target="_blank">规则测试</a></li>
                <!--<li><a class="link_1 " href="/user/userinfo.html">批量小说爬取</a></li>
                <li><a class="link_4 " href="/user/favorites.html">单本小说爬取</a></li>-->
            </ul>

        </div>
        <div class="my_r">
            <div class="my_bookshelf">

                <div class="userBox cf">
                    <form method="post" action="./register.html" id="form2">

                        <div class="user_l">
                            <div></div>
                            <h3>采集信息填写（示例均为笔趣阁：http://www.mcmssc.com）</h3>
                            <ul class="log_list">
                                <li><span id="LabErr"></span></li>
                                <input type="hidden" id="sourceName" class="s_input icon_name">
                                <b>采集源:</b>
                                <li><select id="sourceId" class="s_input icon_key">
                                </select></li>
                                <b>采集分类:</b>
                                <li><select id="catId" class="s_input icon_key">
                                    <option value="1">玄幻奇幻</option>
                                    <option value="2">武侠仙侠</option>
                                    <option value="3">都市言情</option>
                                    <option value="4">历史军事</option>
                                    <option value="5">科幻灵异</option>
                                    <option value="6">网游竞技</option>
                                    <option value="7">女生频道</option>
                                </select>
                                </li>
                                示例：<b>73_73911</b>
                                <li><input type="text" id="sourceBookId" class="s_input icon_key"
                                           placeholder="采集的源站小说ID"/></li>
                                示例：<b>苏厨</b>
                                <li><input type="text" id="bookName" class="s_input icon_key"
                                           placeholder="采集的小说名"/></li>
                                示例：<b>二子从周</b>
                                <li><input type="text" id="authorName" class="s_input icon_key"
                                           placeholder="采集的小说作者名"/></li>

                                <!--示例：<b>https://m.xdingdiann.com/sort/0/1.html</b>
                                <li><input type="text" id="updateBookListUrl" class="s_input icon_key"
                                           placeholder="小说更新列表url"></li>-->


                                <li><input type="button" onclick="addCrawlSingleTask()" name="btnRegister" value="提交"
                                           id="btnRegister" class="btn_red"></li>
                            </ul>
                        </div>
                    </form>
                </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 language="javascript" type="text/javascript">
    $(function () {
        $.ajax({
            type: "get",
            url: "/crawl/listCrawlByPage",
            data: {'curr': 1, 'limit': 100},
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {
                    var crawlSourceList = data.data.list;
                    if (crawlSourceList.length > 0) {
                        var crawlSourceListHtml = "";
                        for (var i = 0; i < crawlSourceList.length; i++) {
                            var crawlSource = crawlSourceList[i];
                            crawlSourceListHtml += ("<option value=\"" + crawlSource.id + "\">" + crawlSource.sourceName + "</option>");
                        }
                        $("#sourceId").html(crawlSourceListHtml);


                    }


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

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

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


    function addCrawlSingleTask() {

        var sourceId = $("#sourceId").find("option:selected").val();

        var catId = $("#catId").find("option:selected").val();

        var sourceName = $("#sourceId").find("option:selected").html();


        var sourceBookId = $("#sourceBookId").val();

        if (!sourceBookId) {
            layer.alert("采集的源站小说ID不能为空");
            return;
        }

        var bookName = $("#bookName").val();

        if (!bookName) {
            layer.alert("采集的小说名不能为空");
            return;
        }

        var authorName = $("#authorName").val();

        if (!authorName) {
            layer.alert("采集的小说作者名不能为空");
            return;
        }

        $.ajax({
            type: "POST",
            url: "/crawl/addCrawlSingleTask",
            data: {
                'sourceId': sourceId,
                'sourceName': sourceName,
                'catId': catId,
                'sourceBookId': sourceBookId,
                'bookName': bookName,
                'authorName': authorName
            },
            dataType: "json",
            success: function (data) {
                if (data.code == 200) {

                    window.location.href = '/crawl/crawlSingleTask_list.html';


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

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

    }

</script>
</html>
