﻿//alert("xx");
/*--------------全局控制----------------*/
//var debug=true;//测试开关/屏蔽错误  
var iPageSize_ListGoodsComment=5; //分页每页记录数
var iPageCount_ListGoodsComment=0;//分页总页数
var iCurrentPageRecord=0;//当前页的记录数
var iRecordCount_ListGoodsComment=0;//总记录数  
var CurrentPageIndex_ListGoodsComment=1 ;  //指示当前页
var requestData_ListGoodsComment=true;//当前是否是请求数据
/*--------------全局控制[end]----------------*/
/*----------------------------------------------------------------------
ajax请求,bCountData参数表示当前是统计数据还是获取数据
----------------------------------------------------------------------*/
function  Ajax_PageAbleRequest_ListGoodsComment(vGoodsID,vCurrentMemberID,iPageIndex,bCountData){
    //alert("here");
	if(bCountData)//统计数据
	{
		AjaxService.FrontListGoodsCommentByPageAble(vGoodsID,vCurrentMemberID,-1,-1,true,ListGoodsComment_GetAjaxResponse_CountData_callback);
	}
	else  //显示数据
	{
		AjaxService.FrontListGoodsCommentByPageAble(vGoodsID,vCurrentMemberID,iPageSize_ListGoodsComment,iPageIndex,false,ListGoodsComment_GetAjaxResponse_ReadData_callback);
	}
}
/*------------------------------------------------------------------------------
   处理ajax返回: 获得当前页数据记录，并显示
--------------------------------------------------------------------------------*/
function ListGoodsComment_GetAjaxResponse_ReadData_callback(response){
    //alert('处理返回');   
    var vReturnDataString="";
    var ds = response.value; 
    //alert(ds.Tables[0].Rows.length);
    if(ds != null && typeof(ds) == "object" && ds.Tables[0]!=null && ds.Tables != null)
    { 			
	    //alert(ds.Tables[0].Rows.length);
	    var s = new Array();  
	    for(var i=0; i<ds.Tables[0].Rows.length; i++)
	    {   
            var dr=ds.Tables[0].Rows[i];//当前行
	        var vSmallHeadportrait=dr.SmallHeadportrait;
	        var vUserName=dr.UserName;
	        var vCommentContent=dr.Message;
	        var vCommentDateTime=dr.CommentDateTime;
	        var vCommentContent=dr.CommentContent;
	        var vCommentReplyContent=dr.CommentReplyContent;
	        if(vCommentReplyContent=="")vCommentReplyContent="暂无";
            //每行数据处理
	        vReturnDataString+=ListGoodsComment_BindRowData(i,vSmallHeadportrait,vUserName,vCommentDateTime,vCommentContent,vCommentReplyContent);
        } 	        
	    //alert(vReturnDataString);    
	    $("divItemDetail_ListGoodsComment").innerHTML=vReturnDataString; 								 
    }
    else{
	    if(debug){
	     alert("Error. [3001] " + response.request.responseText);
	    }
    } 
}
    
/**每行数据处理*/
function ListGoodsComment_BindRowData(i,vSmallHeadportrait,vUserName,vCommentDateTime,vCommentContent,vCommentReplyContent)
{     
      //alert(vSmallHeadportrait);
      var s="";
	  s+= "<div>";
	  s+=       vSmallHeadportrait;
	  s+="<p><span>"+ShowFormatDateTime(vCommentDateTime)+" by <b>"+vUserName+"</b></span>";
	  s+= vCommentContent;
	  s+="<strong>客服回复:"+vCommentReplyContent+"</strong>";
	  s+= "</p></div>";  
	 return s;
}
/*------------------------------------------------------------------------------
   处理ajax返回:获得统计数据记录数的响应
--------------------------------------------------------------------------------*/
function ListGoodsComment_GetAjaxResponse_CountData_callback(response){
	var ds = response.value; 
	if(ds != null && typeof(ds) == "object" && ds.Tables != null)
	{ 
	    //总记录数
	    var vRecordCount=ds.Tables[0].Rows[0].RecordCount;//定义总记录数时候返回列名为RecordCount
	    //处理分页导航
	    ProcessDataPageNavigator_ListGoodsComment(vRecordCount,CurrentPageIndex_ListGoodsComment);
	}
	else{
	    if(debug){
		  alert("Error. [3001] " + response.request.responseText);
		}
	} 
}
/*------------------------------------------ajax[end]------------------------------------------*/
/*------------------------------------------ javascript分页------------------------------------------*/
//处理记录分页导航
function ProcessDataPageNavigator_ListGoodsComment(RecordCount,_PageIndex)
{
    iRecordCount_ListGoodsComment=RecordCount;//总记录数
    iPageCount_ListGoodsComment=Math.ceil(iRecordCount_ListGoodsComment/iPageSize_ListGoodsComment); //总页数
    
    changePage_ListGoodsComment(_PageIndex);//跳到第一页,0表示第一页
}
//[前一页]处理
function UpPageGo_ListGoodsComment(){ 
    if(CurrentPageIndex_ListGoodsComment>0) 
       CurrentPageIndex_ListGoodsComment--; 
     
    getContent_ListGoodsComment(); //获取数据
} 
//下一页处理
function NextPageGo_ListGoodsComment()
{ 
   if (CurrentPageIndex_ListGoodsComment<iPageCount_ListGoodsComment) 
        CurrentPageIndex_ListGoodsComment++;    
    getContent_ListGoodsComment(); //获取数据
} 

//分页导航字样
function pageBar_ListGoodsComment(_PageIndex)
{
    var pb="";
    //pb=UpPage(_PageIndex)+"  "+NextPage(_PageIndex)+"  "+currentPage()+"  "+allPage_ListGoodsComment()+"  "+allRecordCount_ListGoodsComment()+selectPage(); 
    //前一页
    if(_PageIndex>1) pb+="<A style='CURSOR: hand' onclick='Javascript:return UpPageGo_ListGoodsComment();'>前一页</A> ";
    else pb+="前一页 ";
    //后一页
    if(_PageIndex<iPageCount_ListGoodsComment) pb+="<A  style='CURSOR: hand' onclick='Javascript:return NextPageGo_ListGoodsComment();'>后一页</A> ";
    else pb+="后一页 ";
    //输出[当前页]字样
    //pb+=" 当前是第 "+(CurrentPageIndex_ListGoodsComment)+" 页";
    //输出[总共页]字样
    //pb+=' 总共 '+(iPageCount_ListGoodsComment)+' 页';
    //输出[总记录数]字样
    pb+=' 总共'+(iRecordCount_ListGoodsComment)+' 条记录';
    //下拉导航页
    pb+=selectPage_ListGoodsComment();
    return pb;
}

//跳到某一页处理
function changePage_ListGoodsComment(tpage)
{    
    //alert(tpage);
    CurrentPageIndex_ListGoodsComment=tpage
    if(CurrentPageIndex_ListGoodsComment>=1) CurrentPageIndex_ListGoodsComment--; 
    if (CurrentPageIndex_ListGoodsComment<iPageCount_ListGoodsComment) CurrentPageIndex_ListGoodsComment++;
    getContent_ListGoodsComment(); 
}

//显示下拉
function selectPage_ListGoodsComment()
{
    var sp="";
    sp=sp+"  第 ";
    sp=sp+"<select name='selPageIndex' onChange='javascript:changePage_ListGoodsComment(this.options[this.selectedIndex].value)'>";
    for (t=1;t<=iPageCount_ListGoodsComment;t++)
    {
        if(CurrentPageIndex_ListGoodsComment==t) //当前页
        {
           sp=sp+"<option value='"+t+"' selected>"+(t)+"</option>";
        }
        else
        {
            sp=sp+"<option value='"+t+"'>"+(t)+"</option>";
        }
    }
    sp=sp+"</select>"
    sp=sp+" 页";
    return sp;
}

//显示评论内容
function getContent_ListGoodsComment()
{
       if (!CurrentPageIndex_ListGoodsComment) CurrentPageIndex_ListGoodsComment=1;    
       if($("divItemDetail_PageNavigator_ListGoodsComment")) { 
            $("divItemDetail_PageNavigator_ListGoodsComment").innerHTML=pageBar_ListGoodsComment(CurrentPageIndex_ListGoodsComment); 
       }      
        
       if($("_hidGoodsID") && $("_hidCurrentMemberID") ){
          var vGoodsID=$("_hidGoodsID").value;
          var vCurrentMemberID=$("_hidCurrentMemberID").value;
          Ajax_PageAbleRequest_ListGoodsComment(vGoodsID,vCurrentMemberID,CurrentPageIndex_ListGoodsComment,false);//注意这里调用后台的时候，页码要从1开始(请参考存储过程)
       }
}
/*---------------- javascript分页[end]---------------------*/
/*显示商品的评价*/
function Ajax_Request_ListGoodsComment(){
     if($("_hidGoodsID") && $("_hidCurrentMemberID") ){
          //alert("here");
          var vGoodsID=$("_hidGoodsID").value;
          var vCurrentMemberID=$("_hidCurrentMemberID").value;
          Ajax_PageAbleRequest_ListGoodsComment(vGoodsID,vCurrentMemberID,CurrentPageIndex_ListGoodsComment,true);//注意这里调用后台的时候，页码要从1开始(请参考存储过程)
    }
}
/*显示商品的评价[end]*/

/**---------------------------- 评论商品处理 ----------------------------**/
//评论商品ajax 对话框
function CommentGoodsDialogShow(){
    ScreenConvert();
    if($("_hidGoodsID"))
    {
        var iGoodsID=$("_hidGoodsID").value;
        AjaxService.GetCommentGoodsAjaxDialogGUI(iGoodsID,CommentGoodsDialogShow_callback);
    }
}  
function CommentGoodsDialogShow_callback(response){
   var AJAX_DialogGUIHtml=response.request.responseText;
   AJAX_DialogGUIHtml=AJAX_DialogGUIHtml.substring(1,AJAX_DialogGUIHtml.length-1); //去掉前后的'号
   DialogShow(AJAX_DialogGUIHtml,350,200,400,250);//显示
}
function CommentGoodsProcess(){
   if($("_hidGoodsID") &&  $("txtCommentContent") )
   {
      var vGoodsID=$("_hidGoodsID").value;
      var vCommentContent=$("txtCommentContent").value;
       
      if(confirm("确定留言?!?"))
         AjaxService.DoCommentGoodsProcess(vGoodsID, vCommentContent,CommentGoodsProcess_callback);
   }
}
function CommentGoodsProcess_callback(response){
  var vRes=response.request.responseText;
  if(vRes.length>0)
      vRes=vRes.substring(1,vRes.length-1) ;
  if(vRes=="0")//成功
  {
     alert("留言成功,谢谢你的参与!");
     //changePage_ListGoodsComment(1);
     CurrentPageIndex_ListGoodsComment=1;
     getContent_ListGoodsComment(); 
     DialogHide(); 
  }
  else
  {
     alert(vRes);
     //alert("操作有错误发生,有可能是服务器不响应当前操作,请稍后操作。");
  }
}
/**---------------------------- 评论商品处理[end] ----------------------------**/

//格式化时间显示(显示位置时间)
function ShowFormatDateTime(d)
{
        if(d=="") return "";
		//alert(d.getYear()+" "+ d.getMonth()+" "+d.getDate());
		if(d.getYear()==0 && d.getMonth()==0 &&d.getDate()==1 )
	 	  return "";
	 	  
		var v;
		var year=d.getYear();
		var month=d.getMonth()+1;
		var day=d.getDate();
		v=year+"-"; 
		if(month<10){
			v+="0"+month+"-"; 
		}
		else{
			v+=month+"-"; 
		}	   
		if(day<10){
			v+="0"+day; 
		}
		else{
			v+=day; 
		}
		
	  h="0"+d.getHours(); 
      m="0"+d.getMinutes(); 
      s="0"+d.getSeconds(); 
      if(h>9){h=d.getHours()} 
      if(m>9){m=d.getMinutes()} 
      if(s>9){s=d.getSeconds()} 

      v+=" "+h+":"+m+":"+s;
		
		//alert(v);
		return v;
}