// JavaScript Document

$(function(){
	//alert("sciresouser");
	
	var userid = $.cookie("userid");
	var name = $.cookie("userName");
	var flag;
	
////发布资源发布及修改
	var resourceNamePass = true;
	//var professorPass=true;
	var supportedServicesPass=true;	
	
	function resourceName()
	{
		var code = $("#resourceName").val();
		if(code.length==0||code==" ")
		{
			$(".workmsg1").text("发布资源名称不能为空");
			resourceNamePass = false;
		}
		else
		{
			$(".workmsg1").text("");
			resourceNamePass= true;
		}
	}
	$("#resourceName").blur(function(){
		 resourceName();
	});

//验证可提供服务	
	function supportedServices()
	{
		var code = $("#supportedServices").val();
		if(code.length==0||code==" ")
		{
			$(".workmsg3").text("可提供服务不能为空");
			supportedServicesPass= false;
		}
		else
		{
			$(".workmsg3").text("");
			supportedServicesPass= true;
		}
	}	
	$("#supportedServices").blur(function(){
		 supportedServices();
	});		

	function industryShow(data,industryList,deleteIndustry)
	{
				if(data != undefined && data.length != 0  )
				{
					var subs = new Array();
					if(data.indexOf(','))
					{
						subs = data.split(',');
					}
					else
					{
						subs[0] = data;
					}
					if(subs.length>0)
					{
						for (var i = 0; i < subs.length; i++) 
						{
							$("#"+industryList+"").append("<div class='"+deleteIndustry+"'>"+ subs[i] +"<span class='removeNu'><img src='images/move.png'></span></div>");																
						};
					}	
				}			
	}
	//添加或者删除应用行业及学术领域
	function addDele(){
		$("#industryList").on("click",".removeNu",function(){					
			$(this).parent().remove();
			});	
		$("#industryAdd").click(function(){
			var val=$("#industry").val();
			$("#industryList").append("<div class='deleteIndustry'>"+ val +"<span class='removeNu'><img src='images/move.png'></span></div>")							
			});
		$("#SubjectList").on("click",".removeNu",function(){					
			$(this).parent().remove();
			});	
		$("#subjectAdd").click(function(){				
			var val=$("#subject").val();
			$("#SubjectList").append("<div class='deleteSubject'>"+ val +"<span class='removeNu'><img src='images/move.png'></span></div>")							
			});
	}
//我的资源的删除，修改
	$("#workmysrc").on("click",".resoumag",function()
			{ 		
				ResourceInfo();
				addDele()
				$(".limitBox").removeClass("limitBox");
		        $(".limitwords").removeClass("limitwords");
		        $(".limitwordbox").removeClass("limitwordbox");
				
				$(".respublisher").css("display","none");
				$(".stateinfor span").text("资源发布中");
				var resourceID=$(this).attr("resourceId");
				function delet(){
					$.ajax({
						"url" : "/ajax/resource/"+resourceID,
						"type" : "DELETE",
						"success" : function($data) {							
							if ($data.success) {
								$(".blackcover").remove();
								$("body").css("position","static");	
								getDataResource();								
							} else {
								$.MsgBox.Alert('message',$data.msg);
							}
						}
					})
				}
				if(resourceID){
					$("#deletedResource").on("click",function(){
						$(".blackcover").remove();
						$("body").css("position","static");
						$.MsgBox.Confirm("消息", "执行删除后资源信息将无法恢复，确定继续吗？",delet)					
					})
					$.ajax({		
						"url":"/ajax/resource/"+resourceID,
						"type":"get",
						"async": true,
						"success":function(info){
							if(info.success)
								{
								//console.log(info);
								$("#resourceName").val(info.data.resourceName);
								$("#supportedServices").val(info.data.supportedServices);
								$("#hopePayMethod").val(info.data.hopePayMethod) ;
								$("#cooperationNotes").val(info.data.cooperationNotes) ;
								industryShow(info.data.subject,"SubjectList","deleteSubject");
								 industryShow(info.data.industry,"industryList","deleteIndustry");								
								$("#descp").val(info.data.descp);
								$("#professor").text(name);
								if(info.data.images.length) {
															 var $liMages = $(
																	 '<div id="WU_FILE" class="file-item thumbnail">'+
															 			'<img src="/images/resource/'+resourceID+'.jpg">'+								 			
															 			'</div>'
															            )
								}
								else
								{
									var $liMages = $(
											 '<div id="WU_FILE" class="file-item thumbnail">'+
									 			'<img src="/images/default-resource.jpg">'+								 			
									 			'</div>'
									            )
								}
								
								 $("#fileList").append($liMages);     
								
								}
								else
								{
									$.MsgBox.Alert('message',"系统异常!");
								}
						},
						"error":function(){$.MsgBox.Alert('message','failed')}
					});
				}
				
				function captiureSubInd(subIndu)
				{
					var industrys = $("#"+subIndu+"");
					var industryAll = "";
					if(industrys.size()>0){
						for (var i = 0; i <industrys.size(); i++) {
							industryAll += industrys[i].innerText;
							industryAll += ',';
						};
						industryAll = industryAll.substring(0, industryAll.length-1);
					}
					return industryAll;
				}		
				$("#inputb").on("click",function()
						{						
								var $data = {};
								$data.resourceName = $("#resourceName").val();
								$data.supportedServices = $("#supportedServices").val();
								$data.professorId = userid;
								$data.hopePayMethod = $("#hopePayMethod").val();
								$data.cooperationNotes = $("#cooperationNotes").val();
								$data.subject=captiureSubInd("SubjectList .deleteSubject");
								$data.industry=captiureSubInd("industryList .deleteIndustry");
								$data.descp=$("#descp").val();								
								if(cacheImageKey){
									console.log(cacheImageKey);
									$data.fn=cacheImageKey;
								}
								if (resourceID) {
									
									$data.resourceId = resourceID;
									
								}
								function getDataput(){		
									$.ajax({"url" : "ajax/resource/updateResource",
										"type" :  "post" ,
										"success" : function(rdata) {
											if (rdata.success){													
													getDataResource();						
											} else {
												$.MsgBox.Alert("消息","资源发布失败");
											}
										},
										"data" :$data,
										"beforeSend":function(){/*console.log(this.data)*/ },
										"contentType" : "application/x-www-form-urlencoded",
										dataType : "json"
									});
								}
								//console.log($data);
							resourceName();
//							professor();
							supportedServices();
							if(resourceNamePass && supportedServicesPass)
							{
								if(resourceID){
									$(".blackcover").remove();
									$("body").css("position","static");
									$.MsgBox.Confirm("消息", "确定修改资源信息吗？", getDataput)
									$data.fn=cacheImageKey;
								}else{
									
									$.ajax({"url" : "/ajax/resource",
										"type" :  "POST",
										"success" : function(rdata) {
											if (rdata.success) 
											{											
													$(".blackcover").remove();
													$("body").css("position","static");												
													getDataResource();
													$.MsgBox.Alert("消息","资源发布成功");										
											} 
											else 
											{
												$.MsgBox.Alert("消息","资源发布失败");
											}
										},
										"data" : $data,
										"beforeSend":function(){/*console.log(this.data)*/ },
										"contentType" : "application/x-www-form-urlencoded",
										dataType : "json"
									});
								}
								
							}
						});
			});

	getDataResource();
	function getDataResource(){
		$.ajax({		
			"url":"/ajax/resource/qapro",
			"type":"get",
			"async": true,
			"data":{"professorId":userid},
			"success":function(data){
				if(data.success)
					{
					var add='';
					var k=0;
					$("#consd").html("");
					for(var i=0;i<data.data.length;i++)
						{
							var add='<div class="maintab"><div class="lefttab fl"><table class="resoubrief"><tr><td><div class="resoimgbox"><img class="resourceImg" width="100%" height="100%" src=""></div></td>'
							add+='</tr><tr><td><ul><li>'+data.data[i].resourceName+'</li><li>'+data.data[i].supportedServices+'</li> '               
							/*add+='<li class="li1">'+data.data[i].subject+'</li>' */                  
							add+='</ul></td></tr><tr>'                
							add+='<td><span class="managebtn resoumag"">资源管理</span></td></tr></table></div>'                 
							add+='<div class="righttab fr"><table width="100%" class="worktab tablecon">'
							add+='<tr class="worktabtit"><th width="20%" height="40">申请时间</th><th width="20%">需求方</th>'    
							add+='<th width="12%">联系人</th><th width="14%">交付时间</th>'        
							add+='<th width="20%">付款进程</th><th width="12%">状态/操作</th></tr></table><div class="tcdPageCode tcdPageCod'+i+'"></div></div>';
							$add = $(add);
							
							$("#consd").append($add);
							if(data.data[i].subject==undefined){
								$(".li1").eq(i).css({"display":"none"});
							}	
							
							$add.find('.resoumag').attr("resourceId",data.data[i].resourceId);
							
							
							//$('.resoumag').eq(i+1).attr("resourceId",data.data[i].resourceId);
							if(data.data[i].images.length){
								$add.find(".resourceImg").attr("src","/images/resource/"+data.data[i].resourceId+".jpg");
							}
							else
							{
								$add.find(".resourceImg").attr("src","/images/default-resource.jpg");
							}
							
							
							
									
								
							
							//console.log($('.resoumag').eq(i+1).attr("resourceId"));
							//资源所对应的记录
							(function(i){
								getPageResource(3,1,true,i,k)
								k++;
							})(i);
						
							add="";
						}											
					
					}
					else
					{
						$.MsgBox.Alert('message',"系统异常!");
					}
			},
			"error":function(){$.MsgBox.Alert('message','failed')}
		});
	}
	function getPageResource(pageSize,pageNo,isbind,e,f)
	{
				
								$.ajax({		
										"url":"/ajax/operation/pqres",
										"type":"get",
										"async": false,
										"data":{"resourceId":$('.resoumag').eq(e+1).attr("resourceId"),"pageSize":pageSize,"pageNo":pageNo},						
										"success":function(data){			
											if(data.success)
												{			
												$(".maintab").eq(f).find(".workitem").remove();
												
													for(var j=0;j<data.data.data.length;j++)
													{
														if(data.data.data[j].dealPrice==undefined)
														{	
															data.data.data[j].dealPrice=0;													
														}	
														
														if(data.data.data[j].payMethod==undefined){												
															data.data.data[j].payMethod="";
														}
														
														data.data.data[j].deliverTime=changeTime(data.data.data[j].deliverTime);
														data.data.data[j].createTime=changeTime(data.data.data[j].createTime);
														
														var inquiry=inquiryGetPaidMoney(data.data.data[j].operationId);												
														var addString='<tr class="workitem">'
										                    addString+='<td>'+data.data.data[j].createTime+'</td>'
										                     addString+='<td class="workitemsrc">'+data.data.data[j].applysquare+'</td>'
										                      addString+='<td> <span class="worktel">'+data.data.data[j].professor.name+'<!--<span class="worktelbtn"></span>--></span></td>'						                  
										                      addString+='<td>'+data.data.data[j].deliverTime+'</td>'
										                       //addString+='<td class="price1'+e+'">'+data.data.data[j].dealPrice+'</td>'
										                        //addString+='<td>'+data.data.data[j].payMethod+'</td>'
										                       addString+='<td><span>'+inquiry+'</span>/<span>'+data.data.data[j].dealPrice+'</span><br></td>'
										                        addString+='<td><div class="modification'+e+'"></div></td> </tr>'						                      		
										                        	$(".tablecon").eq(e).append(addString);
																	//console.log($(".tablecon").eq(e));
																	if($(".price1"+e+"").eq(j).text()==0){
																		$(".price1"+e+"").eq(j).text("");
																	}																		
																	switch(data.data.data[j].operationStatus)
																	{
																	case 1:
																		var string='<span>新的申请</span><br/>'
																		string+='<a class="operatebtn">'
																		string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>回复申请</span><br />'
																		string+='</a>'
																		$(".modification"+e+"").eq(j).html(string);
																	  break;
																	case 2:
																		var string='<span>已发送报价待对方确认</span><br/>'
																		string+='<a class="operatebtn">'
																		string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus="2" operationId='+data.data.data[j].operationId+'>修改报价</span><br />'
																		string+='</a>'
																			$(".modification"+e+"").eq(j).html(string);
																	  break;
																	case 3:
																		var string='<span>对方发来报价合作进行中</span><br/>'
																		string+='<a class="operatebtn">'
																			string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+' dealPrice='+data.data.data[j].dealPrice+'>查看详情</span><br />'
																		string+='<span class="drawback"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+' dealPrice='+data.data.data[j].dealPrice+'>退款</span><br />'
																		string+='<span resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>投诉</span>'
																		string+='</a>'
																			$(".modification"+e+"").eq(j).html(string);
																	  break;
																	case 4:
																		var string='<span>对方拒绝报价合作结束</span><br/>'
																		string+='<a class="operatebtn">'
																		string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>查看详情</span><br />'
																		string+='</a>'
																			$(".modification"+e+"").eq(j).html(string);
																	  break;
																	case 5:
																		var string='<span>本人拒绝合作</span><br/>'
																		string+='<a class="operatebtn">'
																		string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>查看详情</span><br />'
																		string+='</a>'
																			$(".modification"+e+"").eq(j).html(string);
																	  break;
																	case 6:
																			var string='<span>对方中止合作合作结束</span><br/>'
																			string+='<a class="operatebtn">'
																				string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+' dealPrice='+data.data.data[j].dealPrice+'>查看详情</span><br />'
																			//string+='<span class="discuss" dataStatus="1"resourceId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>评价</span><br />'
																			string+='<span class="drawback"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+' dealPrice='+data.data.data[j].dealPrice+'>退款</span><br />'
																			string+='<span class="complain"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>投诉</span>'
																			string+='</a>'
																				$(".modification"+e+"").eq(j).html(string);	
																	  break;
																	case 7:
																		var string='<span>合作进行中</span><br/>'
																		string+='<a class="operatebtn">'
																			string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+' dealPrice='+data.data.data[j].dealPrice+'>查看详情</span><br />'
																		//string+='<span class="acknowledgement"resourceId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>确认完成</span><br />'
																		string+='<span class="complain"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>投诉</span>'
																		string+='</a>'
																			$(".modification"+e+"").eq(j).html(string);
																	  break;
																	case 8:
																		var string='<span>完成</span><br/>'
																		string+='<a class="operatebtn">'
																			string+='<span class="detailmess"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+' dealPrice='+data.data.data[j].dealPrice+'>查看详情</span><br />'
																		//string+='<span class="discuss" dataStatus="1"resourceId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>评价</span><br />'
																		string+='<span class="complain"resourId='+data.data.data[j].resource.resourceId+' operationStatus='+data.data.data[j].operationStatus+' operationId='+data.data.data[j].operationId+'>投诉</span>'
																		string+='</a>'
																			$(".modification"+e+"").eq(j).html(string);
																	  break;
																	default:																	  
																	}																		
														addString="";
													}
													
									if(data.data.total == 0){	
										
										}else{
											if(isbind == true)
											{	
												$(".tcdPageCod"+e+"").createPage({
											        pageCount:Math.ceil(data.data.total/pageSize),
											        current:data.data.pageNo,
											        backFn:function(p){					        							        	
											        	getPageResource(3,p,false,e,f);									        	
											        }									      
											    });
											 }
										}
												}
												else
												{
													$.MsgBox.Alert("消息","系统异常!");
												}
										},
										"error":function(){$.MsgBox.Alert('message','failed')}
									});
	}

//我的资源状态的回复
$("#consd").on("click",".detailmess",function(){	
	$(".stateinfor span").text("回复申请");
	var operationId=$(this).attr("operationId");
	var operationStatus=$(this).attr("operationStatus");
	var priceDifference=$(this).attr("dealPrice");	
	opo=operationId;
	flag=0;
	
	if(flag==0&&operationStatus==1)
	{	ResourceApply();
		//移出有textare标签的相关class
		$(".limitBox").eq(1).removeClass("limitBox");
        $(".limitwords").eq(1).removeClass("limitwords");
        $(".limitwordbox").eq(1).removeClass("limitwordbox");
        
		ajaxGet(operationId);

		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});

		$("#nextStep").click(function(){
			$(".stateinfor span").text("报价中");
			$(".btnboxup").css({"display":"none"});
			$(".btnboxdown").css({"display":"block"});
			$(".applysure").css({"display":"block"});
			$(".bag").css("display","none");
			$("#reject").hide();
			
			$(".frm").click(function(){
				var $date = {};	
				$date.detailDemand=$(".detail").text();
				$date.deliverTime=replaceStr($.trim($(".dealTime").text()));
				$date.dealPrice =$.trim($("#dealPrice").val());
				$date.payMethod = $.trim($("#payMethod").val());
				$date.replyNotes = $("#consultContent").val();
				$date.applysquare = $(".sname").text();
				$date.operationId=operationId;
				$date.operationStatus=2;
				$.ajax({
					"url" : "/ajax/operation",
					"type" : "put",
					"data" :JSON.stringify($date),
					"contentType" :"application/json",
					"success" : function(data) {
						if (data.success) {					
							$(".blackcover").remove();
							$("body").css("position","static");
							getDataResource();
							$.MsgBox.Alert('message',"报价成功");
						} else {
							$.MsgBox.Alert('message',data.msg);
						}
					},
				"beforeSend":function(){
					//console.log(this.data);
				},
				});
			})
		
		})
		$("#refuses").click(function(){
			ResourceApply();
			ajaxGet(operationId);
			n=5;
			$(".blackcover").remove();
			$("body").css("position","static");
			$.MsgBox.Confirm("消息", "确定拒绝吗？",upStatus1);
		});
	}
	if(flag==0&&operationStatus==2){
		ResourceApply();
		//移出有textare标签的相关class
		$(".limitBox").eq(1).removeClass("limitBox");
        $(".limitwords").eq(1).removeClass("limitwords");
        $(".limitwordbox").eq(1).removeClass("limitwordbox");
        
		ajaxGet(operationId);
		
		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});

		$(".stateinfor span").text("修改报价中");
		$(".btnboxup").css({"display":"none"});
		$(".btnboxdown").css({"display":"block"});
		$(".applysure").css({"display":"block"});
		$(".bag").css("display","none");			
			$(".frm").click(function(){
				var $date = {};	
				$date.detailDemand=$(".detail").text();
				$date.deliverTime=replaceStr($.trim($(".dealTime").text()));
				$date.dealPrice = $("#dealPrice").val();
				$date.payMethod = $("#payMethod").val();
				$date.replyNotes = $("#consultContent").val();
				$date.applysquare = $(".sname").text();
				$date.operationId=operationId;
				$date.operationStatus=2;
				$.ajax({
					"url" : "/ajax/operation",
					"type" : "put",
					"data" :JSON.stringify($date),
					"contentType" :"application/json",
					"success" : function(data) {
						if (data.success) {					
							$(".blackcover").remove();
							$("body").css("position","static");
							getDataResource();
							$.MsgBox.Alert('message',"报价成功");
						} else {
							$.MsgBox.Alert('message',data.msg);
						}
					},
				"beforeSend":function(){
					//console.log(this.data);
				},
				});
			})	
	}
	if(flag==0&&operationStatus==3){
		
		DetailInfo();
		
		$("#totalPrice").text(priceDifference);
		$(".liuyaninfo").css("display","none");		
		$(".pingjiainfo").css("display","none");
		$(".filebox").css("display","none");
		ajaxGet1(operationId);
		$(".payaddbox1").css("display","none");

		discussGetPaidMoney(operationId,priceDifference)
	}
	if(flag==0&&operationStatus==5){
		ResourceApply();
		ajaxGet(operationId);
		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});
		$(".addrebtn").css("display","none");

	}
	if(flag==0&&operationStatus==4){
		ResourceApply();
		ajaxGet1(operationId);

		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});	
		$(".stateinfor span").text("详情");
		$(".btnboxup").css({"display":"none"});
		$(".btnboxdown").css({"display":"block"});
		$(".applysure").css({"display":"block"});
		$(".bag").css("display","none");
		$(".addrebtn").css("display","none");
		$("#payMethod").replaceWith("<span id='payMethod'><span>");
		$("#dealPrice").replaceWith("<span id='dealPrice'><span>");
		$("#consultContent").replaceWith("<span id='consultContent'><span>");

	}	
if(flag==0&&operationStatus==6){
		
		DetailInfo();	
		$("#totalPrice").text(priceDifference);
		$(".liuyaninfo").css("display","none");		
		$(".pingjiainfo").css("display","none");
		$(".filebox").css("display","none");
		ajaxGet1(operationId);
		$(".payaddbox1").css("display","none");

		discussGetPaidMoney(operationId,priceDifference)
	}
if(flag==0&&operationStatus==7){
	
	DetailInfo();
	$("#totalPrice").text(priceDifference);
	$(".liuyaninfo").css("display","none");		
	$(".pingjiainfo").css("display","none");
	$(".filebox").css("display","none");
	ajaxGet1(operationId);
	$(".payaddbox1").css("display","none");
	//根据内容的多少获取高度给父级设置高度
	limitHeight();
	discussGetPaidMoney(operationId,priceDifference)
}
if(flag==0&&operationStatus==8){
	
	DetailInfo();
	$("#totalPrice").text(priceDifference);
	$(".liuyaninfo").css("display","none");		
	$(".pingjiainfo").css("display","none");
	$(".filebox").css("display","none");
	ajaxGet1(operationId);
	$(".payaddbox1").css("display","none");
	//根据内容的多少获取高度给父级设置高度
	limitHeight();
	discussGetPaidMoney(operationId,priceDifference)
}
})





//我的需求查询
function getPageData(pageSize,pageNo,isbind){
	$.ajax({		
	"url":"/ajax/operation/pqdem",
	"type":"get",
	"async": true,
	"data":{"demandId":userid,"pageSize":pageSize,"pageNo":pageNo},
	"success":function(data){
		if(data.success)
			{	
			$(".worktabb").html("");
			var stringTitle="";
			stringTitle +='<tr class="worktabtit"><th width="20%" height="40">申请时间</th><th width="22%">需求资源</th><th width="12%">发布者</th><th width="14%">交付时间</th><th width="22%">付款进程</th><th width="10%">状态/操作</th></tr>';
			$(".worktabb").append( stringTitle);
			
			//console.log(data);
			//alert(data.data.data.length);
				for(var i=0;i<data.data.data.length;i++)
					{	
					
					var inq=inquiryGetPaidMoney(data.data.data[i].operationId);
					if(data.data.data[i].dealPrice==undefined){
						data.data.data[i].dealPrice=0;
					}
					if(data.data.data[i].payMethod==undefined){
						data.data.data[i].payMethod="";
					}
					
					data.data.data[i].deliverTime=changeTime(data.data.data[i].deliverTime);
					data.data.data[i].createTime=changeTime(data.data.data[i].createTime);

					var stringContent="";
						stringContent +='<tr class="workitem">'
	                    stringContent +='<td>'+data.data.data[i].createTime+'</td>'
	                    stringContent +='<td class="workitemsrc">'+data.data.data[i].resource.resourceName+'</td>'
	                    stringContent +='<td> <span class="worktel">'+data.data.data[i].resource.professor.name+'<!--<span class="worktelbtn"></span>--></span></td>'	                    
	                    stringContent +='<td>'+data.data.data[i].deliverTime+'</td>'      
	                    //stringContent +='<td class="price2">'+data.data.data[i].dealPrice+'</td>'     
	                    //stringContent +='<td>'+data.data.data[i].payMethod+'</td>'       
	                    stringContent +='<td><span>'+inq+'</span>/<span>'+data.data.data[i].dealPrice+'</span><br></td>'     
	                    stringContent +='<td><div class="loginStatus"></div></td></tr>'
	                   $(".worktabb").append( stringContent);						
									if($(".price2").eq(i).text()==0){
										$(".price2").eq(i).text("");
									}
							switch(data.data.data[i].operationStatus)
							{
							case 1:
								var string='<span>申请已发送待对方确认</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>修改申请</span><br />'
								string+='</a>'
									$(".loginStatus").eq(i).html(string);
							  break;
							case 2:
								var string='<span>对方发来报价</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>回复报价</span><br />'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);
							  break;
							case 3:
								var string='<span>合作进行中</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+' dealPrice='+data.data.data[i].dealPrice+'>查看详情</span><br />'
								string+='<span class="payMonety"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+' dealPrice='+data.data.data[i].dealPrice+'>付款</span><br />'
								string+='<span class="stopcoo"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>中止合作</span>'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);								
							  break;
							case 4:
								var string='<span>本人拒绝合作</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>查看详情</span><br />'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);
							  break;
							case 5:
								var string='<span>对方拒绝合作合作结束</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>查看详情</span><br />'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);
							  break;
							case 6:
								var string='<span>本人中止合作</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+' dealPrice='+data.data.data[i].dealPrice+'>查看详情</span><br />'
								//string+='<span class=" discuss"dataStatus="0"resourceId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>评价</span><br />'
								string+='<span class="complain"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>投诉</span>'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);
							  break;
							case 7:
								var string='<span>合作进行中</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+' dealPrice='+data.data.data[i].dealPrice+'>查看详情</span><br />'
								string+='<span class="acknowledgement"resourceId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>确认完成</span><br />'
								string+='<span class="complain"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>投诉</span>'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);
							  break;
							case 8:
								var string='<span>完成</span><br/>'
								string+='<a class="opbtn">'
								string+='<span class="detailm"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+' dealPrice='+data.data.data[i].dealPrice+'>查看详情</span><br />'
								//string+='<span class="discuss"dataStatus="0"resourceId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>评价</span><br />'
								string+='<span class="complain"resourId='+data.data.data[i].resource.resourceId+' operationStatus='+data.data.data[i].operationStatus+' operationId='+data.data.data[i].operationId+'>投诉</span>'
								string+='</a>'
								$(".loginStatus").eq(i).html(string);
							  break;
							default:							  
							}	
					}
				if(data.data.total == 0){	
					
				}else{
					if(isbind == true)
					{
						$(".tcdPageCode1").createPage({
					        pageCount:Math.ceil(data.data.total/pageSize),
					        current:data.data.pageNo,
					        backFn:function(p){								        	
					        	getPageData(pageSize,p,false);
					        },								      
					    });
					 }
				}
				
			}
			else
			{
				$.MsgBox.Alert('message',"系统异常!");
			}
	},
	"error":function(){$.MsgBox.Alert('message','failddd')}
});
}
getPageData(6,1,true);
//确认完成
$("#workmysrc2").on("click",".acknowledgement",function(){	
	  opo=$(this).attr("operationId");
	  n=8;
	 $.MsgBox.Confirm("消息", "确认合作完成?",upStatus);	 	 	 	 
})
//退款
$(".workmysrc").on("click",".drawback",function(){
	 DetailInfo();
	 $(".resoubox").css("display","none");
	 $(".liuyaninfo").css("display","none");
	 $(".pingjiainfo").css("display","none");
	 var op=$(this).attr("operationId");
	 opo=op;
	 var $price=$(this).attr("dealPrice");
	 $("#totalPrice").text($price);	
	 discussGetPaidMoney(opo,$price);
	
	 $("#paytit").on("click",".ret",function(){	
		 var payStatus=$(this).attr("payStatus");
		 console.log(payStatus);
		if(payStatus==0){
			payHistoryId=$(this).attr("payhistoryid");
			getPayhistoryData();
		}			
		});
		function getPayhistoryData(){
			$.ajax({		
			"url":"/ajax/payhistory/status",
			"type":"post",
			"async": true,
			"data":{"payHistoryId":payHistoryId,"payStatus":"1"}, 
			"success":function(data)
			{
				if(data.success)
					{	
					$("#paytit").find(".payitem").remove();
					 discussGetPaidMoney(opo,$price);
					}
					else
					{
						$.MsgBox.Alert('message',"系统异常!");
					}
			},
			"error":function(){$.MsgBox.Alert('message','failddd')}
		});
		}		
		 $(".panbtn").click(function(){	
			 var payed= Number($("#realCharge").text());//已经收到的付款
			 var paying= Number($("#payMoney").val());//此次正在付入金额
			 //alert(payed+","+paying);
			 
			if(paying <= payed)
				{
					$.MsgBox.Confirm("消息", "确定退款吗？",getPay1)
				 }
			if(paying > payed){
					 $.MsgBox.Alert('消息',"您所退的款项有误，请核对您已经收到的款项");
				}
			 });
	
});
//付款
function getPay(){
	$.ajax({"url" : "/ajax/payhistory",
		"type" : "POST",
		"success" : function(rdata) 
		{
			if (rdata.success) 
			{
			
			$(".blackcover").remove();
			$("body").css("position","static");			
				getPageData(6,1,false);																	
			}
			else 
			{
				$.MsgBox.Alert('消息',"付款失败!");							
			}
		},
		"data" :{"operationId":opo,"paidMoney":$("#payMoney").val(),
				"remark":$("#payRemark").val(),"payStatus":$("#payStatus").val(),"professorId":userid,
				"isonline":$("#isOnline").find("option:selected").val()},			
		"contentType" :"application/x-www-form-urlencoded",
		"beforeSend":function(){},
		dataType : "json"
	});
}
//退款
function getPay1(){
	$.ajax({"url" : "/ajax/payhistory",
		"type" : "POST",
		"success" : function(rdata) 
		{
			if (rdata.success) 
			{
			$(".blackcover").remove();
			$("body").css("position","static");
				getDataResource();						
			}
			else 
			{
				$.MsgBox.Alert('消息',"付款失败!");							
			}
		},
		"data" :{"operationId":opo,"returnMoney":$("#payMoney").val(),
				"remark":$("#payRemark").val(),"payStatus":$("#payStatus").val(),"professorId":userid,
				"isonline":$("#isOnline").find("option:selected").val()},			
		"contentType" :"application/x-www-form-urlencoded",
		"beforeSend":function(){},
		dataType : "json"
	});
}
$(".workmysrc").on("click",".payMonety",function(){
	 DetailInfo();
	 $(".resoubox").css("display","none");
	 $(".liuyaninfo").css("display","none");
	 $(".pingjiainfo").css("display","none");
	  opo=$(this).attr("operationId");
	 var $price=$(this).attr("dealPrice");
	 $("#totalPrice").text($price);	
	 discussGetPaidMoney(opo,$price);
	 $("#paytit").on("click",".ret",function(){	
		 var payStatus=$(this).attr("payStatus");
		 console.log(payStatus);
		if(payStatus==0){
			payHistoryId=$(this).attr("payhistoryid");
			getPayhistoryData();
		}			
		});
		function getPayhistoryData(){
			$.ajax({		
			"url":"/ajax/payhistory/status",
			"type":"post",
			"async": true,
			"data":{"payHistoryId":payHistoryId,"payStatus":"1"}, 
			"success":function(data)
			{
				if(data.success)
					{	
					$("#paytit").find(".payitem").remove();
					 discussGetPaidMoney(opo,$price);
					}
					else
					{
						$.MsgBox.Alert('message',"系统异常!");
					}
			},
			"error":function(){$.MsgBox.Alert('message','failddd')}
		});
		}
		 $("#panaddbtn").click(function(){				
			 var aa= Number($("#payMoney").val());	
			var bb=Number($("#balance").text());			
			 if(aa<bb){	
				 
					$.MsgBox.Confirm("消息", "确定支付吗？",getPay);
					 $.MsgBox.Alert('消息',"此次付款成功!");	
					
			 }
			 if(aa>bb){
				 $.MsgBox.Alert('消息',"所付款项已经超出预计款项!");
			 }
			 if(aa==bb){
				
				 $.MsgBox.Confirm("消息", "确定支付吗？",getPay);	
					n=7;
					 upStatus();
					 $.MsgBox.Alert('消息',"款项已经全部付清!");
			 }
			 });
	
	
});
function inquiryGetPaidMoney(operationId){	
	var realCharge=0,balance=0;
	$.ajax({	
	"url":"/ajax/payhistory/qadetail",
	"type":"get",
	"async": false,
	"data":{"operationId":operationId},		
	"success":function(data){
		if(data.success)
		{			
			var $data=data.data;
			var m;
			for(var i=0;i<$data.length;i++)
				{										
					if($data[i].paidMoney==undefined)
					{
						$data[i].paidMoney=0;
					}
					if($data[i].returnMoney==undefined)
					{
						$data[i].returnMoney=0;
					}
					m=$data[i].paidMoney-$data[i].returnMoney;																				
					realCharge+=m;
				}						
			
			}
			else
			{
				//console.log("系统异常!");
			}
	},
	"error":function(){$.MsgBox.Alert('message','failddd')}
	});
	return realCharge;
}
//获取订单付款历史记录
function discussGetPaidMoney(operationId,priceDifference){	
	var realCharge=0,balance=0;
	$.ajax({	
	"url":"/ajax/payhistory/qadetail",
	"type":"get",
	"async": true,
	"data":{"operationId":operationId},		
	"success":function(data){
		if(data.success){
			//console.log(data);
			var popHtml="";
			var $data=data.data;
			var m;
			for(var i=0;i<$data.length;i++){
				if($data[i].paidMoney==undefined)
				{
					$data[i].paidMoney=0;
				}
				if($data[i].returnMoney==undefined)
				{
					$data[i].returnMoney=0;
				}
				if($data[i].remark==undefined)
				{
					$data[i].remark="--";
				}
				
				PopHtml = '<tr class="payitem">';
				PopHtml += '<td><div class="resouinforcon">'+changeTime($data[i].createTime)+'</div></td>';
				PopHtml += '<td><div class="resouinforcon">'+$data[i].professor.name+'</div></td>';
				PopHtml += '<td><div class="resouinforcon resou"></div></td>';
				PopHtml += '<td><div class="resouinforcon to"></div></td>';
				if(userid==$data[i].professor.id){
					PopHtml += '<td><div class="resouinforcon resta"></div></td>';
				}else{
					PopHtml += '<td><div class="resouinforcon resta ret"payHistoryId='+$data[i].payHistoryId+' payStatus='+$data[i].payStatus+'></div></td>';
				}				
				PopHtml += '<td><div class="resouinforcon">'+$data[i].remark+'</div></td>';
				PopHtml += '</tr>';
				$("#paytit").append(PopHtml);
				
				
				m=$data[i].paidMoney-$data[i].returnMoney;				
				$(".to").eq(i).text(m);
				
				if($data[i].isonline==0){
					$(".resou").eq(i).text("线上支付");
				}else{
					$(".resou").eq(i).text("线下支付");
				}
				if($data[i].payStatus==0){
					$(".resta").eq(i).text("未确认");
				}else{
					$(".resta").eq(i).text("确认收款");
				}
				popHtml="";				
				realCharge+=m;
			}			
			balance=priceDifference-realCharge;			
			$("#balance").text(balance);
			$("#realCharge").text(realCharge);
			}
			else
			{
				//console.log("系统异常!");
			}
	},
	"error":function(){$.MsgBox.Alert('message','failddd')}
	});
}
//中止合作
$(".workmysrc").on("click",".stopcoo",function(){
	opo=$(this).attr("operationId");
	n=6;
	$.MsgBox.Confirm("消息", "你确定要中止吗？",upStatus); 
});
//评论
var start;
$(".workmysrc").on("click",".discuss",function(){
	var resourceId=$(this).attr("resourceId");	
	var operationId=$(this).attr("operationId");
	var dataStatus=$(this).attr("dataStatus");	
	getAssess1(operationId);
	CommentInfo();
	if(lengths==0&&dataStatus==0){
		$(".sqlcomment").css("display","none");
		$(".evastar2").click(function(){
			$(".evastar2").removeClass('span');
			start=$(this).index()+1;
			for(var i=0;i<start;i++){
				if(i<start){
					$(".evastar2").eq(i).addClass("span");
				}
				else{
					$(".evastar2").eq(i).removeClass('span');
				}
			}
		});
		$("#discuss").click(function(){
			//discussContent(resourceId,operationId,start,userid);
			$.ajax({	
				"url":"/ajax/assess",
				"type":"post",
				"async": true,
				"data":{"operationId":operationId,"professorId":userid,"resourceId":resourceId,"starLevel":start,"descp":$("#discussContent").val()},
				"success":function(data){
				if(data.success)
					{	
					location.reload(true);
					}
					else
					{
						//console.log("系统异常!");
					}
				},
				"beforeSend":function(){/*console.log(this.data)*/},
				"error":function(){$.MsgBox.Alert('message','failddd')}
				});
		})
	}else if(lengths==0&&dataStatus==1){
		$(".addcomment").css("display","none");
		var string='<tr><td><div class="righteva"><div class="noconmment">对方还未评价</div></div></div></td></tr>';
		$("#commbox").append(string);
	}else if(lengths==1&&dataStatus==0){
		$(".addcomment").css("display","none");
		getAssess(operationId,1);
	}else if(lengths==1&&dataStatus==1){
		getAssess(operationId,1);	
		$(".evastar2").click(function(){
			$(".evastar2").removeClass('span');
			start=$(this).index()+1;
			for(var i=0;i<start;i++){
				if(i<start){
					$(".evastar2").eq(i).addClass("span");
				}
				else{
					$(".evastar2").eq(i).removeClass('span');
				}
			}
		});
		$("#discuss").click(function(){
			//discussContent(resourceId,operationId,start,userid);
			$.ajax({	
				"url":"/ajax/assess",
				"type":"post",
				"async": true,
				"data":{"operationId":operationId,"professorId":userid,"resourceId":resourceId,"starLevel":start,"descp":$("#discussContent").val()},
				"success":function(data){
				if(data.success)
					{													
					}
					else
					{
						//console.log("系统异常!");
					}
				},
				"beforeSend":function(){/*console.log(this.data)*/},
				"error":function(){$.MsgBox.Alert('message','failddd')}
				});
		})
	}else if(lengths==2){
		$(".addcomment").css("display","none");
		getAssess(operationId,2);
	}
	
	
	
})
var  lengths;
//获取每条记录的评论
function getAssess1(operationId){
	$.ajax({"url" : "/ajax/assess/qaoper",
		"type" : "get",
		"async":false,
		"success" : function(rdata) 
		{
			if (rdata.success) 
			{
					//console.log(rdata);
					 lengths=rdata.data.length;								 
			}
			else 
			{
				//alert("jjj");
			}
		},
		"data" :{"operationId":operationId},
		"contentType" :"application/x-www-form-urlencoded",
		dataType : "json"
	});
}
function getAssess(operationId,le){
	$.ajax({"url" : "/ajax/assess/qaoper",
		"type" : "get",
		"async":true,
		"success" : function(rdata) 
		{
			if (rdata.success) 
			{					
					 $data=rdata.data;
					 if(le==1){
						 var string="";
							string+='<div class="ass"><tr><td><div class="teamwork"><div class="lefteva"><a href="" class="evaimg"><img src="images/default-photo.jpg" width="100%" height="100%"></a>'
							string+='<p>'+ $data[0].professor.name +'</p></div>'			
							string+='<div class="righteva"><ul class="evasort">'			
							string+='<li class="teamname"><span>'+$data[0].resource.resourceName+'资源的合作</span><span class="teamtime">2016-09-06</span></li></ul>'					
							string+='<div class="evastarbox"><span class="evastar evastar1"></span><span class="evastar evastar1"></span><span class="evastar evastar1"></span><span class="evastar evastar1"></span><span class="evastar evastar1"></span></div>'						
							string+='<p class="evabrief">'+$data[0].descp+'</p>'						
							string+='</div></div></td></tr>'
							string+='<tr><td><div class="righteva"><div class="noconmment">对方还未评价</div></div></div></td></tr></div>'								
							$("#commbox").append(string);
							//console.log($data[0].starLevel);
							for(var i=0;i<$data[0].starLevel;i++)
							{
								//console.log(i);
							$(".evastar1").eq(i).addClass('span');
							}
					 }else if(le==2){
						 for(var j=0;j<2;j++){
							 var string="";
								string+='<div class="ass"><tr><td><div class="teamwork"><div class="lefteva"><a href="" class="evaimg"><img src="images/default-photo.jpg" width="100%" height="100%"></a>'
								string+='<p>'+ $data[j].professor.name +'</p></div>'			
								string+='<div class="righteva"><ul class="evasort">'			
								string+='<li class="teamname"><span>'+$data[j].resource.resourceName+'资源的合作</span><span class="teamtime">2016-09-06</span></li></ul>'					
								string+='<div class="evastarbox"><span class="evastar evastar1"></span><span class="evastar evastar1"></span><span class="evastar evastar1"></span><span class="evastar evastar1"></span><span class="evastar evastar1"></span></div>'						
								string+='<p class="evabrief">'+$data[j].descp+'</p>'						
								string+='</div></div></td></tr></div>'															
								$("#commbox").append(string);
								if(j==0)
								{
									for(var i=0;i<$data[j].starLevel;i++)
									{
										//console.log(i);
										$(".evastar1").eq(i).addClass('span');
									}
								}
								else{
									for(var i=0;i<$data[j].starLevel;i++)
									{
										//console.log(i);
										$(".evastar1").eq(i+5).addClass('span');
									}
								}
								string="";
						 }
					 }
			}
			else 
			{
				//alert("jjj");
			}
		},
		"data" :{"operationId":operationId},
		"contentType" :"application/x-www-form-urlencoded",
		dataType : "json"
	});
}
function discussContent(){
	$.ajax({	
"url":"/ajax/assess",
"type":"post",
"async": true,
"data":{"operationId":operationId,"professorId":userid,"resourceId":resourceId,"starLeval":start,"descp":$("#discussContent").val()},
"success":function(data){
if(data.success)
	{
		location.reload(true);
	}
	else
	{
		//console.log("系统异常!");
	}
},
"error":function(){$.MsgBox.Alert('message','failddd')}
});
}
//我的需求中修改申请，对方已经回复(合作)，我拒绝合作或者约对方合作
function getIdentity(professorId){		
	$.ajax({	
	"url":"ajax/professor/"+professorId,
	"type":"get",
	"async": false,
	"success":function(data){
		if(data.success)
		{																				
			$("option")[0].value=data.data.name;
			$("option")[1].value=data.data.organization.name;			
		}
		else
		{
			$.MsgBox.Alert("消息","系统异常!");
		}
	},
	"error":function(){$.MsgBox.Alert('message','failddd')}
	})	
}
$(".workmysrc").on("click",".detailm",function(){
	var resourceId=$(this).attr("resourId");
	var operationStatus=$(this).attr("operationStatus");
	var operationId=$(this).attr("operationId");
	var priceDifference=$(this).attr("dealPrice");
	
	flag=1;
	opo=operationId;
	if(flag==1&&operationStatus==1)
	{ 
		ResourceApply();
		$(".limitBox").removeClass("limitBox");
        $(".limitwords").removeClass("limitwords");
        $(".limitwordbox").removeClass("limitwordbox");
		
		$( "#datepicker" ).datepicker({ "dateFormat":" yy-mm-dd"});

		$(".stateinfor span").text("修改申请中");
		$(".btnboxup").css({"display":"none"});
		$(".applysure").css({"display":"none"});
		ajaxGet(operationId,1,1);
		getIdentity(userid);
		//if($(".dealTime").val()!=""&&$(".detail").val()!="")
		//{
			$("#deliver").on("click",function()
					{	
						var $data = {};
						$data.demandId = userid;
						$data.resourceId = resourceId;
						$data.operationId=operationId;
						$data.detailDemand=$(".detail").val();						
						$data.deliverTime=replaceStr($.trim($("#datepicker").val()));
						$data.applysquare=$("select option:selected").val();
						$data.operationStatus=1;						
						$.ajax({
							"url" : "/ajax/operation",
							"type" : "put",
							"success" : function(rdata) {
								if (rdata.success){
									getPageData(6,1,false);
									$(".blackcover").remove();
									$("body").css("position","static");
									$.MsgBox.Alert('消息',"资源申请信息修改成功");									
								} else {
									$.MsgBox.Alert('消息',"资源申请信息修改失败");
								}
							},
							"data" : JSON.stringify($data) ,
							"contentType" :"application/json",							
							dataType : "json"
						});
				});
		//}
		
	}
	if(flag==1&&operationStatus==2)
	{		
		ResourceApply();

		ajaxGet1(operationId);
		
		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});			
		$(".stateinfor span").text("回复报价中");
		$(".btnboxup").css({"display":"none"});
		$(".btnboxdown").css({"display":"block"});
		$(".applysure").css({"display":"block"});
		$(".bag").css("display","none");	
		$(".sendpri").text("");
		$("#payMethod").replaceWith("<span id='payMethod'><span>");
		$("#dealPrice").replaceWith("<span id='dealPrice'><span>");
		$("#consultContent").replaceWith("<span id='consultContent'><span>");
		$("#del")[0].value="合作";
		$("#reject")[0].value="直接拒绝";		
		$("#reject").click(function(){
			n=4;
			$(".blackcover").remove();
			$("body").css("position","static");
			$.MsgBox.Confirm("消息", "确定继续吗？",upStatus);
		})
		$("#del").click(function(){
			 n=3;
			 $(".blackcover").remove();
			$("body").css("position","static");
			upStatus();
		})
	}
	if(flag==1&&operationStatus==3){
		DetailInfo();
		$("#totalPrice").text(priceDifference);
		$(".liuyaninfo").css("display","none");		
		$(".pingjiainfo").css("display","none");
		$(".filebox").css("display","none");
		ajaxGet1(operationId);
		$(".payaddbox1").css("display","none");

		discussGetPaidMoney(operationId,priceDifference);
	}
	if(flag==1&&operationStatus==4){
		ResourceApply();
		ajaxGet1(operationId);

		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});
		$(".sendpri").text("");		
			$(".stateinfor span").text("详情");
			$(".resde").text("详情页面");
			$(".btnboxup").css({"display":"none"});
			$(".btnboxdown").css({"display":"block"});
			$(".applysure").css({"display":"block"});
			$(".bag").css("display","none");
			$(".addrebtn").css("display","none");
			$("#payMethod").replaceWith("<span id='payMethod'><span>");
			$("#dealPrice").replaceWith("<span id='dealPrice'><span>");
			$("#consultContent").replaceWith("<span id='consultContent'><span>");		
	}
	if(flag==1&&operationStatus==5){
		ResourceApply();
		ajaxGet(operationId);

		$(".stateinfor").find("span").text("合作结束");
		$(".dealTime").replaceWith("<span class='dealTime'></span>");
		$(".detail").replaceWith("<span class='detail'></span>");
		$("select").replaceWith("<span class='sname'></span>")
		$(".btnboxdown").css({"display":"none"});
		$(".applysure").css({"display":"none"});
		//$(".resouinfotype2").text("");
		$(".addrebtn").css("display","none");
	}
	if(flag==1&&operationStatus==6){
		DetailInfo();	
		$("#totalPrice").text(priceDifference);
		$(".filebox").css("display","none");
		$(".liuyaninfo").css("display","none");		
		$(".pingjiainfo").css("display","none");
		$(".filebox").css("display","none");
		ajaxGet1(operationId);
		$(".payaddbox1").css("display","none");

		discussGetPaidMoney(operationId,priceDifference)
	}
	if(flag==1&&operationStatus==7){
		DetailInfo();	
		$("#totalPrice").text(priceDifference);
		$(".liuyaninfo").css("display","none");		
		$(".pingjiainfo").css("display","none");
		$(".filebox").css("display","none");
		ajaxGet1(operationId);
		$(".payaddbox1").css("display","none");

		discussGetPaidMoney(operationId,priceDifference)
	}
	if(flag==1&&operationStatus==8){
		DetailInfo();	
		$("#totalPrice").text(priceDifference);
		$(".liuyaninfo").css("display","none");		
		$(".pingjiainfo").css("display","none");
		$(".filebox").css("display","none");
		ajaxGet1(operationId);
		$(".payaddbox1").css("display","none");

		discussGetPaidMoney(operationId,priceDifference)
	}
})
//获取评论
function discussGetContent(operationId){
	$.ajax({	
	"url":"/ajax/assess/qaoper",
	"type":"get",
	"async": true,
	"data":{"operationId":operationId},		
	"success":function(data){
		if(data.success){
				//console.log(data);
			}
			else
			{
				//console.log("系统异常!");
			}
	},
	"error":function(){$.MsgBox.Alert('message','failddd')}
	});
}
//更新状态
function upStatus(){
	$.ajax({"url" : "/ajax/operation/operationStatus",
		"type" : "POST",
		"success" : function(rdata) 
		{
			if (rdata.success) 
			{		
			getPageData(6,1,false);
			}					
			else 
			{
				$.MsgBox.Alert('message','状态更新失败');
			}
		},
		"data" :{"operationId":opo,"operationStatus":n},
		"beforeSend":function(){/*console.log(this.data)*/},
		"contentType" :"application/x-www-form-urlencoded",
		dataType : "json"
	});
}
function upStatus1(){
	$.ajax({"url" : "/ajax/operation/operationStatus",
		"type" : "POST",
		"success" : function(rdata) 
		{
			if (rdata.success) 
			{	
				getDataResource();			
			}
			else 
			{
				$.MsgBox.Alert('message','状态更新失败');
			}
		},
		"data" :{"operationId":opo,"operationStatus":n},
		"beforeSend":function(){/*console.log(this.data)*/},
		"contentType" :"application/x-www-form-urlencoded",
		dataType : "json"
	});
}
//我的需求，获取每条记录的数据根据合作id
function ajaxGet(operationId,o,p){
	$.ajax({	
		"url":"/ajax/operation/"+operationId,
		"type":"get",
		"async": true,

		"success":function(data){
			if(data.success)
				{
				//console.log(data);
					$(".log").text(data.data.resource.resourceName);
					$(".timelog").text(changeTime(data.data.createTime));
					$(".contration").text(data.data.operationId);
					$(".detail").text(data.data.detailDemand);
					if(o==1&&p==1){
						$(".dealTime").val(changeTime(data.data.deliverTime));
					}else{
						$(".dealTime").text(changeTime(data.data.deliverTime));
					}
					if(data.data.professor.name==data.data.applysquare){						
						$("select").find("option[title=个人]").attr("selected",true);						
					}else{						
						$("select").find("option[title=所属机构]").attr("selected",true);						
					}
					$(".sname").text(data.data.applysquare);
					$(".namecon").text(data.data.resource.professor.name);
					$(".resouImage").attr("src","/images/resource/"+data.data.resource.resourceId+".jpg");
					$(".resouImage").load(function(){})
						.error(function(){
							$(this).attr("src","/images/default-resource.jpg");
						});	
					
					if(data.data.payMethod){
						$("#payMethod").val(data.data.payMethod);
					}
					if(data.data.dealPrice){
						$("#dealPrice").val(data.data.dealPrice);
					}
					if(data.data.replyNotes){
						$("#consultContent").val(data.data.replyNotes);
					}
					//根据内容的多少获取高度给父级设置高度
					limitHeight();
				}
				else
				{
					//console.log("系统异常!");
				}
		},
		"error":function(){$.MsgBox.Alert('message','failddd')}
	});
}
function ajaxGet1(operationId){
	$.ajax({	
		"url":"/ajax/operation/"+operationId,
		"type":"get",
		"async": true,

		"success":function(data){
			if(data.success)
				{//console.log(data);
					$(".log").text(data.data.resource.resourceName);
					$(".timelog").text(changeTime(data.data.createTime));
					$(".contration").text(data.data.operationId);
					$(".detail").text(data.data.detailDemand);
					$(".dealTime").text(changeTime(data.data.deliverTime));
					$(".namecon").text(data.data.resource.professor.name);
					$(".sname").text(data.data.applysquare);
					$(".resouImage").attr("src","/images/resource/"+data.data.resource.resourceId+".jpg");
					$(".resouImage").load(function(){})
						.error(function(){
							$(this).attr("src","/images/default-resource.jpg");
						});	
					if(data.data.payMethod){
						$("#payMethod").text(data.data.payMethod);
					}
					if(data.data.dealPrice){
						$("#dealPrice").text(data.data.dealPrice);
					}
					if(data.data.replyNotes){
						$("#consultContent").text(data.data.replyNotes);
					}
					//根据内容的多少获取高度给父级设置高度
					limitHeight();
				}
				else
				{
					//console.log("系统异常!");
				}
		},
		"error":function(){$.MsgBox.Alert('message','failddd')}
	});
}



	/*科研资源菜单点击切换*/
	$(".worksamlltit1").click(function(){
		var index = $(this).index();	
		$(this).addClass("worksamlltitnow").siblings().removeClass("worksamlltitnow");	
		$(".workmysrc1").eq(index).show().siblings().hide();
	});


});