
var PageSize = 20;//每页计数
var CurrentPage = 1; //当前页
var isConfirm = 0;

$(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()); //设置内容区域的高度
    },100);
 
    $('input[@name=chkAll]').click(function(){$('input[@name=chkItem]').attr('checked',$(this).attr('checked'));});//全选
	
	isConfirm = getQueryStringRegExp('IsConfirm');
	BindList('Page='+CurrentPage);
	
	var titleInfo = '';
	if(isConfirm == 0){
	    titleInfo = '未确认申请';
	}else{
	    titleInfo = '已确认申请';
	};
	
	$('#titleinfo').text(titleInfo);
		
});

//绑定数据
function BindList(urldata){
    $('#template').hide();//将第一行模板隐藏
    $.ajax({
        type:"get",
        dataType:"json",
        url:'Repairs.aspx?NoCopyRight=1&type=ajax&Action=GetList&PageSize=' + PageSize + '&IsConfirm=' + isConfirm,
        data:urldata,
        cache:false,
        success:function(msg){
            $('tr:gt(0)','#datas').remove();
            var data = msg.Repair;
            $.each(data,function(i,n){
               var row = $('#template').clone();
               row.show().mouseover(function(){$(this).addClass('on')}).mouseout(function(){$(this).removeClass('on')});
               row.find('#ID').text(n.RepairID);
               row.find('#OrderNo').html(n.OrderNo);
               row.find('#ProductNo').html(n.ProductNo);
               row.find('#ProductName').html(n.ProductName);
               row.find('#RepairType').html(GetRepairType(n.RepairType));
               row.find('#MemberName').text(n.MemberName);
               row.find('#AddTime').text(n.AddTime);
               row.find('#Detail')
                    .html('<span class="hand span_reply" id="click_reply_' + n.RepairID + '">详细</span>')
                    .click(function(){
                        $('#frmdetail').attr('src','RepairDetail.aspx?ID='+n.RepairID);
                        $('#popupContact').popup({width:'80%',height:'500',popupHead:'popupHead',btnClose:'popupClose'});
                    });
               row.find('#Delete').html('<span class="hand">删除</span>').click(function(){
                    if(confirm('确定要删除吗?')){
                        Delete(n.RepairID);
                    };
               });
               row.attr('id','item_'+i).appendTo($('#datas'));
            });
           
            //分页
            $('.sub_container_page').show();
            var pagerStyle = "flickr";//jPagerBar样式
            ShowPageBar("pageDataList1_Pager",//[containerId]
               "Complaint.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){if(textStatus=='parsererror'){alert('身份已过期,请重新登陆!');}else{alert(textStatus)};}
    });//end ajax
};//end funciton

function GetRepairType(typeID){
    var result = '';
    switch(typeID){
        case '1':
            result = '返修';
        break;
        case '2':
            result = '换货';
        break;
    };
    return result;
};

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

function checkLoginStatus(data){
    var result = true;
    if(data.indexOf('<!DOCTYPE') != -1){
        result = false;
        alert('身份已过期,请重新登陆!');
    };
    return result;
};