$(document).ready(function() {
var articleId = GetQueryString("articleId");
var professorId = GetQueryString("professorId");
var oFlag = GetQueryString("oFlag");
loginStatus();//判断个人是否登录
var userid = $.cookie("userid");
if(userid == "null"||userid==undefined) {
$(".goMsgbox").hide();
} else {
$("#login").hide();
}
/*应用行业*/
var industryShow = function(data, $id) {
if(data != undefined && data.length != 0) {
var subs = new Array();
if(data.indexOf(',')) {
subs = data.split(',');
} else {
subs[0] = data;
}
if(subs.length > 0) {
var html = [];
for(var i = 0; i < subs.length; i++) {
html.push("
" + subs[i] + "");
};
document.getElementById($id).innerHTML = html.join('');
}
}
}
function proInfoMain() {
$.ajax({
url: "/ajax/article/query",
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
data: {
"articleId": articleId
},
timeout: 10000, //超时设置
success: function(data) {
var $info = data.data || {};
if(data.success && data.data) {
console.log(data);
//var oTime = $info.createTime.substring(0, 4) + "." + $info.createTime.substring(4, 6) + "." + $info.createTime.substring(6, 8)
var oTime=timeGeshi($info.createTime);
$("#creTime").text(oTime);
$("#articleName").text($info.articleTitle);
$(".message1").text($info.articleAgree);
if($info.subject) {
industryShow($info.subject, "subjectList");
} else {
$("#subjectList").parent().hide();
}
if($info.industry) {
industryShow($info.industry, "industryList");
} else {
$("#industryList").parent().hide();
}
if(!$info.subject&&!$info.industry){
$(".resAbout").hide();
}
var proTitle = document.getElementById("proTitle");
var proOffice = document.getElementById("proOffice");
var proOrg = document.getElementById("proOrg");
var proAddress = document.getElementById("proAddress");
if($info.articleContent) {
$("#main_content").html($info.articleContent);
var oImg = $("#main_content").find("img");
for(var i = 0; i < oImg.length; i++) {
(function(n) {
$("#main_content").find("img").eq(n).load(function() {
var imgWidth = $("#main_content").find("img").eq(n).width();
var pWidth = $("#main_content").find("p").width();
if(imgWidth > pWidth) {
$("#main_content").find("img").eq(n).css({
"width": "100%"
});
}
})
})(i);
}
}
var articletitle = $info.articleTitle + "-科袖网";
window.setTimeout(function() {
document.title = articletitle;
}, 500);
}
},
error: function() {
return;
}
});
}
var proArticle = function() {
var $f=new Object();
if(oFlag==1){
$f.orgId=professorId;
}else{
$f.professorId=professorId;
}
/*科研文章*/
$.ajax({
url: (oFlag==1)?"/ajax/article/qaOrg":"/ajax/article/qaPro",
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
data: $f,
timeout: 10000, //超时设置
success: function(data) {
if(data.success) {
var $data = data.data;
if($data.length == 1) {
$("div:contains('相关文章')").parents(".rightBlock").hide();
return;
}
var oNu=Math.min(data.data.length,3);
for(var i = 0; i < oNu; i++) {
if(articleId != $data[i].articleId) {
var articleImg = $data[i].articleImg;
(!articleImg) ? articleImg = "../images/default-artical.jpg": articleImg = '/data/article/' + $data[i].articleImg;
if($data[i].industry) {
var subs = new Array();
if($data[i].industry.indexOf(',')) {
subs = $data[i].industry.split(',');
} else {
subs[0] = $data[i].industry;
}
if(subs.length > 0) {
var indu = "";
for(var n = 0; n < subs.length; n++) {
indu += "" + subs[n] + "";
}
}
} else {
var indu = "";
}
var add = ''
if(oFlag==1){
add += ''
}else{
add += ''
}
add += ''
add += '
'
add += '
'
add += '
' + $data[i].articleTitle + '
'
add += ''
add += '
'
add += ''
add += indu
add += '
'
add += ''
add += ''
$(".otherRes").append(add);
}
}
}
},
error: function() {
return;
}
});
}
function message() {
$.ajax({
url: "/ajax/leaveWord/ql",
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
data: {
"articleId": articleId
},
timeout: 10000, //超时设置
success: function(data) {
var $info = data.data || {};
if(data.success && data.data) {
$(".commentList").html("");
$(".message").text($info.length);
for(var i = 0; i < $info.length; i++) {
//var time = $info[i].createTime.substring(0, 4) + "年" + $info[i].createTime.substring(4, 6) + "月" + $info[i].createTime.substring(6, 8) + "日 " + $info[i].createTime.substring(8, 10) + ":" + $info[i].createTime.substring(10, 12);
var time=timeGeshi($info[i].createTime)
if($info[i].professor.hasHeadImage){
var img='/images/head/' + $info[i].professor.id + '_l.jpg'
}else{
var img='../images/default-photo.jpg'
}
var string = ''
string += ''
string += ''
string += ''
string += '
'+$info[i].professor.name+''+time+'
'
string += '
'+$info[i].content+'
'
if(userid==$info[i].professor.id){
string += '
删除
'
}
string += '
'
$(".commentList").append(string);
}
}
},
error: function() {
return;
}
});
}
function userInformation(){
if(oFlag==1){
$.ajax({
url: "/ajax/org/" + professorId,
type: "GET",
timeout: 10000,
dataType: "json",
beforeSend: function() {},
success: function(data, textState) {
if(data.success) {
var $data = data.data;
$("#nameS").text($data.name);
$("#proName").text($data.name);
if($data.authStatus == 3) {
$("#authFlag,#proTitle").replaceWith("");
} else {
$("#authFlag,#proTitle").replaceWith("");
}
if($data.hasOrgLogo) {
$("#headImg,#proHead").attr("src", "/images/org/" + $data.id + ".jpg").addClass("headRadius").removeClass("userRadius");
} else {
$("#headImg,#proHead").attr("src", "images/default-icon.jpg").addClass("headRadius").removeClass("userRadius");
}
// if($data.foundTime) {
// var oTime = $data.foundTime.substring(0,4)+"-"+$data.foundTime.substring(4,6)+"-"+$data.foundTime.substring(6,8);
// $("#createTime").text(oTime);
// }
if($data.city) {
$("#ocity").text($data.city);
}
if($data.orgSize) {
switch($data.orgSize) {
case '1':
$("#qualificationList").text("50人以内")
break;
case '2':
$("#qualificationList").text("50-100人")
break;
case '3':
$("#qualificationList").text("100-200人")
break;
case '4':
$("#qualificationList").text("200-500人")
break;
case '5':
$("#qualificationList").text("500-1000人")
break;
default:
$("#qualificationList").text("1000人以上")
break;
}
}
if($data.orgType) {
switch($data.orgType) {
case '2':
$("#orgType").text("国有企业");
break;
case '3':
$("#orgType").text("上市企业");
break;
case '4':
$("#orgType").text("合资企业");
break;
case '5':
$("#orgType").text("私人企业");
break;
case '6':
$("#orgType").text("外资企业");
break;
default:
$("#orgType").text("初创企业");
break;
}
}
}
},
error: function(XMLHttpRequest, textStats, errorThrown) {
$.MsgBox.Alert('提示', '服务器请求失败')
}
})
}else{
$.ajax({
url: "/ajax/professor/editBaseInfo/"+professorId,
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
timeout: 10000, //超时设置
success: function(data) {
console.log(data);//
if(data.success && data.data) {
/*if(data.data.hasHeadImage==1){
$("#limg").attr("src","/images/head/" + data.data.id + "_l.jpg")
}*/
var $profesor=data.data;
$("#nameS,#proName").text($profesor.name);
var oString = todStr($profesor.title, $profesor.office, $profesor.department);
$("#proTitle").text(oString);
if($profesor.title) {
if($profesor.office) {
$("#orgType").text($profesor.title + " , "+$profesor.office);
} else {
$("#orgType").text($profesor.title);
}
}else{
if($profesor.office) {
$("#orgType").text($profesor.office);
}
}
if($profesor.department) {
$("#qualificationList").text($profesor.department);
}
if($profesor.orgName){
$("#createTime").text($profesor.orgName)
}
if($profesor.address) {
$("#ocity").text($profesor.address);
}
if($profesor.hasHeadImage) {
$("#headImg,#proHead").attr("src", "/images/head/" + $profesor.id + "_l.jpg").addClass("userRadius").removeClass("headRadius")
}else{
$("#headImg,#proHead").attr("src", "images/default-photo.jpg").addClass("userRadius").removeClass("headRadius")
}
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败')
}
});
}
}
/*职位职称所属机构*/
function todStr() {
var arr = new Array(),
i;
for(i in arguments) {
if(arguments[i]) {
arr.push(arguments[i])
}
}
return arr.join();
}
/*时间格式转换*/
function timeGeshi(otm) {
var ti=otm.substring(4, 5);
var otme;
if(ti=="0"){
otme =otm.substring(5, 6) + "月" + otm.substring(6, 8)+"日 "+otm.substring(8, 10)+":"+otm.substring(10, 12);
}else{
otme =otm.substring(4, 6) + "月" + otm.substring(6, 8)+"日 "+otm.substring(8, 10)+":"+otm.substring(10, 12);
}
return otme;
}
function article() {
$.ajax({
url:"/ajax/leaveWord",
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
data: {
"articleId": articleId,
"sender": userid,
"content": $("textarea").val(),
},
timeout: 10000, //超时设置
success: function(data) {
var $info = data.data || {};
if(data.success && data.data) {
document.getElementsByTagName("textarea")[0].value = "";
document.getElementById("meSend").style.background="#dadada";
message();
}
},
error: function() {
$.MsgBox.Alert('提示', '服务器请求失败')
}
});
}
function trim(str) { //删除左右两端的空格
return str.replace(/(^\s*)|(\s*$)/g, "");
}
document.getElementsByTagName("textarea")[0].addEventListener("keyup", function() {
var valueLength = document.getElementsByTagName("textarea")[0].value;
var length = trim(valueLength);
if(length) {
$("#meSend").addClass("colorAdd");
document.getElementById("meSend").style.background="#ff9900";
} else {
$("#meSend").removeClass("colorAdd");
document.getElementById("meSend").style.background="#dadada";
}
});
$(".goMsgbox").on('click', '.colorAdd', function() {
article();
});
function luser(){
$.ajax({
url: "/ajax/professor/editBaseInfo/"+userid,
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
timeout: 10000, //超时设置
success: function(data) {
if(data.success && data.data) {
if(data.data.hasHeadImage==1){
$("#limg").attr("src","/images/head/" + data.data.id + "_l.jpg")
}
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
}
proInfoMain();
proArticle();
message();
userInformation();
luser();
/*删除留言*/
$(".commentList").on("click","span:contains('删除')",function(){
var oDid=$(this).attr("data-id");
var $this=$(this);
$.ajax({
url: "/ajax/leaveWord/delete",
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
timeout: 10000, //超时设置
data:{
"id":oDid
},
success: function(data) {
if(data.success) {
$this.parents('li').remove();
var oNum=$(".message").eq(0).text();
$(".message").text(oNum-1);
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败')
}
});
})
/*跳转详情页面专家或者企业*/
$("#details").click(function(){
if(oFlag==1){
location.href="companybrowinfor.html?orgId="+professorId;
}else{
location.href="information-brow.html?professorId="+professorId;
}
})
/*点赞模块*/
var oIsGree = {
/*查询登陆者是否为文章点赞*/
inquiry: function() {
$.ajax({
url: "/ajax/article/isAgree",
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
timeout: 10000, //超时设置
data: {
operateId:userid,
articleId:articleId
},
success: function(data) {
if(data.success) {
if(data.data==null){
$(".plus").attr("data-flag","0");
}else{
$(".plus").attr("data-flag","1");
$(".plus").css("background-position-y","-26px");
}
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
},
/*点赞及取消点赞*/
favour:function() {
$(".plus").click(function(){
if(userid == "null"||userid==undefined){
location.href="login.html";
return;
}
var isgree=$(this).attr("data-flag");
if(isgree==0){
oIsGree.articleIsAgree();
}else{
oIsGree.articleNoIsAgree();
}
});
},
/*为文章点赞*/
articleIsAgree:function(){
$.ajax({
url: "/ajax/article/agree",
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
timeout: 10000, //超时设置
data: {
operateId:userid,
articleId:articleId
},
success: function(data) {
if(data.success) {
$(".plus").attr("data-flag","1");
$(".plus").css("background-position-y","-26px");
$(".message1").text(parseInt($(".message1").html())+1);
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
},
/*为文章取消点赞*/
articleNoIsAgree:function(){
$.ajax({
url: "/ajax/article/unAgree",
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
timeout: 10000, //超时设置
data: {
operateId:userid,
articleId:articleId
},
success: function(data) {
if(data.success) {
$(".plus").attr("data-flag","0");
$(".plus").css("background-position-y","0px");
$(".message1").text(parseInt($(".message1").html())-1);
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
}
}
oIsGree.inquiry();
oIsGree.favour();
/*收藏模块*/
var collection={
/*查询是否收藏文章*/
inquiry:function(){
$.ajax({
url: "/ajax/watch/hasWatch",
dataType: 'json', //数据格式类型
type: 'GET', //http请求类型
timeout: 10000, //超时设置
data: {
professorId:userid,
watchObject:articleId
},
success: function(data) {
if(data.success) {
if(data.data==null){
$("#attention").attr("data-flag","0");
}else{
$("#attention").attr("data-flag","1").css({"background":"url(../images/favoricon.png) 0 -26px no-repeat","background-size": "100% auto"});
}
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
},
/*收藏及取消收藏*/
attention:function() {
$("#attention").click(function(){
if(userid == "null"||userid==undefined){
location.href="login.html";
return;
}
var attFlag=$(this).attr("data-flag");
if(attFlag==0){
collection.attentionYes();
}else{
collection.attentionNo();
}
});
},
/*收藏文章*/
attentionYes:function(){
$.ajax({
url: "/ajax/watch",
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
timeout: 10000, //超时设置
data: {
professorId:userid,
watchObject:articleId,
watchType:3
},
success: function(data) {
if(data.success) {
$("#attention").attr("data-flag","1").css({"background":"url(../images/favoricon.png) 0 -26px no-repeat","background-size": "100% auto"});
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
},
/*取消收藏文章*/
attentionNo:function(){
$.ajax({
url: "/ajax/watch/delete",
dataType: 'json', //数据格式类型
type: 'POST', //http请求类型
timeout: 10000, //超时设置
data: {
professorId:userid,
watchObject:articleId
},
success: function(data) {
if(data.success) {
$("#attention").attr("data-flag","0").css({"background":"url(../images/favoricon.png) 0 -50px no-repeat","background-size": "100% auto"});
}
},
error: function(XMLHttpRequest) {
$.MsgBox.Alert('提示', '服务器请求失败');
}
});
}
};
collection.inquiry();
collection.attention();
})