<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采集任务/网站管理</title>
</head>
<body>

<link rel="stylesheet" href="<%=request.getContextPath()%>/comm/plugins/jqgrid/css/ui.jqgrid.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/style/bootstrap.css">
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/style/cupertino/jquery-ui-1.7.2.custom.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/style/style.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/style/main.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/style/framestyle.css">

<script type="text/javascript" src="<%=request.getContextPath()%>/comm/site.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/dialog.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/eb.grid.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/ckfinder/ckfinder.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/jquery/jquery-1.8.3.js"></script>

<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/jquery/jquery-1.7.2.min.js" ></script>
<script type=text/javascript   src="<%=request.getContextPath()%>/comm/plugins/mras/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/bootstrap.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/template.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/mras/jquery.jqGrid-4.3.1/js/jquery.jqGrid.src.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/jqgrid/js/i18n/grid.locale-en.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/calendar/calendar.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/mras/jquery/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/mras/jquery/jquery.blockUI.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/echarts.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/highcharts-5.0.7/highcharts.js" ></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/comm/plugins/highcharts-5.0.7/highcharts-3d.js" ></script>
<script>
	$(document).ready(function() {
		siteGrid();
		$(".site-query").click(function(){
			siteGrid();
		})

		//新增弹窗
		$("#detail-edit").click(function(){
			$("input[value='0']").attr('checked','true');
			$(".ui-dialog-title").text("新增数据");
			$("#detail-dialog").dialog("open");
		});
		//验证弹窗
		$("#detail-edit").click(function(){
			$("#verify-dialog").dialog("open");
		});

		$("#detail-dialog").dialog({
			autoOpen:false,
			modal:true,
			width:600,
			height:570,
			resizable:false,
			buttons:{
				"确认":function(){
					var name=$("input[name='name']").val();
					if(name==undefined||name==""){
							genWarn("input[name='name']",'	必填项');
						return ;
					}
					var domainUrl=$("input[name='domainUrl']").val();
					if(domainUrl==undefined||domainUrl==""){
						genWarn("input[name='domainUrl']",'	必填项');
						return ;
					}
					var uri=$("input[name='uri']").val();
					if(uri==undefined||uri==""){
						genWarn("input[name='name']",'	必填项');
						return ;
					}
					var category=$("select[name='category']").val();
					if(category==undefined||category==""){
						genWarn("select[name='category']",'	必填项');
						return ;
					}

					var matchTitle=$("input[name='matchTitle']").val();
					var matchSummary=$("input[name='matchSummary']").val();
					var matchContent=$("input[name='matchContent']").val();
					var matchOrigin=$("input[name='matchOrigin']").val();
					var matchAuthor=$("input[name='matchAuthor']").val();
					var matchPublishDate=$("input[name='matchPublishDate']").val();
					var id=$("#siteid").text();
					var sitemsg={id:id,name: name,domainUri: domainUrl,uri: uri,category: category,
						matchTitle: matchTitle,matchSummary: matchSummary, matchContent: matchContent,
						matchOrigin: matchOrigin,matchAuthor: matchAuthor,matchPublishDate: matchPublishDate}
					$.ajax({
						url:"save",
						type:"post",
						dataType:"json",
						headers:{'Content-Type':'application/json;charset=utf8'},
						data:JSON.stringify(sitemsg),
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							console.log(textStatus);
							if ('timeout' == textStatus)
								alert("系统忙、请稍候再试...");
						},
						success:function(data){
							if(data.success){
								$("#detail-dialog").dialog("close");
								$(".msg-content","#msg-dia").html(data.desc);
								$("#msg-dia").dialog("open");
							}else{
								$(".dia_msg","#detail-dialog").html(data.desc);
							}
						}

					});
				},
				"取消":function(){
					$(this).dialog("close");

					//location.reload(); //刷新页面
				}

			},
			close:function(){
				//	location.reload();
				// $("input[name='name']").val("");
				// $("input[name='domainUrl']").val("");
				// $("select[name='uri']").val("");
				// $("input[name='category']").val("");
				// $("input[name='matchTitle']").val("");
				// $("input[name='matchSummary']").val("");
				// $("input[name='matchContent']").val("");
				// $("input[name='matchOrigin']").val("");
				// $("input[name='matchAuthor']").val("");
				// $("input[name='matchPublishDate']").val("");
				$(".dia_msg").remove();
				$('span').remove(".warn");
			}
		});
		$("#verify-dialog").dialog({
			autoOpen:false,
			modal:true,
			width:600,
			height:570,
			resizable:false,
			buttons:{
				"验证":function(){
					$.ajax({
						url:"verifySite",
						type:"get",
						dataType:"json",
						headers:{'Content-Type':'application/json;charset=utf8'},
						data:{id:$("#siteid").text()},
						async: false,
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							if ('timeout' == textStatus)
								alert("系统忙、请稍候再试...");
						},
						success:function(data){
							if(data.success){
                                $(".verify-title").html(data.data.title);
                                $(".verify-summary").html(data.data.summary);
                                $(".verify-content").html(data.data.contentWithTag);
                                $(".verify-contentNoTag").html(data.data.contentNoTag);
                                $(".verify-author").html(data.data.author);
                                $(".verify-publishDate").html(data.data.publishDate);
                                $(".verify-origin").html(data.data.origin);
							}else{
								$(".dia_msg","#detail-dialog").html("验证失败");
							}
						}
					});
				},
				"不通过":function(){
					$(this).dialog("close");

					//location.reload(); //刷新页面
				},"通过":function (){

                }

			},
			close:function(){
				//	location.reload();
				// $("input[name='name']").val("");
				// $("input[name='domainUrl']").val("");
				// $("select[name='uri']").val("");
				// $("input[name='category']").val("");
				// $("input[name='matchTitle']").val("");
				// $("input[name='matchSummary']").val("");
				// $("input[name='matchContent']").val("");
				// $("input[name='matchOrigin']").val("");
				// $("input[name='matchAuthor']").val("");
				// $("input[name='matchPublishDate']").val("");
				$(".dia_msg").remove();
				$('span').remove(".warn");
			}
		});

		//弹框
		$("#msg-dia").dialog({
			autoOpen:false,
			modal:true,
			width:300,
			height:200,
			resizable:false,
			buttons:{
				"确定":function(){
					$("#msg-dia").dialog("close");
					location.reload(); //刷新页面
				}
			}
		});

		$("#remove-dia").dialog({
			autoOpen:false,
			modal:true,
			width:250,
			height:200,
			resizable:false,
			onLoad:function(){
				$('#name').val("赋值");
			},

			buttons:{
				"确认":function(){
					$.ajax({
						type:"get",
						url: '/needsite/deleteById',
						dataType:"json",
						data:{id:$("#siteid").text()},
						error: function (XMLHttpRequest, textStatus, errorThrown) {
							console.log(textStatus);
							if ('timeout' == textStatus)
								alert("系统忙、请稍候再试...");
						},
						success:function(data){
							if(data.success){
								$("#remove-dia").dialog("close");
								$(".msg-content","#msg-dia").html(data.desc);
								$("#msg-dia").dialog("open");
							}else{
								//	$(".dia_msg","#delete-dia").html(data.desc);
								$("#remove-dia").dialog("close");
								$(".msg-content","#msg-dia").html(data.desc);
								$("#msg-dia").dialog("open");
							}
						}

					});
				},
				"取消":function(){
					$(this).dialog("close");
					//	location.reload(); //刷新页面
				}
			},
			close:function(){
				location.reload();
				$(".dia_msg").remove();
			}

		});
	});

	//表单验证提示信息
	function genWarn(target,warn){
		$('span').remove(".warn");
		$(target).after('<span class="warn">'+warn+'</span>');
	}

	function siteGrid(){
		var opt={
			headUrl:"/needsite/getColumnSite",
			gridUrl:"/needsite/getPageDetail",
			data:{keywords:$("input[name='site_name']").val(),
				domain_url:$("input[name='domain_uri']").val()
			},
			gridId:"siteGrid",
			tableId:"site_table",
			pageId:"site_pager",
			parentDiv:"siteOverview",
			downloadType:'0',
		}

		ajaxGridHeaders(opt);
	}
	function ajaxGridHeaders(opt){
		$.ajax({
			type: "POST",
			url: opt.headUrl,
			data: opt.data,
			cache: false,
			async : false,
			dataType: "json",
			timeout: 1000*10,
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				var error = '网络连接失败...';
				if ('timeout' == textStatus) error = '系统忙...';
				var $h = $('<h3 class="warn">'+error+'<a href="#">点击这里，刷新数据</a></h3>');
				$('a',$h).click(function(){// 表头数据请求错误，提供刷新功能
					ajaxGridHeaders(opt);
				});
				$("#"+opt.gridId).html($h);
			},
			success: function(msg){
				if( msg.success ){
					ajaxGrid( {
						opt: opt,
						msg: msg
					});
				} else {
					$("#"+opt.gridId).html('<h3 class="warn">'+msg.msg+'</h3>');
				}
			}
		});
	}

	function ajaxGrid(opt){
		if(opt.opt.parentDiv){
			$("#"+opt.opt.parentDiv).show();
		}
		$("#"+opt.opt.gridId).html('<table id="'+opt.opt.tableId+'"></table><div id="'+opt.opt.pageId+'"></div>');
		var rowNum=10;
		$("#"+opt.opt.tableId).jqGrid({
			url: opt.opt.gridUrl,
			datatype: 'json',
			mtype: 'POST',
			async : false,
			jsonReader : {
				root: "rows",
				page: "currpage",
				total: "totalpages",
				records: "totalrecords",
				repeatitems: false,
				id: "0",
				userdata:opt.opt.userdata
			},
			grouping:opt.opt.data.grouping,
			groupingView:opt.opt.data.groupingView,
			postData: opt.opt.data,
			colNames: opt.msg.colNames,
			colModel: opt.msg.colModel,
			rowNum: rowNum,
			rownumbers: false,
			sortname:opt.opt.sortname,
			sortorder: "desc",
			pager: "#"+opt.opt.pageId,
			shrinkToFit: false,
			viewrecords: true,
			autowidth:true,
			height: 300,
			recordtext: "共{2}条记录,显示{0}-{1}",
			emptyrecords: "没有要显示的记录",
			loadtext: "",
			pgtext : "{0}/{1}页",
			beforeRequest:function(){
				$('#load_site_table').remove();
				$('.warn',$('#'+opt.opt.tableId).parent()).remove();
			},
			loadError:function(){
				var $h = $('<div class="warn"><a href="javascript:;">数据读取失败，请点击重试...<a></div>');
				$("a",$h).click(function(){
					ajaxGrid(opt);
				});
				$("#"+opt.opt.tableId).parent().append($h);
			},
			loadComplete:function(){
				var grid = $("#"+opt.opt.tableId);
				var ids = grid.getDataIDs();
				for (var i = 0; i < ids.length; i++) {   //重写表高度
					grid.setRowData ( ids[i], false, {height: 30} );
					$("#siteGrid .ui-jqgrid-labels").css("cssText","height:30px;");
				}

			},
			gridComplete:function(){
				$("#"+opt.opt.tableId).width($("#"+opt.opt.tableId).width()+1);//调整对齐
				var records  = $("#"+opt.opt.tableId).getGridParam('records');
				//	添加数据操作
				if( records && records > 0 ){
					var _ids  = jQuery("#site_table").jqGrid('getDataIDs');  ///获得jqgrid行数
					$(_ids).each(function(i, n) {
						var _html = '';
						var _auth = jQuery("#site_table").jqGrid('getCell', n, 'func');


						_html += ('<a class="dv-func-opt icon-delete btn-opt"  val="'+n+'" title="" >删除</a>');

						jQuery("#site_table").jqGrid('setRowData', n, { func: _html });
					});
					var $t = $(this).parent().parent();
					$('.dv-func-opt').click(function(){
						var $t = $(this).parent().parent();
						var sid=$t.attr('id');
						var flag=0; //0:删除，1：更新，2：验证
						if($(this).attr('class').indexOf('icon-delete')>-1){
							flag=0;
						}
						$.ajax({
							url:"/needsite/getSiteById",
							type:"get",
							dataType:"json",
							headers:{'Content-Type':'application/json;charset=utf8'},
							data:{id:sid},
							error: function (XMLHttpRequest, textStatus, errorThrown) {
								console.log(textStatus);
								if ('timeout' == textStatus)
									alert("系统忙、请稍候再试...");
							},
							success:function(data){
								if(flag==0){
									deleteDiversionById(data.data);
								}

							}

						});


					});

				}else{
					$('#my_grid_task').parent().append('<div class="norecords">没有符合条件的记录</div>');
				}

			}
		});
	};

	/**
	 * 删除数据
	 */
	function deleteDiversionById(args){
		$("#siteid").text(args.id);
		$("#remove-dia").dialog("open");
	}

</script>
<style type="text/css">
	#siteGrid{
		margin-top: 60px;
	}
	.sub-content{
		height: 440px;
		margin: auto;
		margin-top: 50px;
	}
	.ui-jqgrid{
		margin-top: -20px;
	}
	.dialog-sub{padding-top:0px;}
	.dialog-sub p{
		height:30px;
		margin-top:16px;
	}
    .dialog-sub label{
		display:inline-block;
		vertical-align:middle;
		width:120px;
		text-align:right;
		margin-right: 20px;
	}
	.dialog-sub select{margin-bottom:0;font-family:微软雅黑;}
	.dia_msg{color:red;}
	.isreport{
		width:12px;
		margin-left:50px;
		height:10px;
	}
	.dialogmsg{
		height: 28px;
		border: 1px solid #dddddd;
		border-radius: 3px;
		width: 308px;
		padding-left:10px;
	}
	.dia_msg{color:red;}

	.btn-opt, .btn-opt:visited, .btn-opt:active, .btn-opt:focus {
		margin-left: 5px;
		line-height: 26px;
		color: #168EF8 !important;
		min-width: 25px;
		height: 26px;
		padding: 0 8px;
		font-size: 13px;
		background-color: #fff;
		background-image: none;
		border: 0px;
		cursor:pointer;
		text-shadow: none;
		font-family: 微软雅黑;
	}
	.btn-dis{
		color: #C4C4C4 !important;
		pointer-events:none;
	}
	.adddiver{
		float:right;
		width:72px;
		height:28px;
		background-color: #168EF8 !important;
		margin-right: 10px;
		margin-top:6px;
	}
	.grid-title{
		height:40px;
	}
	.msg-content{
		height:40px;
		text-align:center;
		margin-top:40px;
		font-family: 微软雅黑;
		font-size: 12px;

	}

	.ui-dialog .ui-dialog-buttonpane button{
		float:none;
		margin-left:10px;
		background-color: #3A9EDE;
	}
	.ui-dialog .ui-dialog-buttonpane{
		border:0;
		height:52px;
		text-align:center;
	}
	.grid-title .btn{
		padding:0px;
	}
	.warnmark{
		color:red;
		font-size: 12px;
	}
    .verifydialog-sub p{
        margin-top:8px;
    }
    .verifydialog-sub label{
        display:inline-block;
        vertical-align:middle;
        width:400px;
        text-align:left;
        margin-right: 15px;
    }

	/*导航烂*/
	.ulbar .libar:nth-child(3){
		color: #5584FF;
		text-decoration: none;
		border-bottom: 3px solid #5584ff;
	}
	a:hover, a:focus{
		color: #737374;
		text-decoration: none;
	}

	.formulbar{
		background: url("<%=request.getContextPath()%>/images/opinion-nav-bg.png") repeat 0px 0px;
		height:55px;
		width:100%;
	}
	.formulbar .ulbar{
		margin-left:30px;
	}
	.formulbar .libar{
		float: left;
		color:rgb(51, 51, 51);
		font-size:13px;
		font-weight: bold;
		width: 110px;
		margin-right:20px;
		height: 50px;
		text-align: center;
		line-height: 50px;
	}
	.formulbar .libar a{
		display: inline-block;
		width: 100px;
		height: 50px;
		color: #333333;
		text-decoration: none;
	}
	.formulbar .libar a:hover, a:focus {
		color: #5584FF;
		text-decoration: none;
		border-bottom: 3px solid #5584ff;
	}
</style>
<div id="siteOverview" class="sub-content">
	<div class="formulbar">
		<ul class="ulbar">
			<li class="libar" ><a  href="/site/siteList">站点模板</a></li>
			<li class="libar"><a href="/search/baiduword"   >百度搜索测试</a></li>
			<li class="libar" ><a href="/needsite/list" style="width: 110px;" class="active">测试问题站点记录</a></li>

		</ul>
	</div>
		<div class="sub-title">
			<span>抽取失败的站点信息</span>
		</div>
<%--		<a id="detail-edit" class="btn adddiver" style="float:left;">新增数据</a>--%>
		<div style="float:right; display: inline-block;margin-top:5px;">
			<span style="margin-left:10px;">关键词：</span>
			<input name="site_name" placeholder="可模糊查询" style="margin-left:10px;">
			<span style="margin-left:10px;">站点域名：</span>
			<input name="domain_uri" placeholder="可模糊查询" style="margin-left:10px;">
			<%--<a class="title-btn batch-export" href="javascript:void(0);">批量导出</a>
			<a class="title-btn export">数据导出</a>--%>
			<a class="title-btn site-query" href="javascript:;" style="margin-left:10px;">查询</a>
		</div>
		<div id="siteGrid" class="grid-div">
		</div>
</div>

<div id="verify-dialog" title="模板验证">
    <div class="verifydialog-sub">
        <p>
            <label class="verify-tag">站点名称:<span class="name"></span></label>
        </p>
        <p>
            <label class="verify-tag">站点域名: <span class="domainUrl"></span></label>
        </p>
        <p>
            <label class="verify-tag">资讯地址URL: <span class="uri"></span></label>
        </p>
        <p>
            <label class="verify-tag">匹配方式: <span class="category"></span></label>
        </p>
        <p>
            <label class="verify-tag">匹配标题:<span class="matchTitle"></span> </label>
            <textarea class="verify-title" rows="1" cols="50" style="width: 525px; height: 45px;"> </textarea>
        </p>
        <p>
            <label class="verify-tag">匹配摘要:<span class="matchSummary"></span></label>
            <textarea class="verify-summary" rows="1" cols="50" style="width: 525px; height: 45px;"> </textarea>
        </p>
        <p>
            <label class="verify-tag">匹配来源:<span class="matchOrigin"></span> </label>
            <textarea class="verify-origin" rows="1" cols="50" style="width: 525px; height: 45px;"> </textarea>
        </p>
        <p>
            <label class="verify-tag">匹配作者:<span class="matchAuthor"></span></label>
            <textarea class="verify-author" rows="1" cols="50" style="width: 525px; height: 45px;"> </textarea>
        </p>
        <p>
            <label class="verify-tag">匹配发布时间:<span class="matchPublishDate"></span></label>
            <textarea class="verify-publishDate" rows="1" cols="50" style="width: 525px; height: 45px;"> </textarea>
        </p>
        <p>
            <label class="verify-tag">匹配内容:<span class="matchContent"></span> </label>
            <textarea class="verify-content" rows="8" cols="50" style="width: 525px; height: 90px;"> </textarea>
            <textarea class="verify-contentNoTag" rows="8" cols="50" style="width: 525px; height: 90px;"> </textarea>
        </p>
    </div>
	<p class='dia_msg'></p>
</div>


<div id="detail-dialog" title="新增数据">
	<div class="dialog-sub">
		<p>
			<label>站点名称 <span class="warnmark">*</span></label>
			<input class="dialogmsg" name="name"/>
		</p>
		<p>
			<label>站点域名 <span class="warnmark">*</span></label>
			<input class="dialogmsg" name="domainUrl"/>
		</p>
		<p>
			<label>资讯地址URL <span class="warnmark">*</span></label>
			<input class="dialogmsg" name="uri"/>
		</p>
		<p>
			<label>匹配方式 <span class="warnmark">*</span></label>
			<select  name="category" style="height: 35px;">
				<option val="">--请选择--</option>
				<option val="0">默认采集方式</option>
				<option val="1">自定义采集方式</option>
			</select>
		</p>
		<p>
			<label>匹配标题</label>
			<input class="dialogmsg" name="matchTitle"/>
		</p>
		<p>
			<label>匹配摘要</label>
			<input class="dialogmsg" name="matchSummary"/>
		</p>
		<p>
			<label>匹配内容 </label>
			<input class="dialogmsg" name="matchContent"/>
		</p>
		<p>
			<label>匹配来源 </label>
			<input class="dialogmsg" name="matchOrigin"/>
		</p>
		<p>
			<label>匹配作者</label>
			<input class="dialogmsg" name="matchAuthor"/>
		</p>
		<p>
			<label>匹配发布时间</label>
			<input class="dialogmsg" name="matchPublishDate"/>
		</p>
	</div>
	<div id="divertype" style="display:none;">0</div>
	<p class='dia_msg'></p>
</div>



<div id="remove-dia" title="是否删除">
	<div class="msg-content">是否确认删除</div>
	<div id="siteid" style="display:none;"></div>
</div>

<div id="msg-dia" title="提示">
	<p class="msg-content"></p>
</div>

</body>
</html>

