wzp
2021-08-09 826bce65ac9b1e5dae43fc06974b8b1284f1d12c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
Pagination = function(options) {
    var _this = this;
    var _index = 1;
    var _size = 20;
    var _recordCount = 0;
    var _maxLinkCount = 5;
 
    this.setPageIndex = function(index) {
        _index = index;
    }
 
    this.setPageSize = function(size) {
        _size = size;
    }
 
    this.setRecordCount = function(recordCount) {
        _recordCount = recordCount;
    }
 
    this.getRecordCount = function() {
        return _recordCount;
    }
 
    this.getPageSize = function() {
        return _size;
    }
 
    this.getPageIndex = function() {
 
        if (_index > 0)
            return _index;
        else
            return 1;
    }
 
    this.getNextPageIndex = function() {
        if (_this.getPageIndex() < _this.getPageCount())
            return parseInt(_this.getPageIndex()) + 1;
        else
            return _this.getPageIndex();
    }
 
    this.getPrevPageIndex = function() {
        if (_this.getPageIndex() > 1)
            return parseInt(_this.getPageIndex()) - 1;
        else
            return _this.getPageIndex();
    }
 
    this.getPageCount = function() {
 
        if (_recordCount == 0)
            return 0;
 
        if (_recordCount <= _size)
            return 1;
 
        var _count = Math.floor(_recordCount / _size);
 
        if (_recordCount % _size > 0)
            _count = _count + 1;
 
        return _count;
    }
 
    this.getPageIndexJump = function() {
        var i = $("#Jump");
        if (i == "")
            return 1;
        else
            return i;
    }
 
    this.getHtml = function() {
 
        var begin = 1;
        var end = begin + _maxLinkCount;
 
        var b = _this.getPageIndex() > (Math.floor(_maxLinkCount / 2)); //前面
        var e = _this.getPageIndex() > (parseInt(_this.getPageCount()) - (Math.floor(_maxLinkCount / 2))); //后面
 
        if (b) {
            begin = parseInt(_this.getPageIndex()) - (Math.floor(_maxLinkCount / 2));
            end = begin + _maxLinkCount;
        }
        if (e) {
            begin = parseInt(_this.getPageCount()) - _maxLinkCount + 1;
            end = begin + _maxLinkCount;
        }
 
        if (begin <= 0)
            begin = 1;
 
        if (end >= parseInt(_this.getPageCount()) + 1)
            end = parseInt(_this.getPageCount()) + 1;
 
        //如果页面少于
        if (_maxLinkCount >= _this.getPageCount()) {
            begin = 1;
            end = parseInt(_this.getPageCount()) + 1;
        }
 
        var html = "<div>共 <span  class='label label-info'>" + _this.getRecordCount() + " </span>条信息 , <span  class='label label-info'>" + _this.getPageCount() + " </span>页</div><div class='pagination'>";
        if (_this.getPageCount() > 1) {
 
            if (_this.getPageCount() > _maxLinkCount) {
                if (_this.getPageIndex() > 1)
                    html += "<li><a href=\"javascript:\" data-index=\"" + 1 + "\">首页</a></li>";
 
                if (_this.getPageIndex() > 1)
                    html += "<li><a href=\"javascript:\" data-index=\"" + _this.getPrevPageIndex() + "\">上一页</a></li>";
            }
 
            for (var i = begin; i < end; i++) {
                if (i == _this.getPageIndex())
                    html += "<li class=\"active\"><a href=\"javascript:\" data-index=\"" + i + "\">" + i + "</a></li>";
                else
                    html += "<li><a href=\"javascript:\" data-index=\"" + i + "\">" + i + "</a></li>";
            }
 
            if (_this.getPageCount() > _maxLinkCount) {
                if (_this.getPageIndex() < _this.getPageCount()) {
                    html += "<li><a href=\"javascript:\" data-index=\"" + _this.getNextPageIndex() + "\">下一页</a></li>";
                }
 
                if (_this.getPageIndex() < _this.getPageCount()) {
                    html += "<li><a href=\"javascript:\" data-index=\"" + _this.getPageCount() + "\">尾页</a></li>";
                }
 
                html += "<input type=\"text\" id=\"Jump\" name =\"Jump\" /><a href=\"javascript:\" data-index=\"" + _this.getPageIndexJump() + "\">跳转</a></li>";
            }
 
 
        }
 
        html += "</div>"
 
        return html;
    }
}