
var PageSize = 30;//每页计数
var CurrentPage = 1; //当前页

$(document).ready(function() {
	$('#loadingContainer').ajaxStart(function(){$(this).show();}).ajaxStop(function(){$(this).hide();});
	setInterval(function(){
        $('div.sub_container_page').css('top',$(window.parent.frames.right).height()-$('div.sub_container_page').height()-2); //设置底部分页区域的位置
        $('div.sub_container_content').css('height',$(window.parent.frames.right).height()-$('div.sub_container_title').height()-$('div.sub_container_operation').height()-$('div.sub_container_listhead').height()-$('div.sub_container_page').height()); //设置内容区域的高度
    },1000);
    
    $('[@name=chkAll]').click(function(){
        $('[@name=chkItem]').attr('checked',$(this).attr('checked'));
    });
    $('#btnDelete').click(function(){
        var IDs = '';
        $('input[@name=chkItem][@checked]').each(function(){
            IDs += $(this).val() + ',';
        });
        if(IDs != ''){
            if(!confirm('确定要删除选择的记录吗?')){return false;};
            IDs = IDs.substring(0,IDs.length-1);
            Delete(IDs);
        }else{
            alert('请选择要删除的记录');
        };
    });
    
    $('#ddlStatus').change(function(){
        $('#txtKeywords').val('');
        $('#btnSearch').click();
    });
    
    $('#btnSearch').click(function(){
        CurrentPage = 1;
        BindList();
    });
 
	BindList();		
});

//绑定数据
function BindList(){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:'PayNotify.aspx?NoCopyRight=1&type=ajax&Action=GetList&PageSize=' + PageSize + '&Page=' + CurrentPage + '&SearchType='+$('#ddlSearchType').val() + '&keyword=' +escape($.trim($('#txtKeywords').val())) + '&Status=' + $('#ddlStatus').val(),
        cache:false,
        success:function(msg){
            $('tr:gt(0)','#datas').remove();
            $('input[@name=chkAll]').attr('checked',false);
            var data = msg.PayNotify;
            $.each(data,function(i,n){
               var row = $('#template').clone();
               row.show().mouseover(function(){$(this).addClass('on')}).mouseout(function(){$(this).removeClass('on')});
               row.find('#checkbox').html('<input type="checkbox" name="chkItem" value="'+n.PayNotifyID+'" />');
               row.find('#orderno').html(n.OrderNo);
               row.find('#member').text(n.MemberName);
               row.find('#amount').text(n.Amount);
               row.find('#payerbank').text(n.PayerBank);
               row.find('#receivebank').text(n.ReceiverBank);
               row.find('#paytime').text(n.PayTime);
               row.find('#status').html(GetStatusText(n.Status));
               row.find('#detail').html('<span class="hand" status="' + n.Status + '">详细</span>')
                    .find('span')
                    .click(function(){
                        var obj = $(this);
                        $('#popupContact').popup({width:'60%',height:'400',popupHead:'popupHead',btnClose:'popupClose'});
                        $('#d_orderno').text(n.OrderNo);
                        $('#d_membername').text(n.MemberName);
                        $('#d_amount').text(n.Amount);
                        $('#d_paytime').text(n.PayTime);
                        $('#d_payerbank').text(n.PayerBank);
                        $('#d_receivebank').text(n.ReceiverBank);
                        $('#d_payeraccount').text(n.PayerAccount);
                        $('#d_receiveaccount').text(n.ReceiverAccount);
                        $('#d_payername').text(n.PayerName);
                        $('#d_receivername').text(n.ReceiverName);
                        $('#d_addtime').text(n.AddTime);
                        if(n.Attach != ''){
                            $('#d_attach').html('<a href="../upload/PayNotify/' + n.Attach + '" target="_blank">'+n.Attach+'</a>');
                        }else{
                            $('#d_attach').html('');
                        };
                        $('#d_remark').text(n.Remark);
                        $('[@name=status][@value=' + obj.attr('status') + ']').attr('checked','checked');
                        if(obj.attr('status') == '0'){
                            $('[@name=status]').removeAttr('disabled');
                            $('#btnSave').removeAttr('disabled');
                        }else{
                            $('[@name=status]').attr('disabled','disabled');
                            $('#btnSave').attr('disabled','disabled');
                        };
                        
                        $('#btnSave').unbind().click(function(){
                            var curStatus = $('[@name=status][@checked]').val();
                            $.ajax({
                                url:'PayNotify.aspx?NoCopyRight=1&type=ajax&action=ChangeStatus&ID=' + n.PayNotifyID + '&Status=' + curStatus,
                                cache:false,
                                success:function(data){
                                    if(!checkLoginStatus(data)){return false;};
                                    if(data == '1'){
                                        row.find('#status').html(GetStatusText(curStatus));
                                        obj.attr('status',curStatus);
                                        $('#popupContactClose').click();
                                    };
                                },error:function(){alert('error');}
                            });
                        });
                    });
               row.find('#delete').html('<span class="hand">删除</span>')
                    .find('span')
                    .click(function(){
                        if(confirm('确定要删除吗？')){
                            Delete(n.PayNotifyID);
                        };
                    });

               row.attr('id','item_'+i).appendTo($('#datas'));
            });
           
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "EventLog.aspx",//[url]
               {style:pagerStyle,mark:"pageDataList1Mark",
               totalCount:msg.totalCount,showPageNumber:3,pageCount:PageSize,currentPageIndex:CurrentPage,noRecordTip:" 没有记录",preWord:"上一页",nextWord:"下一页",
               onclick:"CurrentPage={pageindex};BindList();return false;"}//[attr]
            );
        },//end success
        error:function(XMLHttpRequest,textStatus){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!');}else{alert(textStatus)};}
    });//end ajax
};//end funciton

function Delete(id){
    $.ajax({
        url:'PayNotify.aspx?type=ajax&Action=Delete&IDs=' + id,
        cache:false,
        success:function(data){
            if(!checkLoginStatus(data)){return false;}
            BindList();
        },
        error:function(){alert('error');}
    });//end ajax
};

function GetStatusText(status){
   var statustext = '';
   if(status == '0'){
    statustext = '<span style="color:Red">未确认</span>';
   }else if(status == '1'){
    statustext = '<span style="color:blue">通过</span>';
   }else if(status == '2'){
    statustext = '<span style="color:Gray">不通过</span>';
   };
   return statustext;
}