﻿
$(document).ready(function() {
	BindList('Page=1');
});

//绑定数据
function BindList(urldata){
//    return false;
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:baseUrl + 'ProductAsk.aspx?NoCopyRight=1&type=GetList&PID='+productID + '&PageSize=' + PageSize,
        data:urldata,
        cache:false,
        success:function(msg){
            $('div.item:gt(0)','#AskContent').remove();
            var data = msg.ProductAsk;
            $.each(data,function(i,n){
               
               var row = $('#template').clone().show();
               row.find('.name').text('网友：'+n.MemberName);
               row.find('.group').text(n.GroupName);
               row.find('.asktime').text(n.AddTime);
               row.find('.ask').html(n.Body);
               row.find('.answbody').html(n.Reply);
               row.find('.answtime').html(n.ReplyTime);
               var objYesNum = row.find('.yesnum').text(n.YesNum);
               var objNotNum = row.find('.notnum').text(n.NotNum);
               
               row.find('.vote_y').click(function(){
                    var result = VoteAsk(n.ProductAskID,1);
                    if(result == '1'){
                        objYesNum.text(Number(objYesNum.text())+1);
                    }else if(result == '2'){
                        alert('不能重复投票!');
                    };
               });
               row.find('.vote_n').click(function(){
                    var result = VoteAsk(n.ProductAskID,0);
                    if(result == '1'){
                        objNotNum.text(Number(objNotNum.text())+1);
                    }else if(result == '2'){
                        alert('不能重复投票!');
                    };
               });
               
               if((i%2)==1){row.addClass('itemeven');}else{row.addClass('itemodd');};
               
               row.attr('id','item_'+i).appendTo($('#AskContent'));
            });
           
           if(showpage){
                //分页
                $('.sub_container_page').show();
                var pagerStyle = "flickr";//jPagerBar样式
                ShowPageBar("pageDataList1_Pager",//[containerId]
                   "ProductAsk.aspx",//[url]
                   {style:pagerStyle,mark:"pageDataList1Mark",
                   totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:" 暂无咨询",preWord:"上一页",nextWord:"下一页",
                   onclick:"CurrentPage={pageindex};BindList('Page={pageindex}');return false;"}//[attr]
                );
            };
        },//end success
        error:function(XMLHttpRequest,textStatus){alert(textStatus);}
    });//end ajax
};//end funciton

function VoteAsk(paid,val){
    var result = '0';
    $.ajax({
        type:"get",
        url:shopFolder + 'ProductAsk.aspx?NoCopyRight=1&type=Vote&PAID='+paid+'&val='+val + '&r='+Math.random(),
        async:false,
        success:function(data){
            if(data == 'NOLOGIN'){
                if(confirm('登录后才可以投票,是否现在登录')){
                    window.location.href= shopFolder + 'login.aspx?ReturnUrl='+window.location.href;
                }else{
                    return false;
                }
            };
            result = data;
        },error:function(){alert('error');}
    });
    return result;
};
