// 获取表格数据
function getList(page){
	page = page || 1;
	var pageSize = 10,data = {
        "mediaDate" : $("#mediaDate").val(),
        "mediaType" : $("#mediaType option:selected").val(),
        "pageNo" : page,
        "pageSize" : pageSize
    }, html = "";

    $("#page, #list").empty();
    ajax("ajaxSearchAdRankList.do", data, function(res){
    	if (res.code == 1 && res.list.length > 0){
    		$.each(res.list, function(index, item){
    			html += '<tr>'+
    				'<td>'+(item.mediaDate ? new Date(item.mediaDate.time).Format("yyyy-MM-dd"):"")+'</td>'+
    				'<td>'+item.mediaType.toString().decode(0,"电视台排名",1,"电视台电视剧排名",2,"电视台栏目排名",3,"网络平台电视剧排名",4,"网络平台栏目排名","")+'</td>'+
    				'<td>'+((item.mediaType==3||item.mediaType==4)?"--":(item.cityType.toString().decode(0,"35城",1,"52城","")))+'</td>'+
                    '<td class="edit"><a href="javascript:openInfoWin('+item.id+','+item.mediaType+');">'+item.dataNum +'</a></td>'+
    				'<td class="edit">'+
                    // '<a href="javascript:delRecord('+item.id+');" style="color: dodgerblue;">删除</a>'+
                   	 	(delete_flag == 1 ? '<a href="javascript:delRecord('+item.id+');">删除</a>' : '' )+
    				'</td>'+
    			'</tr>';
    		});
    		$("#list").html(html);
            $("#count").text(res.count);
            var newpage = new createPage(res.count, page, pageSize, 3);
            $("#page").html(newpage.pageHtml);
    	}else{
    		$("#list").info("暂无数据。");
    	}
    });
}
pageGo = function(page){
	getList(page);
}

// 弹窗
function openImportWin(title, type){
    $("#isSure").val("");
    $("#selectMediaType").val("");
	$.openWindow(title, "select_media_type.do?type="+type, 450, 270, true);
}

function confirmWin(type) {
    var selectMediaType = $('input:radio[name="mediaType"]:checked').val();
    if (type == 0) {
    	console.log(top.$("#download"+selectMediaType).attr('href'));
        window.open(top.$("#download"+selectMediaType).attr('href'));
    }
    if (type == 1) {
        top.$("#selectMediaType").val(selectMediaType);
        top.$("#excelfile").click();
    }
    top.$.closeWindow();
}

function openInfoWin(id, mediaType) {
    $.openWindow(mediaType.toString().decode("0","电视台排名","1","电视台电视剧排名","2","电视台栏目排名","3","网络平台电视剧排名","4","网络平台栏目排名",""),
		"ad_mediarank_info.do?id="+id, 500, 470, true, null, true);
}

// 删除记录
function delRecord(id){
	confirm("确定删除该条记录吗？", function(){
        ajax("del_ad_rank.do", {"id" : id}, function(res){
            if (res.code == 1){
    			alert("删除成功。", 1, function(){
    				window.location.href = "ad_mediarank_list.do";
    			});
            } else {
            	alert(res.msg);
            }
        });
	});
}

// 导入表格数据
function importExcel(obj){
	$("#fileForm").submit();
}

// 导入结果
function excelCallback(code, msg) {
	if (code == 1) {
        // 导入成功
    	alert("导入成功。", 1, function(){
			window.location.href = "ad_mediarank_list.do";
		});
    } else {
    	// 导入失败
    	alert(msg, 0, function(){
        	location.reload();
		});
    }
}

// 确认覆盖
function confirmCallback(repeat, msg) {
    if (repeat == 1){
        confirm(msg, function(){
            top.$("#isSure").val("sure");
            top.$("#fileForm").submit();
        });
    }
}