js分頁 – Javascript教程_JS教程_技術文章 – 程式設計聯盟

function showSimplePageData(n){
          $("#simpleShowComp").hideLoading();
         $("#simpleShowComp table").html("");
        $('<tr class="tableTitle"><td>投訴日期</td><td>投訴類型</td><td>投訴個數</td></tr>').appendTo("#simpleShowComp table");
        $("#detailState").hide();
        $("#simpleState").show();
        //alert(simpleComplaintRecordList.simpleCurrData[0].complaintDate)
        for(var i=0,j=simpleComplaintRecordList.simpleCurrData.length;i<j;i++){ //consultationList.currData.length
            var data=simpleComplaintRecordList.simpleCurrData[i],elem;
            elem=$('<tr><td> '+(data.complaintDate==""?"&nbsp;":data.complaintDate)+'</td><td>'+complaintsType[data.complaintsType]+'</td><td>'+(data.count==""?"&nbsp;":data.count)+'</td></td></tr>').appendTo("#simpleShowComp table");
        }
/*        for(var i=consultationList.currData.length;i<7;i++){
            $('<dt></dt>').appendTo("#first_view dl");
            $('<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td class="tdend">&nbsp;</td></tr>').appendTo("#second_view table");
        }*/
         showSimplePages(n);
    }
/**
 * 顯示投訴記錄
 */
    function showSimplePages(curr){
         var showPages=5;
        var totalNum=simpleComplaintRecordList.simpleTotalNum;
        var totalPages=simpleComplaintRecordList.simpleTotalPages;
        var currData=simpleComplaintRecordList.simpleCurrData;
        var currPage=simpleComplaintRecordList.simpleCurrPage;
        //var type=consultationList.type;
        var beginPage=1,endPage=1;
        var quotient=Math.floor((curr-1)/showPages);
        beginPage=showPages*quotient+1;
        endPage=(beginPage+4)>totalPages?totalPages:(beginPage+4);
        if(beginPage>showPages && endPage-beginPage<showPages-1){ //保證如果總頁數大於showPages 則次顯示的頁數為showPages
             beginPage=endPage-showPages+1;
        }
        if(totalPages<1){
            beginPage=1,endPage=1,totalPages=1;
        }
        var html='<span class="number w400">';
         html+=curr==1?'<a title="第一頁">‹‹</a>':'<a class="valid" title="第一頁" href="javascript:goToSimplePage(1);">‹‹</a>';
        html+=curr==1?'<a title="上一頁">‹</a>':'<a class="valid" title="上一頁"  href="javascript:goToSimplePage(\'prev\');">‹</a>';
        for(var i=beginPage;i<=endPage;i++){
            html+=i==curr?('<a title="第 '+i+' 頁" class="cur">'+i+'</a>'):('<a class="valid"  title="第 '+i+' 頁"  href="javascript:goToSimplePage('+i+');">'+i+'</a>');
        }
        html+=curr==totalPages?'<a title="下一頁">›</a>':'<a class="valid" title="下一頁"  href="javascript:goToSimplePage(\'next\');">›</a>';
        html+=curr==totalPages?'<a title="最後一頁">››</a>':('<a class="valid" title="最後一頁"  href="javascript:goToSimplePage('+totalPages+');">››</a>');
        html+='</span>';
         html+='<a href="javascript:goToSimplePage(\'\');" class="goto"><!–go–></a> <input type="text" id="pagetextchange" class="pagetext"><span class="count">當前頁: '+curr+' / '+totalPages+'</span><span id="simpleSizeSpan" class="size">'+simpleComplaintRecordList.simplePageSize+'</span><span class="count">顯示條數:</span>';
        $("#simplePages_pg").html(html).find("span#simpleSizeSpan").click(function(e){
             if($("#simpleSize_style").is(":hidden")){
                $("#simpleSize_style").css({
                    left:$(this).offset().left,
                    top:$(this).offset().top-$("#simpleSize_style").height()-2,
                    width:$(this).width()+5
                }).show();
            }else{
                $("#simpleSize_style").hide();
            }
            e.stopPropagation();
        });
        simpleComplaintRecordList.simpleCurrPage=curr;
    }
    function goToSimplePage(n){
        if(simpleComplaintRecordList.request){
            return;
        }
        if(n=="prev"){
            n=simpleComplaintRecordList.simpleCurrPage-1;
        }else if(n=="next"){
            n=simpleComplaintRecordList.simpleCurrPage+1;
        }else if(n==""){
            n=$("#pagetextchange").val().replace(/\D/g,"");
            if(n==""){
                $("#pagetextchange").val("").focus();
                return false;
            }else{
                n=parseInt(n,10);
                $("#pagetextchange").val(n);
            }
         }
        if(n>simpleComplaintRecordList.totalPages){
            n=simpleComplaintRecordList.totalPages;
        }
        if(n<1){
            n=1;
        }
         $("#simplePages_pg").html("");
        $("#simpleShowComp").showLoading();
        if(type=="detail"){
            getPageData(n);
        }else if(type=="simple"){
            getSimplePageData(n);
        }else{
            getPageData(n);
        }
        
     }
    function getSimplePageData(n){ //noDoctor辨別是否是不選醫生的
        simpleComplaintRecordList.request=true; //標識數據正在請求   防止多次點擊
        simpleComplaintRecordList.simpleCurrData=[];
        var complaintsProcess_ID=$("#complaintsProcess_ID").val();//投訴流水號(投訴信息事件id)
        var complainant_personID=$("#complainant_personID").val();
        var checkStatus=$("input[name=checkStatus]:checked").val();
        var complaintDate=$("#complaintDate").val().replace("年","-").replace("月","-").replace("日","");
        var complaintsSource=$("#complaintsSource").val();
        var orderName=$("#orderName").val();
        /*var docId=$("#docId").val();
        var userId=$("#userId").val();
        var timeIndex=$("input[name=timeIndex]:checked").val();
        var sourceType=$("input[name=sourceType]:checked").val()||"0";*/
        var data={};
       
            data={simplePageSize:simpleComplaintRecordList.simplePageSize,complaintsSource:complaintsSource,orderName:orderName,currPage:n,complaintsProcess_ID:complaintsProcess_ID,complainant_personID:complainant_personID,checkStatus:checkStatus,complaintDate:complaintDate};
   
        /*if(sourceType==0){
               data={patientId:checkList.patientId,departmentId:depId,doctorId:docId,timeIndex:timeIndex,orderName:checkList.orderName,nowPage:n};
        }else{
            data={patientId:checkList.patientId,userId:userId,timeIndex:timeIndex,orderName:checkList.orderName,nowPage:n};
        }*/

        $.ajax({
            type:"POST",
            url:showSimpleRecordAction,
            data:data,
            dataType:"text",
            success:function(data){
                simpleComplaintRecordList.request=false; //標識數據請求結束
                var data=data.split("|");
                 var dataArr=eval("("+data[0]+")");
                 var type=Object.prototype.toString.apply(dataArr);
                 type=type.substring(8,type.length-1);
                 if(type!="Array"){
                     location.href="loginerror.jsp";
                     return;
                 }
                 simpleComplaintRecordList.simpleTotalNum=data[1];
                 simpleComplaintRecordList.simpleTotalPages=data[2];
                for(var i=0;i<dataArr.length;i++){
                    simpleComplaintRecordList.simpleCurrData[i]={complaintDate:dataArr[i].complaintDate,complaintsType:dataArr[i].complaintsType,count:dataArr[i].count};      
                }
                if(simpleComplaintRecordList.simpleCurrData.length==0){
                    //hideFunPanel1(0);hideFunPanel2(0); //隱藏可能的彈出層
                }
                showSimplePageData(n);
             },
             error:function(){
                 simpleComplaintRecordList.request=false; //標識數據請求結束
                //hideFunPanel1(0);hideFunPanel2(0);
                 alert("獲取數據失敗!");
             }
        });
    }

摘自 web前端wyy的專欄

發佈留言