$(document).ready(function() {
	$(".onlogin .headnavbtn li").eq(0).addClass("navcurrent");
	var demandId = GetQueryString("demandId");	

	function angleDemand() {
		$.ajax({
			url: "/ajax/demand/queryOne",
			type: "GET",
			timeout: 10000,
			dataType: "json",
			data: {
				"demandId": demandId,
			},
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					console.log(data);
					var $data = data.data;
					var oTime, oDemandType;
					$("#dialog_consultTitle").text($data.demandTitle);
					oTime = $data["createTime"].substr(0, 4) + "年" + $data.createTime.substr(4, 2) + "月" + $data.createTime.substr(6, 2) + "日" +
						$data.createTime.substr(8, 2) + ":" + $data.createTime.substr(10, 2);
					$("#dialog_consultTime").text(oTime);
					if($data.closeTime) {
						$("#dil_consultStatus").text("已关闭");
						var oCloseTime = $data["closeTime"].substr(0, 4) + "年" + $data.closeTime.substr(4, 2) + "月" + $data.createTime.substr(6, 2) + "日" +
							$data.closeTime.substr(8, 2) + ":" + $data.closeTime.substr(10, 2);
						$("#dialog_consultTime1").text(oCloseTime);
						$(".closeBtn").hide();
					} else {
						$("#dil_consultStatus").text("发布中");
					}
					if($data.demandType == 1) {
						oDemandType = "个人需求"
					} else {
						oDemandType = "企业需求"
					}
					$("#dialog_consultType1").text(oDemandType);
					if($data.demandAim == 1) {
						oDemandAim = "技术咨询"
					} else if($data.demandAim == 2) {
						oDemandAim = "资源咨询"
					} else if($data.demandAim == 3) {
						oDemandAim = "其他咨询"
					}
					$("#dialog_consultType2").text(oDemandAim);
					$("#dialog_consultContent").text($data.demandContent);
					if($data.professor.hasHeadImage){
						$("#oimg").attr("src","/images/head/" + $data.professor.id + "_l.jpg")														
					}else{
						$("#oimg").attr("src","../images/default-photo.jpg")
					}
					$("#userName").text($data.professor.name);
					var oString = todStr($data.professor.title, $data.professor.office, $data.professor.department);
					$("#offt").text(oString);
					if($data.organization.hasOrgLogo){
						$("#organizationImg").attr("src", "/images/org/" + $data.organization.id + ".jpg");
					}else{
						$("#organizationImg").attr("src", "../images/default-icon.jpg");
					}
					$("#organName").text($data.organization.name);
					if($data.organization.authStatus){
						$("#authCompany").addClass("authicon-com-ok");
						$("#authCompany").attr("title","认证企业")
					}else{
						/*$("#authCompany").addClass("authicon-com-no");
						$("#authCompany").attr("title","未认证企业")*/
					}
					if($data.organization.industry){
						$(".ellipsisSty").text($data.organization.industry);
					}
					var oClass = autho($data.professor.authType, $data.professor.orgAuth, $data.professor.authStatus);
					$("#authFlag").addClass(oClass.sty).attr("title",oClass.title);
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {

			}
		})
	}
	angleDemand();
	$(".closeBtn").click(function() {
		$.MsgBox.Confirm("消息", "确认关闭此需求？——关闭后，专家将看不到此需求，但不会影响进行中的相关咨询。", closeDemand)
	})

	function closeDemand() {
		$.ajax({
			url: "/ajax/demand/close",
			type: "POST",
			timeout: 10000,
			dataType: "json",
			data: {
				"demandId": demandId,
			},
			beforeSend: function() {},
			success: function(data, textState) {
				if(data.success) {
					$(".closeBtn").hide();
					$("#dil_consultStatus").text("已关闭");
				}
			},
			error: function(XMLHttpRequest, textStats, errorThrown) {

			}
		})
	}
	/*职位职称所属机构*/
	function todStr() {
		var arr = new Array(),
			i;
		for(i in arguments) {
			if(arguments[i]) {
				arr.push(arguments[i])
			}
		}
		return arr.join();
	}
})