$(document).ready(function() {
	$(".onlogin .headnavbtn li").eq(0).addClass("navcurrent");
	var id = $.cookie('orgId');
	if(id == "" || id == null || id == "null"){
    	location.href = "cmp-settled-log.html";
    }
	/*企业信息*/
	function companyInformation() {
		$.ajax({
			url: "/ajax/org/" + id,
			type: "GET",
			timeout: 10000,
			dataType: "json",
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					var $data = data.data;
					var otext, oguimo;
					console.log(data);
					if($data.authStatus != 3) {
						/*$("#photoClass").addClass("authicon-com-no")
						$("#photoClass").attr("title", "未认证企业");*/
						$("#authBad").show();
					} else {
						$("#photoClass").addClass("authicon-com-ok");
						$("#authOk").show();
						$("#photoClass").attr("title", "认证企业");
					}
					$(".h1Font").find("span").text($data.name);
					if($data.hasOrgLogo) {
						$("#oimg").attr("src", "/images/org/" + $data.id + ".jpg");
					} else {
						$("#oimg").attr("src", "../images/default-icon.jpg");
					}
					if($data.orgUrl) {
						$("#inteAddress").val($data.orgUrl);
					}
					if($data.city) {
						$("#ocity").text($data.city);
					}
					if($data.orgType) {

						switch($data.orgType) {
							case '2':
								otext = "上市企业";
								break;
							case '3':
								otext = "国有企业";
								break;
							case '4':
								otext = "合资企业";
								break;
							case '5':
								otext = "私人企业";
								break;
							case '6':
								otext = "外资企业";
								break;
							case '7':
								otext = "初创企业";
								break;
							default:
								otext = "";
								break;
						}
						if(otext != "")
						$("#cmpBasic").append("<span>" + otext + "</span>")
					}
					if($data.orgSize) {
						switch($data.orgSize) {
							case '1':
								oguimo = "50人以内";
								break;
							case '2':
								oguimo = "50-100人";
								break;
							case '3':
								oguimo = "100-200人";
								break;
							case '4':
								oguimo = "200-500人";
								break;
							case '5':
								oguimo = "500-1000人";
								break;
							case '6':
								oguimo = "1000人以上";
								break;
							default:
								oguimo = "";
								break;
						}
						if(oguimo!="")
						$("#cmpBasic").append("<span>" + oguimo + "</span>")
					}
					if($data.foundTime) {
						var oTime = timeGeshi($data.foundTime);
						$("#cmpBasic").append("<span>" + oTime + "</span>")
					}
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {
				$.MsgBox.Alert('提示', '服务器请求失败')
			}
		})
	}
	/*时间格式转换*/
	function timeGeshi(otm) {
		var otme = otm.substring(0, 4) + "-" + otm.substring(4, 6) + "-" + otm.substring(6, 8);
		return otme;
	}
	companyInformation();
	/*获取所有的企业认证用户*/
	function companyUser() {
		$.ajax({
			url: "/ajax/professor/qaOrgAuth",
			type: "GET",
			timeout: 10000,
			dataType: "json",
			data: {
				"orgId": id,
				"orgAuth": 1
			},
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					console.log(data);
					var $info = data.data;
					userHtml($info);
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {
				$.MsgBox.Alert('提示', '服务器请求失败')
			}
		})
	}
	companyUser();

	function userHtml(arr) {
		for(var i = 0; i < arr.length; i++) {
			var tiof = "",
				img;
			if(arr[i].hasHeadImage) {
				img = "/images/head/" + arr[i].id + "_l.jpg";
			} else {
				img = "../images/default-photo.jpg"
			}
			var oString = '<dd>'
			oString += '<div style="width: 60px;">'
			oString += '<img class="userRadius" src="' + img + '" width="100%" />'
			oString += '<div class="h4Font"><span>' + arr[i].name + '</span></div></div></dd>'
			$("#userList").append(oString);

		}
	}
	/*企业需求*/
	function companyDemand() {
		$.ajax({
			url: "/ajax/demand/pqOrg",
			type: "GET",
			timeout: 10000,
			dataType: "json",
			data: {
				"orgId": id,
				"demandStatus": 1,
				'pageSize': 3
			},
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					console.log(data);
					var $info = data.data.data;
					companyDemandHtml($info);
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {
				$.MsgBox.Alert('提示', '服务器请求失败')
			}
		})
	}
	/*企业需求html*/
	function companyDemandHtml(arr) {
		for(var i = 0; i < arr.length; i++) {
			var tiof = "",
				img, oTime;
			if(arr[i].professor.hasHeadImage) {
				img = "/images/head/" + arr[i].professor.id + "_l.jpg";
			} else {
				img = "../images/default-photo.jpg"
			}
			if(arr[i].demandAim == 1) {
				tiof = "技术咨询";
			} else if(arr[i].demandAim == 2) {
				tiof = "寻找资源";
			} else if(arr[i].demandAim == 3) {
				tiof = "其他需求";
			}
			if(arr[i].createTime) {
				oTime = arr[i].createTime.substring(0, 4) + '年' + arr[i].createTime.substring(4, 6) + "月" + arr[i].createTime.substring(6, 8) + "日 " + arr[i].createTime.substring(8, 10) + ":" + arr[i].createTime.substring(10, 12)
			}
			var ostring = '<li>'
			ostring += '<div class="leftlogo floatL">'
			ostring += '<img class="userRadius" src="' + img + '" width="100%"/>'
			ostring += '<div class="h4Font"><span>' + arr[i].professor.name + '</span></div></div>'
			ostring += '<div class="rightinfo floatL">'
			ostring += '<p class="h3Font fontweight ellipsisSty">' + arr[i].demandTitle + '</p>'
			ostring += '<p class="h5Font"><span>' + tiof + '</span>-<span>' + oTime + '</span></p></div></li>'
			$(".needUlist").append(ostring);
		}
	}
	companyDemand();
	/*跳转企业浏览页面*/
	$("#conmliu").on("click",function(){
		window.open("../companybrowinfor.html?orgId="+id);
	})
})