//用于判断是否收到咨询传值
var userid = $.cookie("userid");
var professorIdStrByconsult = {
		"professorId":userid
		
};
//用于收到回复传值
var consultIdStrByReply = {
		"consultantId":userid,

};

//点击主页面咨询
$(".workmenu").on("click","#consultbtn",clickConsultBtn);


//data:需要处理的数据，htmlStr:页面中需要的html字符串拼接，
//attrParams:数据中不同的参数比如:收到咨询是professorId，收到答复：consultantId
function handleData(data,attrParams,btnCls){
	var htmlStr = '';
	for(var i = 0; i < data.length;i++){
		var text;
		var state;	
		if(data[i]["consultStatus"] == 0){
			state = "进行中";
			text = '回复';
		} else if (data[i]["consultStatus"] == 1) {
			text = "查看";
			state = "已完成";
			if(attrParams == 'consultId'){
				if(data[i]["assessStatus"] == 0){
					state = "未评价";
				}
			} 
		}
	
		if(data[i]["professor"]["title"] == undefined){
			data[i]["professor"]["title"] = '';
		}
		if(data[i]["professor"]["orgName"] == undefined){
			data[i]["professor"]["orgName"] = '';
		}
		if(data[i]["professor"]["department"] == undefined){
			data[i]["professor"]["department"] = '';
		}
		if(data[i]["professor"]["adress"] == undefined){
			data[i]["professor"]["adress"]  = '';
		};

		//未读信息接口
		var unreadConsultFn = function (senderId,consultId){
			var unreadCount;
			var params = {
					    "senderId":senderId, //发送者ID
					    "consultId":consultId //咨询ID
					};
			$.ajax({
				url:"/ajax/tidings/qaNotReadTidings",
				type:"get",
				async:false,
				data:params,
				success:function(response){
					unreadCount = response["data"];
				},
				error:function(error){
					$.MsgBox.Alert('提示',"未读消息请求失败");
				}
				
			});
			return unreadCount;
			console.log(unreadCount);
		};
		
		
		htmlStr += 
			"<div class='workselectitem' id='" +data[i]["consultId"] +"' >" +
				"<table width='100%'>" +
					"<tbody><tr>" +
						"<td width='14%' class='messagebox'>" +
							"<a class='workhead workitimg'>" +
								"<img src='images/default-photo.jpg' width='100%' height='100%'>" +
							"</a>" +
							"<span class='msgprompt showUnreadMsg' id='" +data[i]["consultId"] +"'>"+unreadConsultFn(userid,data[i]["consultId"])+"</span>" +
						"</td>" +
						"<td style='position:relative;' width='86%'>" +
							"<div class='workinfor worksitcon'>" +
								"<h4><a class='named' id='nameS'> " + data[i]["professor"]["name"] +" </a><img class='modifyicon' src='images/rz.png' width='30'><input type='text' class='assessStar' value='"+data[i]["assessStar"] +"' style='display: none;'></h4>" +
								"<h6><span>职称  " + data[i]["professor"]["title"] +"  </span>,<span>职位   </span>,<span> " + data[i]["professor"]["orgName"] +"  </span>,<span> " + data[i]["professor"]["department"] +" </span>&nbsp;|&nbsp;<span> " + data[i]["professor"]["adress"] +"  </span></h6>" +
								"<h6>"+
								"<span>咨询主题：<em> " + data[i]["consultTitle"] +"  </em></span>" +
									"&nbsp;&nbsp;&nbsp;&nbsp;" +
									"<span>咨询类型：<em> " + data[i]["consultType"] +"  </em></span>" +
									"&nbsp;&nbsp;&nbsp;&nbsp;<span>" +
									"咨询发起时间：<em>  " +
									data[i]["createTime"].substr(0,4) + "-" + data[i]["createTime"].substr(4,2) + "-" + data[i]["createTime"].substr(6,2) + " " + data[i]["createTime"].substr(8,2)+ ":" +data[i]["createTime"].substr(10,2)+
									"</em>" +
									"</span></h6>" +
									"<p>最后回复<span class='lasttime'> (  " +
									lastReplyFn(userid,data[i]["consultId"])["lastReplyTime"]+
									") </span>" +
									"</p>" +
									"<p class='rebackcon lastReplyCon' >"+lastReplyFn(userid,data[i]["consultId"])["lastReplyCon"]+"</p>" +
									"</div>" +
									"<div class='workhandle'>" +
										"<div class='rightopert floatR'>" +
											"<span   attrP='"+attrParams+"' class='replybtn "+btnCls+"' id='"+ data[i]["consultId"]+"' consultStatus='"+ data[i]["consultStatus"]+"' assess='"+ data[i]["assessStatus"]+ "' thanks='"+ data[i]["thanksStatus"]+
											"' onclick='clickLookBtn2(\""+userid+"\",\""+attrParams+"\",\""+data[i]["consultId"]+"\","+data[i]["consultStatus"]+","+data[i]["assessStatus"]+","+data[i]["thanksStatus"]+");'>" +
											text +
											"</span>" +
											"<span class='moreopert complain'>...</span>" +
											"<ul class='moreopertbtn'>" +
												"<li>投诉</li>" +
											"</ul>" +
										"</div>" +
										"<div class='leftstate floatR'>" +
											"<span class='coultstate'><i>"+state+"</i></span>" +
										"</div>" +
									"</div>" +
								"</td>" +
							"</tr></tbody></table>" +
		"</div>";
		
		
	};

	return htmlStr
};


//列表最后回复
function lastReplyFn(sendId,consultId){
	
	var lastReplyTimeData,lastReplyTime,lastReplyCon;
	$.ajax({
		url:"/ajax/tidings/qaLastRevovery",
		async:false,
		data:{
		    "consultId":consultId, //咨询ID
		    "senderId":sendId //登录者ID
		},
		success:function(response){
			if(response["data"] == null || response["data"] == "" || response["data"] == undefined){
				lastReplyTimeData = '';
				lastReplyTime = '';
				lastReplyCon = '';
			}
			else{
				lastReplyTimeData = response["data"]["createTime"];
				lastReplyTime = lastReplyTimeData.substr(0,4) + "-" + lastReplyTimeData.substr(4,2) + "-" + lastReplyTimeData.substr(6,2) + " " + lastReplyTimeData.substr(8,2)+ ":" +lastReplyTimeData.substr(10,2)
				lastReplyCon = response["data"]["tidingsContant"];
			}
			
		},
		error:function(error){
			
		}
		
	});
	
	return  {
		"lastReplyTime":lastReplyTime,
		"lastReplyCon":lastReplyCon
		
	};
};


//咨询点击回复，对话页字符串拼接函数
//data:要处理的数据，htmlStr:需要拼接到页面的元素，position
function dialogContentStrFn(data){
	var htmlStr ="";
	var dialogitem,float,dilinfobox,dilarrow,dilarrow_bor;
	for(var i = 0; i < data.length;i++){
		if(data[i]["professor"]["id"] == userid){
			dialogitem = "dialogrightitem";
			float = "floatR";
			dilinfobox = "dilinfobox_r";
			dilarrow = "dilarrow_r";
			dilarrow_bor="dilarrow_r_bor";
		}
		else{
			dialogitem = "dialogleftitem";
			float = "floatL";
			dilarrow = "dilarrow_l";
			dilinfobox = "dilinfobox_l";
			dilarrow_bor="dilarrow_l_bor";
		}
		htmlStr += 
			"<div class='"+dialogitem+"'>" +
			"<div class='dilmod'>" +
				"<div class='diluser "+float+"'>" +
					"<a  target='_blank' class='userface'>" +
						"<img src='images/default-photo.jpg' width='100%' height='100%'>" +
					"</a>" +
				"</div>" +
				"<div class='dilinfobox "+ dilinfobox+" "+ float +"'>" +
					"<div class='delinfocon clearfix'>" +
						"<div class='dilarrow "+ dilarrow+"'></div>" +
						"<div class='dilarrow "+dilarrow_bor+"'></div>" +
						"<div class='delinfomain "+float+"'>" +
							"<div class='cont'>" +
								"<p>"+data[i]["tidingsContant"]+"</p>" +
							"</div>" +
						"</div>" +
					"</div>" + //dilinfobox
				"</div>" + //dilinfobox
			"</div>" +  //dilmod
		"</div>" + //dialogrightitem
	"</div> "
	};
	
	return htmlStr;
};



//收到回复
var getMyData = function (url,pageSize,pageNo,isbind,status,timeType,sortType){
	var params = {
		    "consultantId":userid, //专家ID
		    "status":status, //查询状态 0-全部，1-进行中，2-未感谢，3-未评价，4-已完成， 可以不传，默认为0
		    "timeType":timeType, //排序类型 0-按发起时间，1-按最后回复时间，2-按完成时间 默认为0
		    "sortType":sortType, //排序类型 0-倒序，1-正序 默认为0
		    "pageSize":pageSize, //每页记录数 默认为5
		    "pageNo":pageNo //当前页码 默认为1
		};
	$.ajax({
    	url:url,//收到回复接口,//收到回复接口
		type:"get",
		//传值：登陆人id:咨询id
		data :params,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		"success":function(response){
			console.log(response);
			if(response["data"]["data"] == null || response["data"]["data"] == undefined || response["data"]["data"] == ""){
				$.MsgBox.Alert('提示',"没有收到回复");
				return false;
			}
			else{
				//拿到收到回复数据
				var replyStr;
				var allData = response.data;
				var myData = allData.data;
				$("#workContainer2 .workselectitem").remove();	
				if(myData.length != 0 &&  myData.length != null){
					replyStr = handleData(myData,"consultId","lookBtn");
					console.log(replyStr);
					$("#workContainer2").prepend(replyStr);
					
//					$("#workContainer2 .workselectitem").find(".lookBtn").bind("click",clickLookBtn);
					
					if(isbind == true){
						$(".getReplyPage").createPage({
					        pageCount:Math.ceil(allData.total/pageSize),
					        current:allData.pageNo,
					        backFn:function(p){
					        	getMyData(url,pageSize,p,false,status,timeType,sortType);
					        }
					    });
					}
					
				}else{
					return false;
				}	
			}
			
		},
		"error":function(response){
			//收到回复错误返回
			$.MsgBox.Alert('提示',"收到回复数据请求失败");
		},
    	
    });
};

var getConsultData = function (url,pageSize,pageNo,isbind,status,timeType,sortType){
	var params = {
		    "professorId":userid, //专家ID
		    "status":status, //查询状态 0-全部，1-进行中，2-未感谢，3-未评价，4-已完成， 可以不传，默认为0
		    "timeType":timeType, //排序类型 0-按发起时间，1-按最后回复时间，2-按完成时间 默认为0
		    "sortType":sortType, //排序类型 0-倒序，1-正序 默认为0
		    "pageSize":pageSize, //每页记录数 默认为5
		    "pageNo":pageNo //当前页码 默认为1
		};
	console.log(params);
	$.ajax({
    	url:url,//收到回复接口,//收到回复接口
		type:"get",
		//传值：登陆人id:咨询id
		data :params,
		async:false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		success:function(response){
			console.log(response);
			//拿到收到回复数据
//			if(response["data"]["data"] == null || response["data"]["data"] == undefined || response["data"]["data"] == ""){
//				$.MsgBox.Alert('提示',"没有此项数据");
//				return false;
//			}
//			else{
				var consultStr;
				var allData = response.data;
				var myData = allData["data"];
				$("#workContainer .workselectitem").remove();	
				if(myData.length != 0 &&  myData.length != null){
					consultStr = handleData(myData,"professorId","lookBtn");
					/*console.log(consultStr);*/
					$("#workContainer").prepend(consultStr);
					
//					$("#workContainer .workselectitem").find(".lookBtn").bind("click",clickLookBtn);
					
					if(isbind == true){
						$(".getConsultPage").createPage({
					        pageCount:Math.ceil(allData.total/pageSize),
					        current:allData.pageNo,
					        backFn:function(p){
					        	getConsultData(url,pageSize,p,false,status,timeType,sortType);
					        }
					    });
					}
					
				}else{
					return false;
				}	
//			}
			
		},
		error:function(response){
			//收到回复错误返回
			$.MsgBox.Alert('提示',"收到咨询数据请求失败");
		},
    	
    });
};


//咨询和回复中点击查看或者回复
function clickLookBtn2(sendId,attrParams,consultId,consultStatus,assessStatus,thanksStatus){
	alert(consultId);
	//收到咨询 
	if(attrParams == "professorId"){
		//调取页面
		$.ajax({
			url:"diloags.html",
			dataType:"html",
			success:function(result){
				//console.log(data);
				$(this).attr("id");
				$(".workcon").html(result);

				dialogHeadFn2("/ajax/consult/qapro",consultId);
				dialogContentDataHandle2(consultId);
				$("#dialog_sendBtn").click(function(){sendDialogContentFn2(sendId,consultId)});
			},
			error:function(error){
				//console.log(data);
				//加载对话页面失败
				console.log(error);
			}
		})

	}

	//收到回复
	if(attrParams == "consultId"){alert("收到回复")
		//进行中
		if(consultStatus == 0){
			//调取页面
			$.ajax({
				url:"diloags.html",
				dataType:"html",
				success:function(result){
					//console.log(data);
					$(this).attr("id");
					$(".workcon").html(result);
	
					dialogHeadFn2("/ajax/consult/qacon",consultId);
					dialogContentDataHandle2(consultId);
					$("#dialog_sendBtn").click(function(){sendDialogContentFn2(sendId,consultId)});
				},
				error:function(error){
					//console.log(data);
					//加载对话页面失败
					console.log(error);
				}
			})


		}
		//完成
		else {
			//未评价
			if(assessStatus == 0){
				assessFn2(thanksStatus);
			}
			else{
				//调取页面
				$.ajax({
					url:"diloags.html",
					dataType:"html",
					success:function(result){
						//console.log(data);
						$(this).attr("id");
						$(".workcon").html(result);
		
						dialogHeadFn2("/ajax/consult/qacon",consultId);
						dialogContentDataHandle2(consultId);
						$("#dialog_sendBtn").click(function(){sendDialogContentFn2(sendId,consultId)});
					},
					error:function(error){
						//console.log(data);
						//加载对话页面失败
						console.log(error);
					}
				})
			}
		}
	}

};

function dialogHeadFn2(url,consultId){
	//星星评价
	var starStart;
	function clickStar(){
		$(".evastar2").removeClass('addStar');
		starStart=$(this).index()+1;
		for(var i=0;i<starStart;i++){
			if(i<starStart){
				$(".evastar2").eq(i).addClass("addStar");
			}
			else{
				$(".evastar2").eq(i).removeClass('addStar');
			}
		}
		$("#startCount").val($(".addStar").length);
	};
	$.ajax({
		url:url,//
		data:{"consultId":consultId},
		type:"get",
		aysnc:false,
		success:function(response){
			var myData = response["data"];
			console.log(myData);
			//咨询进行中
			if(myData["consultStatus"] == 0){alert("jinxing");
				$("#dil_consultStatus").text("进行中");//咨询状态
				$(".dialogfoot").css("display","block");//显示发送对话部分
				$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
				$("#dialog_consultType").text(myData["consultType"]);//咨询类型
				$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话

			}
			//咨询已完成
			else {alert("wanc")
				$("#dil_consultStatus").text("完成");//咨询状态
				$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
				$("#dialog_consultType").text(myData["consultType"]);//咨询类型
				$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话
				//如果评价
				if(myData["assessStatus"] == 1){
					var starCount = myData["assessStar"];
					for(var i=0;i<starCount;i++){
						$("#showAllAssess .evastar2").eq(i).addClass("addStar");
					}
					$("#showAllAssess").css("display","block");//总体评价

					//如果感谢
					if(myData["thanksStatus"] == 1){
						$("#dialog_thanksMoney").text(myData["thanksMoney"]);
						$("#dialog_thanks").css("display","block");//感谢
					}
				}

			}

			//回复
			//回复进行中
			if (myData["consultStatus"] == 0) {
				$("#dil_consultStatus").text(myData["consultStatus"]);//咨询状态
				$(".dialogfoot").css("display","block");//显示发送对话部分
				$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
				$("#dialog_consultType").text(myData["consultType"]);//咨询类型
				$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话

				$("#dial_confirmFinishConsult").css("display","block");//确认完成按钮显示

			}
			//回复完成
			else {
				$("#dil_consultStatus").text(myData["consultStatus"]);//咨询状态
				$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
				$("#dialog_consultType").text(myData["consultType"]);//咨询类型
				$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话
			}


		},
		error:function (error) {
			//对话标题信息
		}
	})

}


	//============对话内容数据处理函数
function dialogContentDataHandle2(consultId){
	$.ajax({
		"url":"/ajax/tidings/qacon",//对话内容显示接口
		"type":"get",
		"data":{"consultId":consultId},
		"success":function(response){
			console.log(response)
			var dialogConData = response["data"];
			var dialogStr;
			dialogStr = dialogContentStrFn(dialogConData);
			$("#dialogContent").prepend(dialogStr);
		},
		error:function(error){
			
		}
	});

};

//发送按钮处理函数
function sendDialogContentFn2(sendId,consultId){
	var tidingsContant = $("#dialog_sendContent").val();
	alert("tidingsContant"+tidingsContant);
	//console.log(tidingStr);
	$.ajax({
		"url":"/ajax/tidings",
		"type":"post",
		"data":{"tidingsContant":tidingsContant,"senderId":sendId,"consultId":consultId},
		"success":function(response){
			console.log(response);//返回对话内容的id
			$("#dialogContent").empty();
			dialogContentDataHandle2(consultId);
		},
		"error":function(error){
			//对话发送消息失败
			console.log(error);
		}
	});
	$("#dialog_sendContent").val("");
};

//评价
function assessFn2(thanksStatus){
	ConsultComment();

	if(thanksStatus == 0){
		$(".addcomment2").css("display","none");//

	}else{

		$(".overcomment").css("display","none");
	}
	//评价星星样式
	var start;
	function clickStar(){
		$(".evastar2").removeClass('addStar');
		start=$(this).index()+1;
		for(var i=0;i<start;i++){
			if(i<start){
				$(".evastar2").eq(i).addClass("addStar");
			}
			else{
				$(".evastar2").eq(i).removeClass('addStar');
			}
		}
		$("#startCount").val($(".addStar").length);
	};
	$(".evastar2").bind("click",clickStar);
	//发表评论
	$("#sendAssessBtn").bind("click",clickSendAssessBtn2(consultId));

};

//发送评价
//点击发表评论：保存发表内容和星级
function clickSendAssessBtn2(consultId){
	var assessStar = $("#startCount").val();
	var assessContant = $(".resouinforcon").find("textarea").val();

	var assessContentStr ={
			"consultId":consultId, //咨询ID
		    "assessStatus":"1", //评价状态 0-未评价，1-已评价
		    "assessStar":assessStar, //评价星级
		    "assessContant":assessContant //评价内容
	};

	if(assessStar == "" || assessStar == null || assessStar == undefined){
		if(assessContant == "" || assessContant == null || assessContant == undefined){
			$.MsgBox.Alert('提示',"未评论，是否退出评论");
		}
		$.MsgBox.Alert('提示',"未选择星级");
	};
	//保存
	$.ajax({
		"url":"/ajax/consult/assess",//点击发表评论接口
		"type":"post",
		"data":assessContentStr,
		"success":function(response){
			$(".blackcover").remove();
			$("body").css("position","static");
			$.MsgBox.Alert('提示',"评论成功");
			
		},
		"error":function(error){
			//发表评论失败
			console.log(error);
		}

	});
	//发表评价后进入对话页
	$.ajax({
		"url":"diloags.html",
		"dataType":"html",
		"success":function(result){
			//console.log(data);
			$(this).attr("id");
			$(".workcon").html(result);

			dialogHeadFn2(url,consultId);
			dialogContentDataHandle2(url,consultId);
			$("#dialog_sendBtn").bind("click",sendDialogContentFn2(url,sendId,consultId));


		},
		"error":function(error){
			//console.log(data);
			//加载对话页面失败
			console.log(error);
		}
	});

};












function clickLookBtn(){
//	var consultId     = $.trim($(this).attr("id"));//咨询id
//	var assessStatus  = $.trim($(this).attr("assess"));//评价状态 0-未评价，1-已评价
	//var consultStatus = $(this).find(".coultState").text();//咨询状态 0-进行中，1-已完成
	//var thanksStatus  = $(this).find(".thanksStatus").text();//感谢状态 0-未感谢，1-已感谢
	//var assessStar    = $(this).find(".assessStar").val();//星级,几颗星 用隐藏域做
//	localStorage.setItem("consultId", consultId);
//	alert(assessStatus);
	alert($.trim($(this).attr("consultStatus")));
	
	var consultIdParams = {"consultId":$.trim($(this).attr("id"))};//咨询id
	var clickConfirmFinishParams = {
			"consultId":$.trim($(this).attr("id")),//咨询id
			"consultStatus":$(this).find(".coultState").text()//咨询状态 0-进行中，1-已完成
	};
	console.log($.trim($(this).attr("assess")));
	
	if($.trim($(this).attr("assess")) == "未评价/" && $.trim($(this).attr("consultStatus")) == "完成/" && $(this).attr("attrP") == "consultId"){
		assessFn();
		//点击稍后评价
		$("#noAssessBtn").bind("click",noAssess);
		
		//ajax加载对话页面
		
	}else{
		$(".dialogfoot").css("display","none");
		$.ajax({
			"url":"diloags.html",
			"dataType":"html",
			"success":function(result){
				//console.log(data);
				$(this).attr("id");
				$(".workcon").html(result);
				
				lookDialogHeadDataHandleFn();
				dialogContentDataHandle();
				$("#dialog_sendBtn").bind("click",sendDialogContentFn);	
			},
			"error":function(error){
				//console.log(data);
				//加载对话页面失败
				console.log(error);
			}
		});
		
	}
	
			//===========================================dialog数据==================
			//=========对话头部
			//对话头部数据渲染
			function lookDialogHeadDataHandleFn(){
				//星星评级
				var starStart;
				function clickStar(){
					$(".evastar2").removeClass('addStar');
					starStart=$(this).index()+1;
					for(var i=0;i<starStart;i++){
						if(i<starStart){
							$(".evastar2").eq(i).addClass("addStar");
						}
						else{
							$(".evastar2").eq(i).removeClass('addStar');
						}
					}
					$("#startCount").val($(".addStar").length);
				};

				$.ajax({
					"url":"/ajax/consult/qacon",//从收到回复点击查看接口
					"type":"get",
					"data":consultIdParams,
					"success":function(response){
//						console.log("点击查看返回数据");
//						console.log(response)
						var consultantData = response["data"];
						//对话框标题信息
						//进行中，
						if(consultantData["consultStatus"] == 0){
							consultantData["consultStatus"] = "进行中";
							$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
							$("#dial_confirmFinishConsult").css("display","block");//确认完成按钮显示
							$("#showAllAssess").css("display","none");//总体评价
							$(".dialogfoot").css("display","block");//显示发送对话部分
							$("#dialog_thanks").css("display","none");//隐藏感谢
							$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
							
							$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
							$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
							
						}
						//已完成
						if(consultantData["consultStatus"] == 1 || consultantData["consultStatus"] == 2 ||consultantData["consultStatus"] == 3 || consultantData["consultStatus"] == 4){
							consultantData["consultStatus"] = "已完成";
							$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
							//已完成，未感谢:
							if(consultantData["thanksStatus"] == 0){
								$("#dialog_thanksBtn").css("display","block");//显示感谢按钮
								//未感谢，未评价
								if(consultantData["assessStatus"] == 0){
									$("#dialog_assessBtn").css("display","block");//显示评价按钮
									
									$("#showAllAssess").css("display","none");//隐藏总体评价
									$("#dialog_thanks").css("display","none");//隐藏感谢
									$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
									$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
									$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
								}
								//未感谢，已评价
								else{
									
//									$("#dialog_thanksBtn").css("display","block");//显示感谢按钮
									
									var starCount = consultantData["assessStar"];
									for(var i=0;i<starCount;i++){
										$("#showAllAssess .evastar2").eq(i).addClass("addStar");
									}
									$("#showAllAssess").css("display","block");//显示星级
									$("#dialog_thanks").css("display","none");//隐藏感谢
									$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
									$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
									$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
								}
								
							}
							//已完成，已感谢：评价星级，感谢金额
							if(consultantData["thanksStatus"] == 1){
								$(".dialogfoot").css("display","none");//隐藏发送对话部分
								var starCount = consultantData["assessStar"];
								for(var i=0;i<starCount;i++){
									$("#showAllAssess .evastar2").eq(i).addClass("addStar");
								};
								$("#showAllAssess").css("display","block");//显示星级
								$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
								
								$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
								$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
								$("#dialog_thanksMoney").text(consultantData["thanksMoney"]);
							}
							
						}
					
					},
					"error":function(error){
					//对话框头部信息请求失败
					}
				});
				
			};
		
			
			
			//============对话内容数据处理函数
			function dialogContentDataHandle(){
				$.ajax({
					"url":"/ajax/tidings/qacon",//对话内容显示接口
					"type":"get",
					"data":consultIdParams,
					"beforeSend":function(response){
						//对话发送消息失败
						//console.log(response);
					},
					"success":function(response){
						console.log()
						var dialogConData = response["data"];
//						console.log(dialogConData);
						var dialogStr;
						dialogStr = dialogContentStrFn(dialogConData);
						$("#dialogContent").prepend(dialogStr);
//						
					},
					"error":function(error){
						//对话框内容信息请求失败
					}
				});
				
				
			};
			
			
			//=============================对话页面底部发送
			//发送按钮处理函数
			function sendDialogContentFn(){
				var tidingsContant = $("#dialog_sendContent").val();
				var tidingStr = {
					"tidingsContant":tidingsContant,
					"senderId":userid,
					"consultId":consultId
				};
				//console.log(tidingStr);
				$.ajax({
					"url":"/ajax/tidings",
					"type":"post",
					"data":tidingStr,
					"beforeSend":function(response){
						//对话发送消息失败
						console.log(response);
					},
					"success":function(response){
						console.log(response);//返回对话内容的id
						$("#dialogContent").empty();
						dialogContentDataHandle();
					},
					"error":function(error){
						//对话发送消息失败
						console.log(error);
					}
				});
				$("#dialog_sendContent").val("");
			};
			
			
			
			//==============发表评价页
			function assessFn(){
				ConsultComment();
				
				if($.trim($(this).attr("thanks")) == "未感谢"){
					$(".addcomment2").css("display","none");//
					
				}else{
					
					$(".overcomment").css("display","none");
				}
				//评价星星样式
				var start;
				function clickStar(){
					$(".evastar2").removeClass('addStar');
					start=$(this).index()+1;
					for(var i=0;i<start;i++){
						if(i<start){
							$(".evastar2").eq(i).addClass("addStar");
						}
						else{
							$(".evastar2").eq(i).removeClass('addStar');
						}
					}
					$("#startCount").val($(".addStar").length);
				};
				$(".evastar2").bind("click",clickStar);
				//发表评论
				$("#sendAssessBtn").bind("click",clickSendAssessBtn);
				
			};
			
			//绑定对话页面确认完成咨询
			$("#dial_confirmFinishConsult").bind("click",assessFn);
			$("#dialog_assessBtn").bind("click",assessFn);
			
			
			//点击发表评论：保存发表内容和星级
			function clickSendAssessBtn(){
				var consultId = localStorage.getItem("consultId");//
				var assessStar = $("#startCount").val();
				var assessContant = $(".resouinforcon").find("textarea").val();
				//评价状态 0-未评价，1-已评价
				
				//确认完成后，发表评论传值
				var assessContentStr ={
						"consultId":consultId, //咨询ID
					    "assessStatus":"1", //评价状态 0-未评价，1-已评价
					    "assessStar":assessStar, //评价星级
					    "assessContant":assessContant //评价内容
				};
				
//				console.log(assessContentStr);
				//如果未评论，提示未评论
				if(assessStar == "" || assessStar == null || assessStar == undefined){
					if(assessContant == "" || assessContant == null || assessContant == undefined){
						$.MsgBox.Alert('提示',"未评论，是否退出评论");
					}
					$.MsgBox.Alert('提示',"未选择星级");
				};
				//保存
				$.ajax({
					"url":"/ajax/consult/assess",//点击发表评论接口
					"type":"post",
					"data":assessContentStr,
					"success":function(response){
//						console.log(response);
						$(".blackcover").remove();
						$("body").css("position","static");
						$.MsgBox.Alert('提示',"评论成功");
						//评价状态改变，所以头部信息改变
						lookDialogHeadDataHandleFn();
					},
					"error":function(error){
						//发表评论失败
						console.log(error);
					}
					
				});
				//发表评论
				$.ajax({
					"url":"diloags.html",
					"dataType":"html",
					"success":function(result){
						//console.log(data);
						$(this).attr("id");
						$(".workcon").html(result);
						
						$(".blackcover").remove();
						$("body").css("position","static");
						lookDialogHeadDataHandleFn();
						dialogContentDataHandle();
						$("#dialog_sendBtn").bind("click",sendDialogContentFn);
						
						
					},
					"error":function(error){
						//console.log(data);
						//加载对话页面失败
						console.log(error);
					}
				});
				
				
				
			};
			
			
			//稍后评价、
			function noAssess(){
				$.ajax({
					"url":"diloags.html",
					"dataType":"html",
					"success":function(result){
						//console.log(data);
						$(this).attr("id");
						$(".workcon").html(result);
						$(".blackcover").remove();
						$("body").css("position","static");
						lookDialogHeadDataHandleFn();
						dialogContentDataHandle();
						$("#dialog_sendBtn").bind("click",sendDialogContentFn);

					},
					"error":function(error){
						//加载对话页面失败
						$.MsgBox.Alert('提醒',"对话请求错误");
					}
				});
			};

	
};//收到回复点击查看函数结束






function clickConsultBtn(){
	if(userid != "" && userid != null){
		$.ajax({
			"url":"/ajax/consult/pqpro",//判断是否有无咨询
			"type" : "get",
			"async":false,
			"data" :{"professorId":userid},
			"contentType" : "application/x-www-form-urlencoded",
			"success":function(consultResponse){
//				console.log(consultResponse);
				if(consultResponse["data"]["data"] == null || consultResponse["data"]["data"] == undefined || consultResponse["data"]["data"] == ""){
					$.MsgBox.Alert('提醒',"您目前没有咨询信息");
					return false;
				}
				else {
					//如果没有咨询数据 隐藏收到咨询
					if(consultResponse["data"]["total"] == 0){
				        $.ajax({
				        	"url":"consult.html",
							"dataType" : "html",
							"success":function(responseHtml){
								$(".workcon").html(responseHtml);
								$(".worksamlltit3:first").hide();
						        $(".workmysrc3:first").hide();
						        $(".workmysrc3:last").fadeIn();
						       
						        //=无咨询  ajax请求收到回复=
						      //收到回复
						        getMyData("/ajax/consult/pqcon","5",1,true,0,0,0);
						      //点击下拉菜单
						        $(".replyOption ul").find("li").click(function(){
						        	getMyData("/ajax/consult/pqcon","5",1,true,$(this).attr("tip"),$("#showTimeSort2").attr("tim"),$("#timeSortId2").val());
						        	});
								$(".timeOption2 ul").find("li").click(function(){
									getMyData("/ajax/consult/pqcon","5",1,true,$("#showStatus2").attr("tip"),$(this).attr("tim"),$("#timeSortId2").val());
									});
								var sortFlag = true;
								$("#replyArrow").click(function(){
									
									if(sortFlag == true){
							      		$(this).find("div").css("background-position","-20px 1px");	
							      		$("#timeSortId2").val("1");
							      		sortFlag = false;
							      	}else{
							      		$(this).find("div").css("background-position","0px 1px");	
							      		$("#timeSortId2").val("0");
							      		sortFlag=true;
							      	}
									getMyData("/ajax/consult/pqcon","5",1,true,$("#showStatus2").attr("tip"),$("#showTimeSort2").attr("tim"),$("#timeSortId2").val());
								});	
							},
							"error":function(response){
								//请求页面失败
	//							console.log(response)
							},
									
				        })
	
						
					}else{
					//ajax页面
					 $.ajax({
				        	"url":"consult.html",
							"dataType" : "html",
							"success":function(responseHtml){
								$(".workcon").html(responseHtml);
						        
						        //ajax 收到咨询数据和收到回复数据
						        //ajax收到咨询   consultResponse 收到咨询返回值
								/*var consultTrHtml;
						        var allData = consultResponse.data;
								var consultData = allData["data"];
						        consultTrHtml = handleData(consultData,consultTrHtml,"professorId","replyBtn");
						        $("#workContainer").prepend(consultTrHtml);*/
								
								//收到咨询
								getConsultData("/ajax/consult/pqpro","5",1,true,0,0,0);
								//点击下拉菜单
						        $(".consultOption ul").find("li").click(function(){
						        	getConsultData("/ajax/consult/pqpro","5",1,true,$(this).attr("tip"),$("#showTimeSort").attr("tim"),$("#timeSortId").val());
						        	});
								$(".timeOption2 ul").find("li").click(function(){
									getConsultData("/ajax/consult/pqpro","5",1,true,$("#showStatus").attr("tip"),$(this).attr("tim"),$("#timeSortId").val());
									});
								var sortFlag = true;
								$("#replyArrow").click(function(){
									
									if(sortFlag == true){
							      		$(this).find("div").css("background-position","-20px 1px");	
							      		$("#timeSortId2").val("1");
							      		sortFlag = false;
							      	}else{
							      		$(this).find("div").css("background-position","0px 1px");	
							      		$("#timeSortId2").val("0");
							      		sortFlag=true;
							      	}
									getConsultData("/ajax/consult/pqpro","5",1,true,$("#showStatus").attr("tip"),$("#showTimeSort").attr("tim"),$("#timeSortId").val());
								});
								
								//
						        getMyData("/ajax/consult/pqcon","5",1,true,0,0,0);
						        //点击下拉菜单
						        $(".replyOption ul").find("li").click(function(){
						        	console.log($("#showTimeSort2"));
						        	getMyData("/ajax/consult/pqcon","5",1,true,$(this).attr("tip"),$("#showTimeSort2").attr("tim"),$("#timeSortId2").val());
						        	});
								$(".timeOption2 ul").find("li").click(function(){
									getMyData("/ajax/consult/pqcon","5",1,true,$("#showStatus2").attr("tip"),$(this).attr("tim"),$("#timeSortId2").val());
									});
								$("#replyArrow").click(function(){
									var sortFlag = true;
									if(sortFlag == true){
							      		$(this).find("div").css("background-position","-20px 1px");	
							      		$("#timeSortId2").val("1");
							      		sortFlag =false;
							      		
							      	}else{
							      		$(this).find("div").css("background-position","0px 1px");	
							      		$("#timeSortId2").val("0");
							      		
							      		sortFlag=true;
							      	}
									getMyData("/ajax/consult/pqcon","5",1,true,$("#showStatus2").attr("tip"),$("#showTimeSort2").attr("tim"),$("#timeSortId2").val());
								});
								
	
						        
						        
						        //================================================有咨询时，下拉菜单改===变 ajax==========================
								// 排列顺序（正序、倒序）	
							    /*var sortFlag = true;//正倒排序标记
								$(".orderedbtn").click(function(){
									if(sortFlag == true){
										$(this).find("div").css("background-position","-20px 1px");	
										$("#timeSortId").val("1");
										
										sortFlag =false;
										
									}else{
										$(this).find("div").css("background-position","0px 1px");	
										$("#timeSortId").val("0");
										
										sortFlag=true;
									}
									
								});
								
								var timeType,sortType,consultStatus,consultId;
								
								consultStatus = $("#consultSelectId").val();//咨询状态值
								timeType = $("#timeTypeId").val();//时间类型值
								sortType = $("#timeSortId").val();//排序值;
								
								//默认传值：
								var consultInfo = {
										"professorId":userid,
										"status":consultStatus,
										"timeType":timeType,
										"sortType":sortType
								};
	//							console.log("默认值："+consultInfo.status + consultInfo.timeType + consultInfo.sortType +  consultInfo.professorId);
								
								//收到咨询信息改变下拉菜单
								function consultStatusFn(){
									//改变后，要传的值
									consultStatus = $("#consultSelectId").val();//咨询状态值
									timeType = $("#timeTypeId").val();//时间类型值
									sortType = $("#timeSortId").val();//排序值;
									
									//要传的值：
									consultInfo = {
											"professorId":userid,
											"status":consultStatus,
											"timeType":timeType,
											"sortType":sortType
											
									};
									
	//								console.log("ajax中的值:"+ consultInfo.status + consultInfo.timeType + consultInfo.sortType +  consultInfo.consultantId);
									
									//更新下拉菜单
									$.ajax({
										"url":"/ajax/consult/pqpro",//更新下拉菜单接口
							        	"data":consultInfo,
							        	"type":"get",
										"success":function(response){
											$("#workContainer .workselectitem").remove();
	//										$(".tcdPageCode:first").before().empty();
											var allData = response.data;
											var consultData = allData["data"];
											consultTrHtml = handleData(consultData,consultTrHtml,"professorId","replyBtn");
											$("#workContainer").prepend(consultTrHtml);
											
											//给咨询回复绑定回复和查看事件
											$("#workContainer .workselectitem").find(".replyBtn").bind("click",clickReplyFn);
											
										},
										"error":function(response){
	//										console.log(response)
											//更新下拉菜单失败
										}
										
									});
									
																
								};//更新咨询下拉菜单处理函数结束
	
								//绑定咨询状态事件
								$(".consultOption ul").bind("click", "li",consultStatusFn);
								
								//绑定咨询状态事件
								$(".timeOption ul").bind("click", "li",consultStatusFn);
								
								$(".orderedbtn").bind("click",consultStatusFn);*/
								
								
								
								//============================================点击咨询页面中回复按钮=====================
						        function clickReplyFn(){
									var consultId     = $.trim($(this).attr("id"));//咨询id
									var assessStatus  = $.trim($(this).find(".assessStatus").text());//评价状态 0-未评价，1-已评价
									var consultStatus = $.trim($(this).find(".coultState").text());//咨询状态 0-进行中，1-已完成
									var thanksStatus  = $.trim($(this).find(".thanksStatus").text());//感谢状态 0-未感谢，1-已感谢
									var assessStar    = $.trim($(this).find(".assessStar").val());//星级,几颗星 用隐藏域做
									
	
									//ajax加载对话页面
									$.ajax({
										"url":"diloags.html",
										"dataType":"html",
										"success":function(result){
											//console.log(data);
											$(this).attr("id");
											$(".workcon").html(result);
											
											//===========================================dialog数据==================
											//=========对话头部
											//对话头部数据渲染
											function dialogHeadDataHandleFn(){
												//星星评级
												var starStart;
												function clickStar(){
													$(".evastar2").removeClass('addStar');
													starStart=$(this).index()+1;
													for(var i=0;i<starStart;i++){
														if(i<starStart){
															$(".evastar2").eq(i).addClass("addStar");
														}
														else{
															$(".evastar2").eq(i).removeClass('addStar');
														}
													}
													$("#startCount").val($(".addStar").length);
												};
	
												$.ajax({
													"url":"/ajax/consult/qapro",//从收到咨询点击回复接口
													"type":"get",
													"data":consultIdStr,
													"success":function(response){
														var consultantData = response["data"];
														//对话框标题信息
														//进行中，
														if(consultantData["consultStatus"] == 0){
															consultantData["consultStatus"] = "进行中";
															$("#dial_confirmFinishConsult").css("display","none");//确认完成按钮显示
															$("#dialog_thanksBtn").css("display","none");
															$("#dialog_assessBtn").css("display","none");
															$("#showAllAssess").css("display","none");//总体评价
															$(".dialogfoot").css("display","block");//显示发送对话部分
															$("#dialog_thanks").css("display","none");//隐藏感谢
															$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
															$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
															$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
															$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
															
														}
														//已完成
														if(consultantData["consultStatus"] == 1 || consultantData["consultStatus"] == 2 ||consultantData["consultStatus"] == 3 || consultantData["consultStatus"] == 4){
															consultantData["consultStatus"] = "已完成";
															$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
															//已完成，未感谢:
															if(consultantData["thanksStatus"] == 0){
																//未感谢，未评价
																if(consultantData["assessStatus"] == 0){
																	$("#dial_confirmFinishConsult").css("display","none");//隐藏确认完成按钮
																	$("#dialog_thanksBtn").css("display","none");
																	$("#dialog_assessBtn").css("display","none");
																	$("#showAllAssess").css("display","none");//隐藏评价
																	$("#dialog_thanks").css("display","none");//隐藏感谢
																	$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																	$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																	$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																}
																//未感谢，已评价
																else{
																	
																	$("#dial_confirmFinishConsult").css("display","none");//隐藏确认完成按钮
																	$("#dialog_thanksBtn").css("display","none");
																	$("#dialog_assessBtn").css("display","none");
																	$("#showAllAssess").css("display","block");
																	var starCount = consultantData["assessStar"];
																	for(var i=0;i<starCount;i++){
																		$("#showAllAssess .evastar2").eq(i).addClass("addStar");
																	}
																	$("#showAllAssess").css("display","block");//显示星级
																	$("#dialog_thanks").css("display","none");//隐藏感谢
																	$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																	$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																	$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																}
																
															}
															//已完成，已感谢：评价星级，感谢金额
															if(consultantData["thanksStatus"] == 1){
																$("#dial_confirmFinishConsult").css("display","none");//隐藏确认完成按钮
																$("#dialog_thanksBtn").css("display","none");
																$("#dialog_assessBtn").css("display","none");
																$(".dialogfoot").css("display","none");//隐藏发送对话部分
																$("#showAllAssess").css("display","block");
																var starCount = consultantData["assessStar"];
																for(var i=0;i<starCount;i++){
																	$("#showAllAssess .evastar2").eq(i).addClass("addStar");
																};
																$("#dialog_thanks").css("display","block");//显示感谢
																$("#showAllAssess").css("display","block");//显示星级
																$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
																$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
															}
															
														}
													
													},
													"error":function(error){
													//对话框头部信息请求失败
													}
												});
												
											};
										
											dialogHeadDataHandleFn();
											
											//============对话内容数据处理函数
											function dialogContentDataHandle(){
												$.ajax({
													"url":"/ajax/tidings/qacon",//对话内容显示接口
													"type":"get",
													"data":consultIdStr,
													"success":function(response){
														var dialogConData = response["data"];
														var dialogStr;
														dialogStr = dialogContentStrFn(dialogConData);
														$("#dialogContent").prepend(dialogStr);
	//													
													},
													"error":function(error){
														//对话框内容信息请求失败
													}
												});
												
												
											};
											dialogContentDataHandle();
											
											//=============================对话页面底部发送
											//发送按钮处理函数
											function sendDialogContentFn(){
												var tidingsContant = $("#dialog_sendContent").val();
												var tidingStr = {
													"tidingsContant":tidingsContant,
													"senderId":userid,
													"consultId":consultId
												};
												//console.log(tidingStr);
												$.ajax({
													"url":"/ajax/tidings",
													"type":"post",
													"data":tidingStr,
													"success":function(response){
														$("#dialogContent").empty();
														dialogContentDataHandle();
													},
													"error":function(error){
														//对话发送消息失败
														console.log(error);
													}
												});
												$("#dialog_sendContent").val("");
											};
											$("#dialog_sendBtn").bind("click",sendDialogContentFn);
											
											
											//==============发表评价
											function assessFn(){
												ConsultComment();
												if($(this).attr("id") == "dialog_thanksBtn"){
													$(".overcomment").css("display","block");//显示感谢
												}
												if($(this).attr("id") == "dialog_assessBtn"){
	//												$(".addcomment2").css("display","block");//显示评价
													$("#showAllAssess").css("display","block");
												}
												//评价星星样式
												var start;
												function clickStar(){
													$(".evastar2").removeClass('addStar');
													start=$(this).index()+1;
													for(var i=0;i<start;i++){
														if(i<start){
															$(".evastar2").eq(i).addClass("addStar");
														}
														else{
															$(".evastar2").eq(i).removeClass('addStar');
														}
													}
													$("#startCount").val($(".addStar").length);
												};
												$(".evastar2").bind("click",clickStar);
												//发表评论
												$("#sendAssessBtn").bind("click",clickSendAssessBtn);
												
											};
											/*//绑定对话页面确认完成咨询
											$("#dial_confirmFinishConsult").bind("click",assessFn);*/
											
											
											//点击发表评论：保存发表内容和星级
											function clickSendAssessBtn(){
												var assessStar = $("#startCount").val();
												var assessContant = $(".resouinforcon").find("textarea").val();
												//评价状态 0-未评价，1-已评价
												
												//确认完成后，发表评论传值
												var assessContentStr ={
														"consultId":consultId, //咨询ID
													    "assessStatus":"1", //评价状态 0-未评价，1-已评价
													    "assessStar":assessStar, //评价星级
													    "assessContant":assessContant //评价内容
												};
	//											console.log(assessContentStr);
												//如果未评论，提示未评论
												if(assessStar == "" || assessStar == null || assessStar == undefined){
													if(assessContant == "" || assessContant == null || assessContant == undefined){
														$.MsgBox.Alert('提示',"未评论，是否退出评论");
													}
													$.MsgBox.Alert('提示',"未选择星级");
												};
												$.ajax({
													"url":"/ajax/consult/assess",//点击发表评论接口
													"type":"post",
													"data":assessContentStr,
													"success":function(response){
	//													console.log(response);
														$(".blackcover").remove();
														$("body").css("position","static");
														$.MsgBox.Alert('提示',"评论成功");
														
														//评价状态改变，所以头部信息改变
														dialogHeadDataHandleFn();
														//点击确认完成
														//绑定对话页面确认完成咨询
														$("#dial_confirmFinishConsult").bind("click",assessFn);
													},
													"error":function(error){
														//发表评论失败
														console.log(error);
													}
													
												});
											};
										
	
										
										},
										"error":function(error){
											//console.log(data);
											//加载对话页面失败
											console.log(error);
										}
									})
									
									
								};
								//给咨询页回复绑定事件
								$("#workContainer .workselectitem").find(".replyBtn").bind("click",clickReplyFn);
	
								
								//收到咨询和收到回复切换
	//							$(".worksamlltit3:first").addClass("active").show();
	//					        $(".workmysrc3:first").show(); 
						          
						        //On Click Event 收到咨询和收到回复tab效果 
						        $(".worksamlltit3").bind("click",tab);
						        function tab(){
						        	$(".worksamlltit3").removeClass("worksamlltitnow");
						            $(this).addClass("worksamlltitnow");
						            $(".workmysrc3").hide();
						            var activeTab = $(this).attr("href");
						            $(activeTab).fadeIn();
						            
						            return false;
						        };
						   
						        
							},
				        })
						
					}
				}
			},
			"error":function(response){
				//收到咨询页面失败
				$.MsgBox.Alert('提醒',"咨询页面请求错误");
			},
			
			
		});

		
	}else{
		$.MsgBox.Alert('提醒',"您尚未登录");
	}

};




/*$(document).ready(function(){
	
//	console.log(localStorage.getItem("professorId"));
	$(".workmenu").on("click","#consultbtn",function(){
		
		//1.先ajax请求，判断是否有收到咨询消息，然后ajax-html，然后渲染数据
//		console.log(professorIdStrByconsult);
		//检查用户是否登录
		if(userid != "" && userid != null){
			$.ajax({
				"url":"/ajax/consult/pqpro",//判断是否有无咨询
				"type" : "get",
				//传值：登陆人id：专家id
				"data" :{"professorId":userid},
				"contentType" : "application/x-www-form-urlencoded",
				"beforeSend":function(response){
//					console.log(response)
				},
				"success":function(consultResponse){
//					console.log(consultResponse);
					//如果没有咨询数据 隐藏收到咨询
					if(consultResponse["data"]["total"] == 0){
//						alert("未收到咨询");

				        //ajax页面
				        $.ajax({
				        	"url":"consult.html",
							"dataType" : "html",
							"success":function(responseHtml){
								$(".workcon").html(responseHtml);
								
								$(".worksamlltit3:first").hide();
						        $(".workmysrc3:first").hide();
						        $(".workmysrc3:last").fadeIn();
						        var replyTrHtml;
						        
						        var pageNo;

						        //======================================没有咨询情况下 ajax请求收到回复======================
						        $.ajax({
						        	"url":"/ajax/consult/pqcon",//收到回复接口
						        	"type":"get",
						        	"data":{"consultantId":userid},
									"dataType" : "json",
									"success":function(replyResponse){
										console.log(replyResponse)
										
										var allData = replyResponse.data;
										var replyData = allData["data"];
										
										if(replyData.length != 0 &&  replyData.length != null){
											replyTrHtml = handleData(replyData,replyTrHtml,"consultantId","lookBtn");
											$("#workContainer2").prepend(replyTrHtml);
											
										}else{
											return false;
										}
										
										
									},
									"error":function(response){
										//收到回复失败
//										console.log(response)
									},
						        	
						        });
						        
						    //==========================================只有收到回复时，下拉菜单改变 ajax开始==================
						        
						      //点击正序倒序
						       var sortFlag2 = true;
						      $("#replyArrow").click(function(){
						      	if(sortFlag2 == true){
						      		$(this).find("div").css("background-position","-20px 1px");	
						      		$("#timeSortId2").val("1");
						      		
						      		sortFlag2 =false;
						      		
						      	}else{
						      		$(this).find("div").css("background-position","0px 1px");	
						      		$("#timeSortId2").val("0");
						      		
						      		sortFlag2=true;
						      	}
						      	
						      });
						        
//						      $("#replyArrow").on("clcik",clickSortFn);

						      var timeType2,sortType2,replyStatus,consultId;
						      
						      replyStatus = $("#replySelectId").val();//回复状态值
						      timeType2 = $("#timeTypeId2").val();//时间类型值
						      sortType2 = $("#timeSortId2").val();//排序值;

						      //console.log(consultStatus,timeType,sortType+"res333");

						      //默认传值：
						      var replyInfo = {
						      		"consultantId":userid,
						      		"status":replyStatus,
						      		"timeType":timeType2,
						      		"sortType":sortType2
						      };
						      function replyStatusFn(){
									//改变后，要传的值
						    	  	replyStatus = $("#replySelectId").val();//咨询状态值
									timeType2 = $("#timeTypeId2").val();//时间类型值
									sortType2 = $("#timeSortId2").val();//排序值;								
									
									replyInfo = {
								      		"consultantId":userid,
								      		"status":replyStatus,
								      		"timeType":timeType2,
								      		"sortType":sortType2
								      };
//									console.log("ajax中的值:"+ replyInfo.replyStatus + replyInfo.timeType +  replyInfo.sortType +replyInfo.consultantId);
									
									//=====================================只有收到回复时 更新下拉菜单==============
									$.ajax({
										"url":"/ajax/consult/pqcon",//更新下拉菜单接口
										"type":"get",
							        	"data":replyInfo,
										"beforeSend":function(response){
											console.log(response);
										},
										"success":function(response){
											$("#workContainer2 .workselectitem").remove();
											var allData = response.data;
											var replyData = allData["data"];
											replyTrHtml = handleData(replyData,replyTrHtml,"consultantId","lookBtn");
											console.log(replyTrHtml);
//											$(".tcdPageCode:last").before(replyTrHtml);
											$("#workContainer2").prepend(replyTrHtml);

										},
										"error":function(response){
//											console.log(response)
											//更新下拉菜单失败
										}
										
									});																	
								};//更新下拉菜单处理函数结束
						        
								//绑定回复状态事件
								$(".replyOption ul").bind("click", "li",replyStatusFn);
								
								//绑定回复状态事件
								$(".timeOption2 ul").bind("click", "li",replyStatusFn);
								
								$("#replyArrow").bind("click",replyStatusFn);
						        
								
							},
							"error":function(response){
								//请求页面失败
//								console.log(response)
							},
									
				        })

						
					}else{
//						alert("收到咨询");
					//ajax页面
					 $.ajax({
				        	"url":"consult.html",
							"dataType" : "html",
							"success":function(responseHtml){
								$(".workcon").html(responseHtml);
						        
						        //ajax 收到咨询数据和收到回复数据
						        //ajax收到咨询   consultResponse 收到咨询返回值
								var consultTrHtml;
						        var allData = consultResponse.data;
								var consultData = allData["data"];
						        consultTrHtml = handleData(consultData,consultTrHtml,"professorId","replyBtn");
						        $("#workContainer").prepend(consultTrHtml);
						        
						        
						        //================================================有咨询时，下拉菜单改===变 ajax==========================
								// 排列顺序（正序、倒序）	
							    var sortFlag = true;//正倒排序标记
								$(".orderedbtn").click(function(){
									if(sortFlag == true){
										$(this).find("div").css("background-position","-20px 1px");	
										$("#timeSortId").val("1");
										
										sortFlag =false;
										
									}else{
										$(this).find("div").css("background-position","0px 1px");	
										$("#timeSortId").val("0");
										
										sortFlag=true;
									}
									
								});
								
								var timeType,sortType,consultStatus,consultId;
								
								consultStatus = $("#consultSelectId").val();//咨询状态值
								timeType = $("#timeTypeId").val();//时间类型值
								sortType = $("#timeSortId").val();//排序值;
//								console.log(consultStatus,timeType,sortType+"res333");
								
								//默认传值：
								var consultInfo = {
										"professorId":userid,
										"status":consultStatus,
										"timeType":timeType,
										"sortType":sortType
								};
//								console.log("默认值："+consultInfo.status + consultInfo.timeType + consultInfo.sortType +  consultInfo.professorId);
								
								//收到咨询信息改变下拉菜单
								function consultStatusFn(){
									//改变后，要传的值
									consultStatus = $("#consultSelectId").val();//咨询状态值
									timeType = $("#timeTypeId").val();//时间类型值
									sortType = $("#timeSortId").val();//排序值;
									
									//要传的值：
									consultInfo = {
											"professorId":userid,
											"status":consultStatus,
											"timeType":timeType,
											"sortType":sortType
											
									};
									
//									console.log("ajax中的值:"+ consultInfo.status + consultInfo.timeType + consultInfo.sortType +  consultInfo.consultantId);
									
									//更新下拉菜单
									$.ajax({
										"url":"/ajax/consult/pqpro",//更新下拉菜单接口
							        	"data":consultInfo,
							        	"type":"get",
										"beforeSend":function(response){
//											console.log(response);
										},
										"success":function(response){
											$("#workContainer .workselectitem").remove();
//											$(".tcdPageCode:first").before().empty();
											var allData = response.data;
											var consultData = allData["data"];
											console.log(consultData.length);
											consultTrHtml = handleData(consultData,consultTrHtml,"professorId","replyBtn");
//											$(".tcdPageCode:first").before(consultTrHtml);
											$("#workContainer").prepend(consultTrHtml);
											//给咨询页回复绑定事件
											$("#workContainer .workselectitem").find(".replyBtn").bind("click",clickReplyFn);
											
										},
										"error":function(response){
//											console.log(response)
											//更新下拉菜单失败
										}
										
									});
									
																
								};//更新咨询下拉菜单处理函数结束

								//绑定咨询状态事件
								$(".consultOption ul").bind("click", "li",consultStatusFn);
								
								//绑定咨询状态事件
								$(".timeOption ul").bind("click", "li",consultStatusFn);
								
								$(".orderedbtn").bind("click",consultStatusFn);
								
								
								
								//============================================点击咨询页面中回复按钮=====================
						        function clickReplyFn(){
									var consultId     = $.trim($(this).attr("id"));//咨询id
									var assessStatus  = $.trim($(this).find(".assessStatus").text());//评价状态 0-未评价，1-已评价
									var consultStatus = $.trim($(this).find(".coultState").text());//咨询状态 0-进行中，1-已完成
									var thanksStatus  = $.trim($(this).find(".thanksStatus").text());//感谢状态 0-未感谢，1-已感谢
									var assessStar    = $.trim($(this).find(".assessStar").val());//星级,几颗星 用隐藏域做
									
									//点击确认完成的传值:consultId,咨询状态
									var confirmFinishStr = {
										"consultId":consultId,
										"consultStatus":consultStatus
									};
									//对话标题 传值，
									var consultIdStr = {
										"consultId":consultId
									}

									//ajax加载对话页面
									$.ajax({
										"url":"diloags.html",
										"dataType":"html",
										"success":function(result){
											//console.log(data);
											$(this).attr("id");
											$(".workcon").html(result);
											
											//===========================================dialog数据==================
											//=========对话头部
											//对话头部数据渲染
											function dialogHeadDataHandleFn(){
												//星星评级
												var starStart;
												function clickStar(){
													$(".evastar2").removeClass('addStar');
													starStart=$(this).index()+1;
													for(var i=0;i<starStart;i++){
														if(i<starStart){
															$(".evastar2").eq(i).addClass("addStar");
														}
														else{
															$(".evastar2").eq(i).removeClass('addStar');
														}
													}
													$("#startCount").val($(".addStar").length);
												};

												$.ajax({
													"url":"/ajax/consult/qapro",//从收到咨询点击回复接口
													"type":"get",
													"data":consultIdStr,
													"success":function(response){
														console.log("点击回复返回数据");
														console.log(response)
														var consultantData = response["data"];
														//对话框标题信息
														//进行中，
														if(consultantData["consultStatus"] == 0){
															consultantData["consultStatus"] = "进行中";
															$("#dial_confirmFinishConsult").css("display","none");//确认完成按钮显示
															$("#dialog_thanksBtn").css("display","none");
															$("#dialog_assessBtn").css("display","none");
															$("#showAllAssess").css("display","none");//总体评价
															$(".dialogfoot").css("display","block");//显示发送对话部分
															$("#dialog_thanks").css("display","none");//隐藏感谢
															$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
															$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
															$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
															$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
															
														}
														//已完成
														if(consultantData["consultStatus"] == 1 || consultantData["consultStatus"] == 2 ||consultantData["consultStatus"] == 3 || consultantData["consultStatus"] == 4){
															consultantData["consultStatus"] = "已完成";
															$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
															//已完成，未感谢:
															if(consultantData["thanksStatus"] == 0){
																//未感谢，未评价
																if(consultantData["assessStatus"] == 0){
																	$("#dial_confirmFinishConsult").css("display","none");//隐藏确认完成按钮
																	$("#dialog_thanksBtn").css("display","none");
																	$("#dialog_assessBtn").css("display","none");
																	$("#showAllAssess").css("display","none");//隐藏评价
																	$("#dialog_thanks").css("display","none");//隐藏感谢
																	$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																	$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																	$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																}
																//未感谢，已评价
																else{
																	
																	$("#dial_confirmFinishConsult").css("display","none");//隐藏确认完成按钮
																	$("#dialog_thanksBtn").css("display","none");
																	$("#dialog_assessBtn").css("display","none");
																	$("#showAllAssess").css("display","block");
																	var starCount = consultantData["assessStar"];
																	for(var i=0;i<starCount;i++){
																		$("#showAllAssess .evastar2").eq(i).addClass("addStar");
																	}
																	$("#showAllAssess").css("display","block");//显示星级
																	$("#dialog_thanks").css("display","none");//隐藏感谢
																	$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																	$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																	$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																}
																
															}
															//已完成，已感谢：评价星级，感谢金额
															if(consultantData["thanksStatus"] == 1){
																$("#dial_confirmFinishConsult").css("display","none");//隐藏确认完成按钮
																$("#dialog_thanksBtn").css("display","none");
																$("#dialog_assessBtn").css("display","none");
																$(".dialogfoot").css("display","none");//隐藏发送对话部分
																$("#showAllAssess").css("display","block");
																var starCount = consultantData["assessStar"];
																for(var i=0;i<starCount;i++){
																	$("#showAllAssess .evastar2").eq(i).addClass("addStar");
																};
																$("#dialog_thanks").css("display","block");//显示感谢
																$("#showAllAssess").css("display","block");//显示星级
																$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
																$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
															}
															
														}
													
													},
													"error":function(error){
													//对话框头部信息请求失败
													}
												});
												
											};
										
											dialogHeadDataHandleFn();
											
											//============对话内容数据处理函数
											function dialogContentDataHandle(){
												$.ajax({
													"url":"/ajax/tidings/qacon",//对话内容显示接口
													"type":"get",
													"data":consultIdStr,
													"beforeSend":function(response){
														//对话发送消息失败
														//console.log(response);
													},
													"success":function(response){
														console.log()
														var dialogConData = response["data"];
														console.log(dialogConData);
														var dialogStr;
														dialogStr = dialogContentStrFn(dialogConData);
														$("#dialogContent").prepend(dialogStr);
//														
													},
													"error":function(error){
														//对话框内容信息请求失败
													}
												});
												
												
											};
											dialogContentDataHandle();
											
											//=============================对话页面底部发送
											//发送按钮处理函数
											function sendDialogContentFn(){
												var tidingsContant = $("#dialog_sendContent").val();
												var tidingStr = {
													"tidingsContant":tidingsContant,
													"senderId":userid,
													"consultId":consultId
												};
												//console.log(tidingStr);
												$.ajax({
													"url":"/ajax/tidings",
													"type":"post",
													"data":tidingStr,
													"beforeSend":function(response){
														//对话发送消息失败
														console.log(response);
													},
													"success":function(response){
														console.log(response);//返回对话内容的id
														$("#dialogContent").empty();
														dialogContentDataHandle();
													},
													"error":function(error){
														//对话发送消息失败
														console.log(error);
													}
												});
												$("#dialog_sendContent").val("");
											};
											$("#dialog_sendBtn").bind("click",sendDialogContentFn);
											
											
											//==============点击确认完成
											function assessFn(){
												ConsultComment();
												if($(this).attr("id") == "dialog_thanksBtn"){
													$(".overcomment").css("display","block");//显示感谢
												}
												if($(this).attr("id") == "dialog_assessBtn"){
													$(".addcomment2").css("display","block");//显示评价
												}
												//评价星星样式
												var start;
												function clickStar(){
													$(".evastar2").removeClass('addStar');
													start=$(this).index()+1;
													for(var i=0;i<start;i++){
														if(i<start){
															$(".evastar2").eq(i).addClass("addStar");
														}
														else{
															$(".evastar2").eq(i).removeClass('addStar');
														}
													}
													$("#startCount").val($(".addStar").length);
												};
												$(".evastar2").bind("click",clickStar);
												//发表评论
												$("#sendAssessBtn").bind("click",clickSendAssessBtn);
												
											};
											//绑定对话页面确认完成咨询
											$("#dial_confirmFinishConsult").bind("click",assessFn);
											
											
											//点击发表评论：保存发表内容和星级
											function clickSendAssessBtn(){
												var assessStar = $("#startCount").val();
												var assessContant = $(".resouinforcon").find("textarea").val();
												//评价状态 0-未评价，1-已评价
												
												//确认完成后，发表评论传值
												var assessContentStr ={
														"consultId":consultId, //咨询ID
													    "assessStatus":"1", //评价状态 0-未评价，1-已评价
													    "assessStar":assessStar, //评价星级
													    "assessContant":assessContant //评价内容
												};
												console.log(assessContentStr);
												//如果未评论，提示未评论
												if(assessStar == "" || assessStar == null || assessStar == undefined){
													if(assessContant == "" || assessContant == null || assessContant == undefined){
														$.MsgBox.Alert('提示',"未评论，是否退出评论");
													}
													$.MsgBox.Alert('提示',"未选择星级");
												};
												$.ajax({
													"url":"/ajax/consult/assess",//点击发表评论接口
													"type":"post",
													"data":assessContentStr,
													"success":function(response){
														console.log(response);
														$(".blackcover").remove();
														$("body").css("position","static");
														$.MsgBox.Alert('提示',"评论成功");
														
														//评价状态改变，所以头部信息改变
														dialogHeadDataHandleFn();
													},
													"error":function(error){
														//发表评论失败
														console.log(error);
													}
													
												});
											};
										

										
										},
										"error":function(error){
											//console.log(data);
											//加载对话页面失败
											console.log(error);
										}
									})
									
									
								};
								//给咨询页回复绑定事件
								$("#workContainer .workselectitem").find(".replyBtn").bind("click",clickReplyFn);

								
								//收到咨询和收到回复切换
								$(".worksamlltit3:first").addClass("active").show();
						        $(".workmysrc3:first").show(); 
						          
						        //On Click Event 收到咨询和收到回复tab效果 
						        $(".worksamlltit3").click(function() {
						            $(".worksamlltit3").removeClass("worksamlltitnow");
						            $(this).addClass("worksamlltitnow");
						            
						            $(".workmysrc3").hide();
						            
						            var activeTab = $(this).attr("href");
						            $(activeTab).fadeIn();
						            return false;
						        });

						    //=============================有咨询和回复时：ajax收到回复数据=============================
						        $.ajax({
						        	"url"  : "/ajax/consult/pqcon",//收到回复接口
									"type" : "get",
									//传值：登陆人id:咨询id
									"data" :consultIdStrByReply,
									"dataType" : "json",
									"contentType" : "application/x-www-form-urlencoded",
									"beforeSend":function(response){
//										console.log(response)
									},
									"success":function(replyResponse){
										//拿到收到回复数据
//										console.log(replyResponse);
										var replyTrHtml;
										var allData = replyResponse.data;
										var replyData = allData["data"];
//										console.log(replyData.length);
										if(replyData.length != 0 &&  replyData.length != null){
											replyTrHtml = handleData(replyData,replyTrHtml,"consultantId","lookBtn");
//											$(".tcdPageCode:last").before(replyTrHtml);	
											$("#workContainer2").prepend(replyTrHtml);
											
											
											$("#workContainer2 .workselectitem").find(".lookBtn").bind("click",clickLookBtn);
											
										}else{
											return false;
										}						
	
										
									},
									"error":function(response){
										//收到回复错误返回
//										console.log(response)
									},
						        	
						        });
						        
						      //==========================================咨询和收到回复，下拉菜单改变 ajax开始==================
						        
							      //收到咨询和收到回复下拉菜单点击函数
							      //排列顺序（正序、倒序）	
							      var sortFlag1 = true;//正倒排序标记
							    $("#replyArrow").click(function(){
							      	if(sortFlag1 == true){
							      		$(this).find("div").css("background-position","-20px 1px");	
							      		$("#timeSortId2").val("1");
							      		
							      		sortFlag1 =false;
							      		
							      	}else{
							      		$(this).find("div").css("background-position","0px 1px");	
							      		$("#timeSortId2").val("0");
							      		
							      		sortFlag1=true;
							      	}
							      	
							      });

							      var timeType2,sortType2,replyStatus,consultId;
							      
							      replyStatus = $("#replySelectId").val();//回复状态值
							      timeType2 = $("#timeTypeId2").val();//时间类型值
							      sortType2 = $("#timeSortId2").val();//排序值;

							      //console.log(consultStatus,timeType,sortType+"res333");

							      //默认传值：
							      var replyInfo = {
							      		"consultantId":userid,
							      		"status":replyStatus,
							      		"timeType":timeType2,
							      		"sortType":sortType2
							      };
							      //回复下拉菜单改变
							      function replyStatusFn(){
										//改变后，要传的值
							    	  	replyStatus = $("#replySelectId").val();//咨询状态值
										timeType2 = $("#timeTypeId2").val();//时间类型值
										sortType2 = $("#timeSortId2").val();//排序值;
									
										//要传的值：
										replyInfo = {
									      		"consultantId":userid,
									      		"status":replyStatus,
									      		"timeType":timeType2,
									      		"sortType":sortType2
									      };
//										console.log("ajax中的值:"+ replyInfo.replyStatus + replyInfo.timeType +  replyInfo.sortType +replyInfo.consultantId);
										
										
										$.ajax({
											"url":"/ajax/consult/pqcon",//更新下拉菜单接口
											"type":"get",
								        	"data":replyInfo,
											"beforeSend":function(response){
												console.log(response);
											},
											"success":function(response){
												$("#workContainer2 .workselectitem").remove();
//												$(".tcdPageCode:first").before().empty();
												var allData = response.data;
												var replyData = allData["data"];
												var replyTrHtml;
												replyTrHtml = handleData(replyData,replyTrHtml,"consultantId","lookBtn");
//												$(".tcdPageCode:last").before(replyTrHtml);
												$("#workContainer2").prepend(replyTrHtml);
												
												$("#workContainer2 .workselectitem").find(".lookBtn").bind("click",clickLookBtn);
											},
											"error":function(response){
//												console.log(response)
												//更新下拉菜单失败
											}
											
										});
										
																	
									};//更新下拉菜单处理函数结束
							        
									//绑定回复状态事件
									$(".replyOption ul").bind("click", "li",replyStatusFn);
									
									//绑定回复状态事件
									$(".timeOption2 ul").bind("click", "li",replyStatusFn);
									
									$("#replyArrow").bind("click",replyStatusFn);
									
									
									
									//=======================================================点击回复中查看
									function clickLookBtn(){
										var consultId     = $.trim($(this).attr("id"));//咨询id
										var assessStatus  = $.trim($(this).attr("assess"));//评价状态 0-未评价，1-已评价
										var consultStatus = $(this).find(".coultState").text();//咨询状态 0-进行中，1-已完成
										var thanksStatus  = $(this).find(".thanksStatus").text();//感谢状态 0-未感谢，1-已感谢
										var assessStar    = $(this).find(".assessStar").val();//星级,几颗星 用隐藏域做
										localStorage.setItem("consultId", consultId);
										//点击确认完成的传值:consultId,咨询状态
										var confirmFinishStr = {
											"consultId":consultId,
											"consultStatus":consultStatus
										};
										//对话标题 传值，
										var consultIdStr = {
											"consultId":consultId
										}
										if(assessStatus == "已评价"){
											//ajax加载对话页面
											$.ajax({
												"url":"diloags.html",
												"dataType":"html",
												"success":function(result){
													//console.log(data);
													$(this).attr("id");
													$(".workcon").html(result);
													
													lookDialogHeadDataHandleFn();
													dialogContentDataHandle();
													$("#dialog_sendBtn").bind("click",sendDialogContentFn);
													
													
												},
												"error":function(error){
													//console.log(data);
													//加载对话页面失败
													console.log(error);
												}
											});
										}else{
											assessFn();
											//点击稍后评价
											$("#noAssessBtn").bind("click",noAssess);
											
										}
										
												//===========================================dialog数据==================
												//=========对话头部
												//对话头部数据渲染
												function lookDialogHeadDataHandleFn(){
													//星星评级
													var starStart;
													function clickStar(){
														$(".evastar2").removeClass('addStar');
														starStart=$(this).index()+1;
														for(var i=0;i<starStart;i++){
															if(i<starStart){
																$(".evastar2").eq(i).addClass("addStar");
															}
															else{
																$(".evastar2").eq(i).removeClass('addStar');
															}
														}
														$("#startCount").val($(".addStar").length);
													};

													$.ajax({
														"url":"/ajax/consult/qacon",//从收到回复点击查看接口
														"type":"get",
														"data":consultIdStr,
														"success":function(response){
//															console.log("点击查看返回数据");
//															console.log(response)
															var consultantData = response["data"];
															//对话框标题信息
															//进行中，
															if(consultantData["consultStatus"] == 0){
																consultantData["consultStatus"] = "进行中";
																$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
																$("#dial_confirmFinishConsult").css("display","block");//确认完成按钮显示
																$("#showAllAssess").css("display","none");//总体评价
																$(".dialogfoot").css("display","block");//显示发送对话部分
																$("#dialog_thanks").css("display","none");//隐藏感谢
																$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																
																$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																
															}
															//已完成
															if(consultantData["consultStatus"] == 1 || consultantData["consultStatus"] == 2 ||consultantData["consultStatus"] == 3 || consultantData["consultStatus"] == 4){
																consultantData["consultStatus"] = "已完成";
																$("#dil_consultStatus").text(consultantData["consultStatus"]);//咨询状态
																//已完成，未感谢:
																if(consultantData["thanksStatus"] == 0){
																	$("#dialog_thanksBtn").css("display","block");//显示感谢按钮
																	//未感谢，未评价
																	if(consultantData["assessStatus"] == 0){
																		$("#dialog_assessBtn").css("display","block");//显示评价按钮
																		
																		$("#showAllAssess").css("display","none");//隐藏总体评价
																		$("#dialog_thanks").css("display","none");//隐藏感谢
																		$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																		$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																		$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																	}
																	//未感谢，已评价
																	else{
																		
//																		$("#dialog_thanksBtn").css("display","block");//显示感谢按钮
																		
																		var starCount = consultantData["assessStar"];
																		for(var i=0;i<starCount;i++){
																			$("#showAllAssess .evastar2").eq(i).addClass("addStar");
																		}
																		$("#showAllAssess").css("display","block");//显示星级
																		$("#dialog_thanks").css("display","none");//隐藏感谢
																		$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																		$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																		$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																	}
																	
																}
																//已完成，已感谢：评价星级，感谢金额
																if(consultantData["thanksStatus"] == 1){
																	$(".dialogfoot").css("display","none");//隐藏发送对话部分
																	var starCount = consultantData["assessStar"];
																	for(var i=0;i<starCount;i++){
																		$("#showAllAssess .evastar2").eq(i).addClass("addStar");
																	};
																	$("#showAllAssess").css("display","block");//显示星级
																	$("#dial_consultName").text(consultantData["professor"]["name"]);//与@@@对话
																	
																	$("#dialog_consultTitle").text(consultantData["consultTitle"]);//咨询主题
																	$("#dialog_consultType").text(consultantData["consultType"]);//咨询类型
																	$("#dialog_thanksMoney").text(consultantData["thanksMoney"]);
																}
																
															}
														
														},
														"error":function(error){
														//对话框头部信息请求失败
														}
													});
													
												};
											
												
												
												//============对话内容数据处理函数
												function dialogContentDataHandle(){
													$.ajax({
														"url":"/ajax/tidings/qacon",//对话内容显示接口
														"type":"get",
														"data":consultIdStr,
														"beforeSend":function(response){
															//对话发送消息失败
															//console.log(response);
														},
														"success":function(response){
															console.log()
															var dialogConData = response["data"];
//															console.log(dialogConData);
															var dialogStr;
															dialogStr = dialogContentStrFn(dialogConData);
															$("#dialogContent").prepend(dialogStr);
//															
														},
														"error":function(error){
															//对话框内容信息请求失败
														}
													});
													
													
												};
												
												
												//=============================对话页面底部发送
												//发送按钮处理函数
												function sendDialogContentFn(){
													var tidingsContant = $("#dialog_sendContent").val();
													var tidingStr = {
														"tidingsContant":tidingsContant,
														"senderId":userid,
														"consultId":consultId
													};
													//console.log(tidingStr);
													$.ajax({
														"url":"/ajax/tidings",
														"type":"post",
														"data":tidingStr,
														"beforeSend":function(response){
															//对话发送消息失败
															console.log(response);
														},
														"success":function(response){
															console.log(response);//返回对话内容的id
															$("#dialogContent").empty();
															dialogContentDataHandle();
														},
														"error":function(error){
															//对话发送消息失败
															console.log(error);
														}
													});
													$("#dialog_sendContent").val("");
												};
												
												
												
												//==============发表评价页
												function assessFn(){
													ConsultComment();
													
													if($.trim($(this).attr("thanks")) == "未感谢"){
														$(".addcomment2").css("display","none");//
														
													}else{
														
														$(".overcomment").css("display","none");
													}
													//评价星星样式
													var start;
													function clickStar(){
														$(".evastar2").removeClass('addStar');
														start=$(this).index()+1;
														for(var i=0;i<start;i++){
															if(i<start){
																$(".evastar2").eq(i).addClass("addStar");
															}
															else{
																$(".evastar2").eq(i).removeClass('addStar');
															}
														}
														$("#startCount").val($(".addStar").length);
													};
													$(".evastar2").bind("click",clickStar);
													//发表评论
													$("#sendAssessBtn").bind("click",clickSendAssessBtn);
													
												};
												
												//绑定对话页面确认完成咨询
												$("#dial_confirmFinishConsult").bind("click",assessFn);
												$("#dialog_assessBtn").bind("click",assessFn);
												
												
												//点击发表评论：保存发表内容和星级
												function clickSendAssessBtn(){
													var consultId = localStorage.getItem("consultId");//
													var assessStar = $("#startCount").val();
													var assessContant = $(".resouinforcon").find("textarea").val();
													//评价状态 0-未评价，1-已评价
													
													//确认完成后，发表评论传值
													var assessContentStr ={
															"consultId":consultId, //咨询ID
														    "assessStatus":"1", //评价状态 0-未评价，1-已评价
														    "assessStar":assessStar, //评价星级
														    "assessContant":assessContant //评价内容
													};
//													console.log(assessContentStr);
													//如果未评论，提示未评论
													if(assessStar == "" || assessStar == null || assessStar == undefined){
														if(assessContant == "" || assessContant == null || assessContant == undefined){
															$.MsgBox.Alert('提示',"未评论，是否退出评论");
														}
														$.MsgBox.Alert('提示',"未选择星级");
													};
													//保存
													$.ajax({
														"url":"/ajax/consult/assess",//点击发表评论接口
														"type":"post",
														"data":assessContentStr,
														"success":function(response){
//															console.log(response);
															$(".blackcover").remove();
															$("body").css("position","static");
															$.MsgBox.Alert('提示',"评论成功");
															//评价状态改变，所以头部信息改变
															lookDialogHeadDataHandleFn();
														},
														"error":function(error){
															//发表评论失败
															console.log(error);
														}
														
													});
													//发表评论
													$.ajax({
														"url":"diloags.html",
														"dataType":"html",
														"success":function(result){
															//console.log(data);
															$(this).attr("id");
															$(".workcon").html(result);
															
															$(".blackcover").remove();
															$("body").css("position","static");
															lookDialogHeadDataHandleFn();
															dialogContentDataHandle();
															$("#dialog_sendBtn").bind("click",sendDialogContentFn);
															
															
														},
														"error":function(error){
															//console.log(data);
															//加载对话页面失败
															console.log(error);
														}
													});
													
													
													
												};
												
												
												//稍后评价、
												function noAssess(){
//													$(".blackcover").remove();
//													$("body").css("position","static");
													$.ajax({
														"url":"diloags.html",
														"dataType":"html",
														"success":function(result){
															//console.log(data);
															$(this).attr("id");
															$(".workcon").html(result);
															
															$(".blackcover").remove();
															$("body").css("position","static");
															lookDialogHeadDataHandleFn();
															dialogContentDataHandle();
															$("#dialog_sendBtn").bind("click",sendDialogContentFn);
															
															
														},
														"error":function(error){
															//console.log(data);
															//加载对话页面失败
															console.log(error);
														}
													});
												};
												
											

											
											
										
										
									};//收到回复点击查看函数结束
									
									

								
								
							},
				        })
						
					}
				},
				"complete":function(response){
//					console.log(response)
				},
				"error":function(response){
					//收到咨询页面失败
//					console.log(response)
				},
				
				
			});

			
		}else{
			$.MsgBox.Alert('提醒',"您尚未登录");
		}
		
			
	})
	
})*/

