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
88
89
90
91
92
93
94
95
$.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) {
                if(item.big_category == 1) {
                    html += '<section class="klwrap1"><a href="'+opts.base+'/ewyw/ewKnowledge/ewKwinfo.html?id='+item.business_id+'"><h2>'+item.title+'</h2></a><h3>时间:'+item.update_time+'</h3><p>'+item.content+'</p><div class="klwrapkeyword">'+item.tag+'</div></section>';
                } else if(item.big_category == 2) {
                    html += '<section class="klwrap1"><a href="'+opts.base+'/ewyw/eworder/ewOrderInfo.html?orderType='+item.small_category+'&orderId='+item.business_id+'"><h2>'+item.title+'</h2></a><h3>时间:'+item.update_time+'</h3><p>'+item.content+'</p></section>';
                }
            });
            
            if(opts.mdiv)$('#'+opts.mdiv).append(html);
            
            _render();
            if(opts.dataHandler) {
                opts.dataHandler(html);
            }
        }
        
        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});
        
        
        
        
        panel.html("<span>加载中</span>").unbind('click');
        //开始执行
        $.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');
    });
};