
$(function(){
		initVirtuals();
		$("#btn-search").click(function(){
			$("#conditionform").submit();
		});
		
		//监控项目发生改变
		$("#organizationId").change(function(){
			initVirtuals();
		});
	});
	
	//翻页
	function goPage(pageNo){
		if(pageNo=="gopage"){
			$("#pageNo").val($("#gopage").val());
		}else{
			$("#pageNo").val(pageNo);
		}
		$("#conditionform").submit();
	}


/**
 * 完善资料
 */
function eidtContractIinformationOrder(id,organizationId,virtualArchitectureId,userName,userMobile,userId){
	$('#saveModal').modal('show');
	$('#userName').val(userName);
	$('#userMobile').val(userMobile);;
	$('#contracId').val(id);
	$('#userId').val(userId);
	
	initVirtual(organizationId,virtualArchitectureId);
	$("#status").attr("disabled",false);
	if(virtualArchitectureId!=""){
//		$("#formOrganizationId").attr("disabled",true);
//		$("#formvirtualId").attr("disabled",true);
		//$(".modal-footer").hide();
	}else{
//		$("#formOrganizationId").attr("disabled",false);
//		$("#formvirtualId").attr("disabled",false);
		//$(".modal-footer").show();
	}
	$('#formOrganizationId').val(organizationId);
	$('#formvirtualId').val(virtualArchitectureId);
	$("#save").show();
	$("#myModalLabel").html("客户服务信息完善");
}
/**
 * 提交保存资料信息
 */
function saveUpdateContart(){
	var userId=$("#userId").val();
	//var contracId=$("#contracId").val();
	var contextPath=$("#contextPath").val();
	var organizationId=$("#formOrganizationId").val();
	var virtualArchitectureId=$("#formvirtualId").val();
	$.ajax({
		url :contextPath+"/admin/contract/saveUpdateContart",
		type : "POST",
		data : {userId:userId,organizationId:organizationId,virtualArchitectureId:virtualArchitectureId},
		dataType:"json",
		success : function(data) {
			console.log(data);
			if(data.code=='sucess'){
				alert("信息资料完善成功！");
				location.href=contextPath+"/admin/contract/page?funcid="+$("#funcid").val();
			}else{
				alert("信息资料完善失败，请稍候再试!");
			}
		},
		error : function(data) {
		}
	});
}

/**
 * 查询企业
 */
function initVirtuals(){
	var organizationId=$("#organizationId").val();
	var virtualId_=$("#virtualId_").val();
	$("#virtualId").empty();
	if(organizationId!=""){
		var optionStr="";
		$("#virtualId").append("<option value=''>请选择企业</option>");
		$.ajax({
			url :$("#contextPath").val()+"/busi/property/getvirtualArchTypeOne",
			type : "POST",
			data : {organizationId:organizationId},
			dataType:"json",
			success : function(data) {
				$.each(data,function(index,obj){
					if(virtualId_!=""&&virtualId_==obj.id){
						optionStr+="<option selected='selected' value='"+obj.id+"'>"+obj.name+"</option>";
					}else{
						optionStr+="<option value='"+obj.id+"'>"+obj.name+"</option>";
					}
				});
				$("#virtualId").append(optionStr);
			},
			error : function(data) {
			}
		});
	}
	else{
		$("#virtualId").append("<option value=''>请选择企业</option>");
	}
}


function initVirtual(organizationId,virtualArchitectureId){
	$("#formvirtualId").empty();
	if(organizationId!=""){
		var optionStr="";
		$("#formvirtualId").append("<option value=''>请选择企业</option>");
		$.ajax({
			url :$("#contextPath").val()+"/admin/contract/getSignVirtualArchitectureList",
			type : "POST",
			data : {organizationId:organizationId},
			dataType:"json",
			success : function(data) {
				$.each(data,function(index,obj){
						if(obj.id==virtualArchitectureId){
							optionStr+="<option value='"+obj.id+"' selected=selected>"+obj.name+"</option>";
						}else{
						optionStr+="<option value='"+obj.id+"'>"+obj.name+"</option>";
						}
				});
				$("#formvirtualId").append(optionStr);
			},
			error : function(data) {
			}
		});
	}
	else{
		$("#formvirtualId").append("<option value=''>请选择企业</option>");
	}
}