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

    $("#page, #list").empty();
    ajax("ajax_platform_list.do", data, function(res){
    	if (res.code == 1 && res.list.length > 0){
    		$.each(res.list, function(index, item){
    			html += '<tr>'+
    				'<td>'+$.orderNum(page,pageSize,index)+'</td>'+
    				'<td>'+item.platformName.toNull()+'</td>'+
    				'<td>'+item.type.toString().decode(1,"电视频道",2,"视频平台","其他")+'</td>'+
    				'<td class="nop">'+(item.imgUrl ? '<img src="'+item.imgUrl.toNull()+'" width="98" height="58" valign="middle" onerror="this.src=\'static/img/noimg.jpg\'"/>':'&nbsp;')+'</td>'+
    				'<td class="edit">'+
    					'<a href="javascript:platformModfiy(\'edit\',\'媒体信息\','+item.id+');">编辑</a>&nbsp;&nbsp;'+
    					'<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){
	resetCheckAll();
	getList(page);
}

// 弹窗
function platformModfiy(act, title, id){
	title = title || "";
	id = id || "";
	$.openWindow(act.decode("add","新增","edit","修改","")+title, "platform_info.do?id="+id, 450, 270, true);
}

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

// 保存数据
function save(){
    var data = $('#dataForm').serializeJSON();
	data.id = $.getParam("id");
    data.imgUrl = $("#imgUrl")[0].src;
    
	if (data.platformName.isEmpty()){
        top.alert("请填写媒体名称", 0, function(){
            $("input[name='platformName']").focus();
        });
        return false;
    }
    if (data['imgUrl'].isEmpty() || data['imgUrl'].indexOf("ylcm_sys") > 1){
    	top.alert("请上传媒体LOGO");
        return false;
    }
	top.ajax("save_platform.do", data, function(res){
        if (res.code == 1){
            top.alert("保存成功。", 1, function(){
            	top.getList(1);
            	top.$.closeWindow();
            });
        } else {
            top.alert(res.msg);
        }
    });
}

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

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