$(document).ready(function(){
	var ctx = $("#ctx").val();//获取服务器地址
	
	/***************************    素材列表页    ***************************/

 	//状态全部、开启、停用
 	if($("#status").val() == 0 || $("#status").val() == ""){
 		$("#selectBar_status a:first").addClass("selectBar_change");
	}
 	$("#selectBar_status a").each(function(){
 		var value = $(this).attr("value");
 		if($("#status").val() == value){
 			$(this).addClass("selectBar_change").siblings('.selectBar_change').removeClass('selectBar_change');
 		}
 	});
 	$("#selectBar_status a").click(function(){
 		$("#status").val($(this).attr("value"));
 		refreshData();
 	});
 
	//通过，或不通过
	$("#btn-pass,#btn-unpass").click(function(){
		var url = "";var type = "";
		if($(this).attr("id") == "btn-pass"){
			url = ctx+"/back/main/audit/audit-banner/enable";
			type = "pass";
		}else if($(this).attr("id") == "btn-unpass"){
			url = ctx+"/back/main/audit/audit-banner/disable";
			type = "unpass";
		}
		singlePassOrUnpassOper($(this),url,type);
	});
			
	//批量通过，或不通过
	$("#all-btn-pass,#all-btn-unpass").click(function(){
		var url = "";var type = "";
		if($(this).attr("id") == "all-btn-pass"){
			url = ctx+"/back/main/audit/audit-banner/enable";
			type = "pass";
		}else if($(this).attr("id") == "all-btn-unpass"){
			url = ctx+"/back/main/audit/audit-banner/disable";
			type = "unpass";
		}
		batchPassOrUnpassOper($(this),url,type);
	});
	
	$("#btn-auditpass,#btn-auditunpass").click(function(){
		var url = ctx+"/back/main/audit/audit/check";
		var type = "";
		if($(this).attr("id") == "btn-auditpass"){
			type = "pass";
		}else if($(this).attr("id") == "btn-auditunpass"){
			type = "unpass";
		}
		batchAuditOper($(this),url,type);
	});
	
});

function batchAuditOper(obj,url,type){
	if(type == 'pass'){
		var _param = {
    		'auditId':$("#auditId").val(),
    		'checkStatus':1,
    	};
		$.post(url,_param,function(data){
			if(data == "ok"){
				window.location.href = $("#ctx").val()+"/back/main/audit/audit/list";
			} else {
				bootbox.alert("审核失败!");
			}
		})
	} else if(type == 'unpass'){
		 bootbox.prompt("请输入审核不通过的理由", function(result) {
            if (result == '') {
            	bootbox.alert("请输入审核不通过的理由");
            } else {
            	var _param = {
            		'auditId':$("#auditId").val(),
            		'checkMemo':result,
            		'checkStatus':-1,
            	};
            	$.post(url,_param,function(data){
            		if(data == "ok"){
            			window.location.href = $("#ctx").val()+"/back/main/audit/audit/list";
					} else {
						bootbox.alert("审核失败!");
					}
				})
            }
        });
	}
}