/*我的关注列表*/
$(function() {
	var userid = $.cookie("userid");
	expertAttention();
	followResources();
	
	$("#fixbtn li").on("click",function(){
		var indexLi=$(this).index();
		$("#fixbtn li").removeClass("liactive");
		$(".attentsCon .attentList").hide();
		$("#fixbtn li").eq(indexLi).addClass("liactive");
		$(".attentsCon .attentList").eq(indexLi).show();
	});
	$("#lookMyAttention").click(function(){
		$("body").css("position","fixed");
		$("#attentCover").fadeIn();
	})
	//关闭按钮
	$("#workclose").click(function(){
		$("#attentCover").fadeOut();
		$("body").css("position","");
	});
	
	/*关注专家*/
	function expertAttention() {
		var data = {
			"professorId": userid,
			"watchType": 1,
			"pageNo": 1,
			"pageSize": 1000
		}
		$.ajax({
			url: "/ajax/watch/qaPro",
			data: data,
			dataType: 'json', //数据格式类型
			type: 'get', //http请求类型
			success: function(data) {
				$("#expert").html("");
				if(data.success && data.data.data != "") {
					var datalist = data.data.data;
					datalistEach(datalist);
				}
			},
			error: function() {
				$.MsgBox.Alert('提示', "服务器链接超时");
			}
		});
	}

	/*关注资源*/
	function followResources() {
		var data = {
			"professorId": userid,
			"watchType": 2,
			"pageNo": 1,
			"pageSize": 1000
		}
		$.ajax({
			url: "/ajax/watch/qaPro",
			data: data,
			dataType: 'json', //数据格式类型
			type: 'get', //http请求类型
			success: function(data) {
				$("#resources").html("");
				if(data.success && data.data.data != "") {
					var datalistd = data.data.data;
					ResourcesEach(datalistd);
				}
			},
			error: function() {
				$.MsgBox.Alert('提示', "服务器链接超时");
			}
		});
	}

	/*专家数据遍历*/
	function datalistEach(datalist) {
		$.each(datalist, function(index, item) {
			/*获取头像*/
			//console.log(JSON.stringify(item));
			if(item.professor.hasHeadImage == 1) {
				var img = "/images/head/" + item.professor.id + "_l.jpg";
			} else {
				var img = "../images/default-photo.jpg";
			}

			/*获取研究方向信息*/
			var researchAreas = item.professor.researchAreas;
			//console.log(JSON.stringify(item.professor.researchAreas))
			var rlist = '';
			for(var n = 0; n < researchAreas.length; n++) {
				//console.log(researchAreas[n].caption);
				rlist += '<span>' + researchAreas[n].caption
				if(n < researchAreas.length - 1) {
					rlist += " , "
				}
				rlist += '</span>';
			}

			/*获取资源信息*/
			var resources = item.professor.resources;
			var zlist = '';
			for(var m = 0; m < resources.length; m++) {
				//console.log(resources[m].caption);
				zlist += '<span>' + resources[m].resourceName
				if(m < resources.length - 1) {
					zlist += " , "
				}
				zlist += '</span>';
			}

			var title = item.professor.title || "";
			var office = item.professor.office || "";
			var orgName = item.professor.orgName || "";
			var address = item.professor.address || "";

			if(title != "") {
				title = title + " , ";
			}
			if(office != "") {
				office = office + " , ";
			}
			if(orgName != "") {
				orgName = orgName;
			}
			if(address != "") {
				address = " | " + address;
			}

			var li = document.createElement('li');
			li.innerHTML = '<a class="proinfor clearfix" target="_blank" href="information-brow.html?professorId=' + item.professor.id + '">' +
				'<div class="headblock floatL"><img id="proHead" class="headimg headRadius" src="' + img + '"></div>' +
				'<div class="mediaBody">' +
				'<span class="listtit">' + item.professor.name + '<em class="authicon authicon-cu" style="position:absolute;margin:4px 0 0 2px ;"></em></span>' +
				'<p class="listtit2"><span>' + title + '</span><span>' + office + '</span><span>' + orgName + '</span><span>' + address + '</span></p>' +
				'<p class="mui-ellipsis listtit3">' + rlist + '</p>' +
				'<p class="mui-ellipsis listtit3">' + zlist + '</p>' +
				'</div></a></li>';

			$("#expert").append(li);

		});
	}

	/*资源数据遍历*/
	function ResourcesEach(datalistd) {
		$.each(datalistd, function(index, item) {

			/*获取头像*/
			if(item.resource.images.length) {
				var img = "/images/resource/" + item.resource.resourceId + "_s.jpg";
			} else {
				var img = "../images/default-resource.jpg";
			}

			var title = item.resource.editProfessor.title || "";
			var office = item.resource.editProfessor.office || "";
			var orgName = item.resource.editProfessor.orgName || "";
			var address = item.resource.editProfessor.address || "";

			if(title != "") {
				title = title + " , ";
			}
			if(office != "") {
				office = office + " , ";
			}
			if(orgName != "") {
				orgName = orgName;
			}
			if(address != "") {
				address = " | " + address;
			}

			var li = document.createElement('li');

			li.innerHTML = '<a class="proinfor clearfix" target="_blank"  href="resourceInfo.html?resourceId=' + item.resource.resourceId + '">' +
				'<div class="headblock floatL ResImgBox"><img id="proHead" class="resImg" src="' + img + '"></div>' +
				'<div class="mediaBody">' +
				'<span class="listtit">' + item.resource.resourceName + '</span>' +
				'<p class="mui-ellipsis listtit2">' + item.resource.supportedServices + '</p>' +
				'<span class="listtit">' + item.resource.editProfessor.name + '<em class="authicon authicon-cu" style="position:absolute;margin:4px 0 0 2px ;"></em></span>' +
				'<p class="listtit2"><span>' + title + '</span><span>' + office + '</span><span>' + orgName + '</span><span>' + address + '</span></p>' +
				'</div></a></li>';
			$("#resources").append(li);

		});
	}

})