cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$.fn.wsinglePagination = function(_opts){
    var opts = $.extend({
        base : "",
        durl : "",
        mdiv : "",
        pdiv : "",
        perPage : 6,
        param : {},
        infoUrl : "/ewyw/ewKnowledge/ewKwinfo.html?id="
    },_opts);
    
    var status = {
        recordCount : 0,
        totalPage : 0
    };
    
    return this.each(function(){
        var currPage,panel = $(this).css({'text-align':'center'});
        
        function _loadData(json) {
            var result = json.DATALIST;
            var num = (currPage-1)*opts.perPage;
            var html = "";
            $.each(result,function(i,item) {
                html += "<li><a href='"+opts.base+opts.infoUrl+item.business_id+"'><span>"+(num+i+1)+".</span>"+item.title+"</a></li>"
            });
            
            $("#loading").remove();
            if(opts.mdiv)$('#'+opts.mdiv).append(html);
            _render();
        }
        
        function _loadPage(cpage,json){
            panel.html("<span>加载中</span>").unbind('click');
            currPage = cpage;
            if(!json) {
                opts.param = $.extend(opts.param,{currPage:cpage,pageSize:opts.perPage});
                $.post(opts.durl,opts.param,function(data){
                    _loadData(data);
                },'json');
            } else {
                _loadData(json);
            }
        }
        
        function _gotoPage(page){
            return function(){
                _loadPage(page);
            };
        }
        
        function _render(){
            if(currPage == status.totalPage){
                panel.html("没有了").unbind('click');
            }else{
                panel.html("<span>加载更多</span>").bind('click',_gotoPage(currPage+1));
            }
        }
        
        opts.param = $.extend(opts.param,{currPage:1,pageSize:opts.perPage});
        
        
        $('#'+opts.mdiv).append("<li id='loading'><div class='loading' ><img src='"+opts.base+"/static/wechat/images/loading.gif' /></div></li>");
        
        //开始执行
        $.post(opts.durl,opts.param,function(json){
            //每次新的查询,都移除panel的click事件
            panel.unbind('click');
            //设置翻页
            var total = json.total;
            if(total==0){
                panel.html("暂无数据").show();
            }else{
                status.recordCount = total;
                status.totalPage = Math.ceil(total/opts.perPage);
                //放置第一页
                _loadPage(1,json);
                //if(total>opts.perPage){
                //    $('#'+opts.pdiv).show();
                //}else{
                //    $('#'+opts.pdiv).hide();
                //}
                $('#'+opts.pdiv).show();
            }
        },'json');
    });
};