| | |
| | | // 设置共有多少页
|
| | | TblPage.prototype._setNum = function() {
|
| | | this.num = Math.ceil(this.all/this.size);
|
| | | } |
| | | }
|
| | |
|
| | | // 定义页面中分页元素的对象
|
| | | var PagePage = function(opts) {
|
| | | this.search = ''; // 查询
|
| | | this.home = ''; // 首页
|
| | | this.pre = ''; // 上一页
|
| | | this.next = ''; // 下一页
|
| | | this.last = ''; // 尾页
|
| | | this.size = ''; // 每页显示条数
|
| | | this.num = ''; // 跳转的页数
|
| | | this.go = ''; // 页面跳转
|
| | | this.current = ''; // 当前页/总页数
|
| | | this.total = ''; // 数据总量
|
| | | this.page = opts.page; // 分页信息
|
| | | this._initDom(opts);
|
| | | this.callback = "";
|
| | | }
|
| | |
|
| | | // 设置PagePage的方法
|
| | | PagePage.prototype = {
|
| | | _initDom: function(opts) {
|
| | | this.search = this._getEle(opts.search);
|
| | | this.home = this._getEle(opts.home);
|
| | | this.pre = this._getEle(opts.pre);
|
| | | this.next = this._getEle(opts.next);
|
| | | this.last = this._getEle(opts.last);
|
| | | this.num = this._getEle(opts.num);
|
| | | this.go = this._getEle(opts.go);
|
| | | this.current = this._getEle(opts.current);
|
| | | this.total = this._getEle(opts.total);
|
| | | this.size = this._getEle(opts.size);
|
| | | //console.log(this.search);
|
| | | this.addEvent();
|
| | | }
|
| | | ,_getEle: function(ele) {
|
| | | //console.log(ele);
|
| | | var len = ele?ele.length:0;
|
| | | //console.log(len);
|
| | | var rsEle = len?ele:$('#PagePageTmp');
|
| | | return rsEle;
|
| | | }
|
| | | ,addEvent: function() {
|
| | | var _this = this;
|
| | | |
| | | // 点击查询
|
| | | this.search.off('click.PagePage.event').on('click.PagePage.event', function() {
|
| | | if(_this._checkCallback()) {
|
| | | _this.callback();
|
| | | } |
| | | });
|
| | | |
| | | // 点击首页
|
| | | this.home.off('click.PagePage.event').on('click.PagePage.event', function() {
|
| | | var Page = _this.page;
|
| | | if(Page.curr != 1){
|
| | | Page.setCurr(1);
|
| | | _this.callback();
|
| | | }
|
| | | });
|
| | | |
| | | // 点击上一页
|
| | | this.pre.off('click.PagePage.event').on('click.PagePage.event', function() {
|
| | | var Page = _this.page;
|
| | | if(Page.curr > 1){
|
| | | Page.setCurr(Page.curr-1);
|
| | | _this.callback();
|
| | | }
|
| | | });
|
| | | |
| | | // 点击下一页
|
| | | this.next.off('click.PagePage.event').on('click.PagePage.event', function() {
|
| | | var Page = _this.page;
|
| | | if(Page.num > Page.curr){
|
| | | Page.setCurr(Page.curr+1);
|
| | | _this.callback();
|
| | | }
|
| | | });
|
| | | |
| | | // 设置每页显示条数
|
| | | this.size.off('blur.PagePage.event').on('blur.PagePage.event', function() {
|
| | | var Page = _this.page;
|
| | | var value= $(this).val();
|
| | | //当输入的数大于0时
|
| | | if(value>0){
|
| | | if(value != Page.size){
|
| | | Page.setSize(parseInt(value));
|
| | | Page.setCurr(1);
|
| | | }
|
| | | }else{
|
| | | //当输入非法数字时
|
| | | alert("请输入合法的数字"); /* 请输入合法的整数 */
|
| | | $(this).val(Page.size); |
| | | }
|
| | | });
|
| | | |
| | | // 尾页
|
| | | this.last.off('click.PagePage.event').on('click.PagePage.event', function() {
|
| | | var Page = _this.page;
|
| | | if(Page.curr < Page.num){
|
| | | Page.setCurr(Page.num);
|
| | | _this.callback();
|
| | | }
|
| | | });
|
| | | |
| | | // 跳转
|
| | | this.go.off('click.PagePage.event').on('click.PagePage.event', function() {
|
| | | var Page = _this.page;
|
| | | var tarpage= _this.num.val();
|
| | | if(tarpage > Page.num){
|
| | | Page.setCurr(Page.num);
|
| | | }else if(tarpage > 0 && tarpage!= Page.curr){
|
| | | Page.setCurr(parseInt(tarpage));
|
| | | }
|
| | | _this.callback();
|
| | | });
|
| | | |
| | | }
|
| | | ,setCallback:function(callback) {
|
| | | this.callback = callback;
|
| | | }
|
| | | ,setPage: function(page) {
|
| | | this.page = page;
|
| | | }
|
| | | ,init:function(page, callback) {
|
| | | this.setPage(page);
|
| | | this.setCallback(callback);
|
| | | this.setVal();
|
| | | }
|
| | | ,setVal: function() {
|
| | | this.current.text(this.page.curr+'/'+this.page.num);
|
| | | this.total.text(this.page.all);
|
| | | this.size.val(this.page.size);
|
| | | }
|
| | | ,_checkCallback: function() {
|
| | | return typeof this.callback === 'function';
|
| | | }
|
| | | };
|
| | |
|