//用户id
var userid = $.cookie("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++){
		//text:回复/查看，state:进行中/已完成/未评价，photoUrl：头像地址，proModify：专家认证
		var text,state,photoUrl,proModify;
		
		if(data[i]["consultStatus"] == 0){
			state = "进行中";
			text = '回复';
		} else if (data[i]["consultStatus"] == 1) {
			text = "查看";
			state = "已完成";
			if(attrParams == 'consultId'){
				if(data[i]["assessStatus"] == 0){
					state = "未评价";
				}
			} 
		}else if(data[i]["consultStatus"] == undefined){
			text = "";
			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"]  = '';
		};
		if(data[i]["professor"]["office"] == undefined){
			data[i]["professor"]["office"] = '';
		};
		//专家头像
		if(data[i]["professor"]["hasHeadImage"] == 0){
			photoUrl = "images/default-photo.jpg"
			
		}else{
			photoUrl = "images/head/"+data[i]["professor"]["id"]+"_m.jpg"
			
		};
		//认证
		if(data[i]["professor"]["authentication"] == true){
			proModify = "display:inline-block;"
		}else{
			proModify = "display:none;"
		}
		
		//未读消息
		var unread = unreadConsultFn (userid,data[i]["consultId"],i);
		
		htmlStr += 
			"<div class='workselectitem' id='" +data[i]["consultId"] +"' >" +
				"<table width='100%'>" +
					"<tbody><tr>" +
						"<td width='14%' class='messagebox'>" +
							"<a class='workhead workitimg'>" +
								"<img class='headPhoto' src='"+photoUrl+"'  width='100%' height='100%'>" +
							"</a>" +
							"<span class='msgprompt showUnreadMsg' style='"+unread.style+"' id='" +data[i]["consultId"] +"'>"+unread.unreadCount+"</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' style='"+proModify+"' 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>职位"+data[i]["professor"]["office"]+"</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 unreadConsultFn (senderId,consultId,i){
	var unreadCount,style;
	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"];
			console.log()
			if(unreadCount == 0){
				style = "display:none;"
			}else{
				style = "display:block;"
				
			}
		},
		error:function(error){
			$.MsgBox.Alert('提示',"未读消息请求失败");
		}
		
	});
	return {"unreadCount":unreadCount,
			"style":style
	}
	

};



//列表最后回复
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){
			$.MsgBox.Alert('提示',"最后回复数据失败");
		}
		
	});
	
	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 (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:"/ajax/consult/pqCon",//收到回复接口
		type:"get",
		data :params,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		success:function(response){
			if(response["data"]["data"] == null || response["data"]["data"] == undefined || response["data"]["data"] == ""){
				return false;
			}
			else{
				//拿到收到回复数据
				var replyStr;
				var allData = response.data;
				var myData = allData.data;
				
				$("#workContainer2").html("");	
				if(myData.length != 0 &&  myData.length != null){
					replyStr = handleData(myData,"consultId","lookBtn");
					$("#workContainer2").append(replyStr);
					
				}else{
					return false;
				};
				//分页
				if(isbind == true){
					$(".getReplyPage").createPage({
				        pageCount:Math.ceil(allData.total/pageSize),
				        current:allData.pageNo,
				        backFn:function(p){
				        	getMyData(pageSize,p,false,status,timeType,sortType);
				        }
				    });
				}
				
			}
			
		},
		error:function(response){
			//收到回复错误返回
			$.MsgBox.Alert('提示',"收到回复数据请求失败");
		},
    	
    });
};

var getConsultData = function (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
		};
	
	$.ajax({
    	url:"/ajax/consult/pqPro",
		type:"get",
		//传值：登陆人id:咨询id
		data :params,
		async:false,
		dataType: "json",
		contentType: "application/x-www-form-urlencoded",
		success:function(response){
			if(response["data"]["data"] == null || response["data"]["data"] == undefined || response["data"]["data"] == ""){
				return false;
			}
			else{
				var consultStr;
				var allData = response.data;
				var myData = allData["data"];

				//拿到收到咨询数据
				$("#workContainer").html("");
				if(myData.length != 0 &&  myData.length != null){
					consultStr = handleData(myData,"professorId","lookBtn");
					$("#workContainer").append(consultStr);

				}else{
					return false;
				}
				//分页
				if(isbind == true){
					$(".getConsultPage").createPage({
				        pageCount:Math.ceil(allData.total/pageSize),
				        current:allData.pageNo,
				        backFn:function(p){
				        	getConsultData(pageSize,p,false,status,timeType,sortType);
				        }
				    });
				}
			}
			
		},
		error:function(response){
			$.MsgBox.Alert('提示',"收到咨询数据请求失败");
		},
    	
    });
};


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

				dialogHeadFn2("/ajax/consult/qapro",attrParams,consultId,thanksStatus);
				dialogContentDataHandle2(consultId);
				$("#dialog_sendBtn").click(function(){sendDialogContentFn2(sendId,consultId)});
			},
			error:function(error){
				//console.log(data);
				//加载对话页面失败
//				console.log(error);
			},
			complete:function(){
				//对话页后退按钮
				$("#backBtn").click(function(){
					$("#consultbtn").css({
						color:"#fff",
						background:"#f99550"
					});
					clickConsultBtn();
					
				});
			}
		})

	}

	//收到回复
	else if(attrParams == "consultId"){
		
		$.ajax({
			url:"diloags.html",
			dataType:"html",
			success:function(result){
				//console.log(data);
				$(".workcon").html(result);
				//进行中
				if(consultStatus == 0){
					dialogHeadFn2("/ajax/consult/qacon",attrParams,consultId,thanksStatus);
					dialogContentDataHandle2(consultId);
					$("#dialog_sendBtn").click(function(){sendDialogContentFn2(sendId,consultId)});
				}
				//完成
				else if(consultStatus == 1){
					//未评价
					if(assessStatus == 0){
							assessFn2(consultId,attrParams,thanksStatus)
	
					}else if(assessStatus == 1){
						dialogHeadFn2("/ajax/consult/qacon",attrParams,consultId,thanksStatus);
						dialogContentDataHandle2(consultId);
						$("#dialog_sendBtn").click(function(){sendDialogContentFn2(sendId,consultId)});
					}

				}
			},
			error:function(error){
				//console.log(data);
				//加载对话页面失败
//				console.log(error);
			},
			complete:function(){
				//对话页后退按钮
				$("#backBtn").click(function(){
					$("#consultbtn").css({
						color:"#fff",
						background:"#f99550"
					});
					clickConsultBtn();
					
				});
			}
			
			
		})
	}

};


//对话页咨询内容展开和收起
var cur_status = "less";
function showMore(){
	//alert("show_more_init!");
	var charNumbers=$("#dialog_consultContent").html().length;//总字数
	var limit = 20;//显示字数
	if(charNumbers > limit){
		var orgText  = $("#dialog_consultContent").html();//原始文本
		var orgHeight= $("#dialog_consultContent").height();//原始高度
		var showText = orgText.substring(0,limit);//最终显示的文本
		var showText = showText + "...";
		$("#dialog_consultContent").html(showText);
		var contentHeight = $("#dialog_consultContent").height();//截取内容后的高度
		$("#dialog_switch").click(function(){
			if(cur_status == "less"){
				$("#dialog_consultContent").height(contentHeight).html(orgText).animate({ height:orgHeight}, { duration: "slow" });
				$(this).html("收起");
				cur_status = "more";
			}else{
				$("#dialog_consultContent").height(orgHeight).html(showText).animate({ height:contentHeight}, { duration: "fast" });
				$(this).html("展开");
				cur_status = "less";
			}
		});
	}
	else{
		$("#dialog_switch").hide();
	}
};




//返回函数
function backHandle(){
	
	
};


//对话标题处理函数
function dialogHeadFn2(url,attrParams,consultId,thanksStatus){
	
	$.ajax({
		url:url,//
		data:{"consultId":consultId,"readStatus":"1"},
		type:"get",
		aysnc:false,
		success:function(response){
			var myData = response["data"];
			//咨询
			if(attrParams == 'professorId'){
				
				//进行中
				if(myData["consultStatus"] == 0){
					$("#dil_consultStatus").text("进行中");//咨询状态
					$(".dialogfoot").css("display","block");//显示发送对话部分
					$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
					$("#dialog_consultType").text(myData["consultType"]);//咨询类型
					$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话
					$("#dialog_consultContent").html(myData["consultContant"])//咨询内容
					
				}
				//咨询已完成
				else {
					$("#dil_consultStatus").text("完成");//咨询状态
					$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
					$("#dialog_consultType").text(myData["consultType"]);//咨询类型
					$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话
					$("#dialog_consultContent").html(myData["consultContant"])//咨询内容
					
					$(".dialogfoot").css("display","none");//隐藏发送对话部分
					//如果评价
					if(myData["assessStatus"] == 1){
						
						var startConut = myData["assessStar"];
						for(var i = 0; i < startConut; i ++){
							$("#showAllAssess .evastar2").eq(i).addClass("addStar");
						}
						$("#showAllAssess").removeClass("displayNone");//总体评价
						
						$("#dialog_assessContent").removeClass("displayNone");
						$("#dialog_assessContentText").html(myData["assessContant"]);

						//如果感谢
						if(myData["thanksStatus"] == 1){

							if(myData["thanksMoney"] != null && myData["thanksMoney"] != undefined && myData["thanksMoney"] != "" && myData["thanksMoney"] != 0 ){
								
								$("#dialog_thanks").removeClass("displayNone");//感谢
								$("#dialog_thanksMoney").text(myData["thanksMoney"]);
							}
							
						}else {//未感谢
							return false;
						}
						
					}else {//未评价
						return false;
					}

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

					$("#confirmBtn").removeClass("displayNone");//确认完成按钮显示
					
					//点击确认完成
					$("#confirmBtn").click(function(){
						clickConfirmFn(consultId,thanksStatus);
					})
					
					//发表评论
					$("#sendAssessBtn").click(function(){
						clickSendAssessBtn2(consultId,attrParams,thanksStatus)
					});
					
					//稍后评价
					$("#noAssessBtn").click(function(){
						noAssessFn2(consultId,attrParams,thanksStatus);
					});
					//点击关闭
					$("#closeAssessBtn").click(function(){
						noAssessFn2(consultId,attrParams,thanksStatus);
					});
					
					
				}
				//回复完成
				else {
					$("#dil_consultStatus").text("已完成");//咨询状态
					$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
					$("#dialog_consultType").text(myData["consultType"]);//咨询类型
					$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话
					$("#dialog_consultContent").html(myData["consultContant"])//咨询内容
					
					$(".dialogfoot").css("display","none");//隐藏发送对话部分
					
					//回复完成未评价
					if(myData["assessStatus"] == 0){
						
							assessFn2(consultId,attrParams,thanksStatus)

					}else {
						//评价星级
						var startConut = myData["assessStar"];
						for(var i = 0; i < startConut; i ++){
							$("#showAllAssess .evastar2").eq(i).addClass("addStar");
						}
						$("#showAllAssess").removeClass("displayNone");//总体评价
//						$("#dialog_thanksBtn").removeClass("displayNone");
						
						$("#dialog_assessContent").removeClass("displayNone");
						$("#dialog_assessContentText").html(myData["assessContant"]);
						
						//未感谢
						if(myData["thanksStatus"] == 0){
							
//							$("#dialog_thanksBtn").removeClass("dispalyNone");
						}else {
							//感谢金额
//							$("#dialog_thanks").removeClass("displayNone");
//							$("#dialog_thanksMoney").text(myData["thanksMoney"]);
							
						}
						
					}
					
				}
	
			};
			
			//咨询内容展开收起效果
			if($("#dialog_consultContent")){
				
				showMore();
			};
			

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

}




//点击确认完成
function clickConfirmFn(consultId,thanksStatus){
	finish();
	
	$("#finish").click(function(){
		finishFn(consultId)
	});
	
}

//点击确认完成弹窗中完成
function finishFn(consultId,thanksStatus){
	//更新咨询状态
	$.ajax({
		url:"/ajax/consult/finishTime",
		type:"post",
		data:{
		    "consultId":consultId, //咨询ID
		    "consultStatus":"1", //咨询状态 0-进行中，1-已完成
		},
		success:function(response){
			console.log(response);
			$(".blackcover").remove();
			$("body").css("position","static");
			assessFn2(consultId,"consultId",thanksStatus);
		},
		error:function(error){
			//更新咨询状态失败
		}
	});
	
	
};


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

};

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


//评价
function assessFn2(consultId,attrParams,thanksStatus){
	ConsultComment();

	//评价星星样式
	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").click(function(){
		clickSendAssessBtn2(consultId,attrParams,thanksStatus)
	});
	
	//稍后评价
	$("#noAssessBtn").click(function(){
		noAssessFn2(consultId,attrParams,thanksStatus)
	});
	//点击关闭
	$("#closeAssessBtn").click(function(){
		noAssessFn2(consultId,attrParams,thanksStatus)
	});

};

//发送评价
//点击发表评论：保存发表内容和星级
function clickSendAssessBtn2(consultId,attrParams,thanksStatus){
	var assessStar = $("#startCount").val();
	var assessContant = $("#assessCon").val();
	var assessContentStr ={
			"consultId":consultId, //咨询ID
		    "assessStatus":"1", //评价状态 0-未评价，1-已评价
		    "assessStar":assessStar, //评价星级
		    "assessContant":assessContant //评价内容
	};
	
	//保存
	$.ajax({
		"url":"/ajax/consult/assess",//点击发表评论接口
		"type":"post",
		"data":assessContentStr,
		"success":function(response){
			
		},
		"error":function(error){
			//发表评论失败
			$.MsgBox.Alert('提示',"评论失败");
		},
		"complete":function(){
			$(".blackcover").remove();
			$("body").css("position","static");
			
			//发表评价后进入对话页
			$.ajax({
				"url":"diloags.html",
				"dataType":"html",
				"success":function(result){
					//console.log(data);
					$(".workcon").html(result);

					dialogHeadFn2("/ajax/consult/qacon",attrParams,consultId,thanksStatus);
					dialogContentDataHandle2(consultId);


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

	});
	

};


//稍后评价、
function noAssessFn2(consultId,attrParams,thanksStatus){
	$.ajax({
		"url":"diloags.html",
		"dataType":"html",
		"success":function(result){
			//console.log(data);
			$(this).attr("id");
			$(".workcon").html(result);
			$(".blackcover").remove();
			$("body").css("position","static");
			
			$.ajax({
				url:"/ajax/consult/qacon",//对话标题信息接口
				data:{"consultId":consultId,"readStatus":"1"},
				type:"get",
				aysnc:false,
				success:function(response){
					var myData = response["data"];
					//稍后评价说明已经完成	
					$("#dil_consultStatus").text("已完成");//咨询状态
					$("#dialog_consultTitle").text(myData["consultTitle"]);//咨询主题
					$("#dialog_consultType").text(myData["consultType"]);//咨询类型
					$("#dial_consultName").text(myData["professor"]["name"]);//与@@@对话
					$(".dialogfoot").css("display","none");//隐藏发送对话部分
					
					$("#dialog_assessBtn").removeClass("displayNone");
					$("#dialog_assessBtn").click(function(){
						assessFn2(consultId,attrParams,thanksStatus);
					});
					
				},
				error:function(error){
					
				}
			});
			
			dialogContentDataHandle2(consultId);

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


//点击主页面咨询函数
function clickConsultBtn(){
	if(userid != "" && userid != null){
		
		 $.ajax({
	        	"url":"consult.html",
				"dataType" : "html",
				"success":function(responseHtml){
					$(".workcon").html(responseHtml);
					
					//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;
			        };
					

					//收到咨询
					getConsultData("5",1,true,0,0,0);
					//咨询点击下拉菜单
					consultPullDownMenu();
					

					//无咨询  显示我的需求
					if($("#workContainer").find(".workselectitem").length == 0){
//						alert("无咨询  显示我的需求");
						$(".worksubcon .workmysrc3 ").eq(0).css("display","none");
						$(".workcontit .worksamlltit3").eq(0).removeClass("worksamlltitnow");
						
						$(".worksubcon .workmysrc3 ").eq(1).css("display","block");
						$(".workcontit .worksamlltit3").eq(1).addClass("worksamlltitnow");
						
						//回复
				        getMyData("5",1,true,0,0,0);
				        //回复点击下拉菜单
				        myRequirePullDownMenu();
						
				        //无咨询和需求
				        if($("#workContainer2").find(".workselectitem").length == 0){
//				        	$("#workContainer2").append("<div>无需求</div>");
				        }
				        
						
					}
					//有咨询
					else {
//						alert("有咨询")
						//回复
				        getMyData("5",1,true,0,0,0);
				        
				        //回复点击下拉菜单
				        myRequirePullDownMenu();
				        
					}

						$(".workcontit .worksamlltit3").eq(0).click(function(){
							
							$("#workContainer").remove();
							$(".getConsultPage").remove();
							$(".workselectcon").eq(0).append('<div id="workContainer"></div>');
							$(".workselectcon").eq(0).append('<div class="tcdPageCode getConsultPage"></div>');
							
							//收到咨询
							getConsultData("5",1,true,0,0,0);
							//点击下拉菜单
							consultPullDownMenu();
							
						});
						
						
		 				$(".workcontit .worksamlltit3").eq(1).click(function(){

		 					$("#workContainer2").remove();
							$(".getReplyPage").remove();
							$(".workselectcon").eq(1).append('<div id="workContainer2"></div>');
							$(".workselectcon").eq(1).append('<div class="tcdPageCode getReplyPage"></div>');
		 					
		 					//回复
					        getMyData("5",1,true,0,0,0);
					        //点击下拉菜单
					        myRequirePullDownMenu();
		 					
						});
	   
				},
	        })
						
	
	}else{
		$.MsgBox.Alert('提醒',"您尚未登录");
	}

};

//咨询下拉菜单顺序处理函数
function  consultPullDownMenu(){
	//点击下拉菜单
    $(".consultOption ul").find("li").click(function(){
    	getConsultData("5",1,true,$(this).attr("tip"),$("#showTimeSort").attr("tim"),$("#timeSortId").val());
    	});
	$(".timeOption ul").find("li").click(function(){

		getConsultData("5",1,true,$("#showStatus").attr("tip"),$(this).attr("tim"),$("#timeSortId").val());
		});
	var sortFlag = true;
	$("#consultArrow").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;
      	}
		
		
		getConsultData("5",1,true,$("#showStatus").attr("tip"),$("#showTimeSort").attr("tim"),$("#timeSortId").val());
	});
};

//我的需求下拉菜单处理函数
function  myRequirePullDownMenu(){
	 //点击下拉菜单
    $(".replyOption ul").find("li").click(function(){
    	
    	getMyData("5",1,true,$(this).attr("tip"),$("#showTimeSort2").attr("tim"),$("#timeSortId2").val());
    	});
	$(".timeOption2 ul").find("li").click(function(){
		getMyData("5",1,true,$("#showStatus2").attr("tip"),$(this).attr("tim"),$("#timeSortId2").val());
		});
	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;
      	}
		getMyData("5",1,true,$("#showStatus2").attr("tip"),$("#showTimeSort2").attr("tim"),$("#timeSortId2").val());
	});
};




