ack-pagination.ctrl.js 2.93 KB
Newer Older
eddie.woo's avatar
eddie.woo committed
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
commonModule.
controller('ackPaginationController', ['SweetAlert', '$scope', '$log', '$translate', '$location', '$timeout', '$interval', '$uibModal', '$document', 'InvoiceManageService',
    function (SweetAlert, $scope, $log, $translate, $location, $timeout, $interval, $uibModal, $document, InvoiceManageService) {

        //分页的设置
        $scope.pagingOptions = {
            pageIndex: $scope.pageOptions.pageIndex || 1,  //当前页码
            totalItems: $scope.pageOptions.totalItems || 0,  //总数据
            totalPages: $scope.pageOptions.totalPages || 0,//总页数
            maxSize: $scope.pageOptions.maxSize || 10, //分页数字的限制。
            pageSize: $scope.pageOptions.pageSize || constant.page.pageSizeArrary[1],  //每页多少条数据 
            pageSizeString: constant.page.pageSizeArrary[1].toString(),
            firstPage: '<<', //$translate.instant('PagingFirstPage'),
            previousPage: '<', //$translate.instant('PagingPreviousPage'),
            nextPage:'>',// $translate.instant('PagingNextPage'),
            lastPage: '>>', //$translate.instant('PagingLastPage'),
        };

        //赋值
        $scope.pageOptions = $scope.pagingOptions;
        $scope.hideSelector = $scope.hidePageSizeSelector ? true : false;

        var refreshDataTable = function () {
       
            if (_.isFunction($scope.refreshTable)) {
                $scope.refreshTable();
            }
        };

        //分页里面的处理
        $scope.pagingService = {
            //分页下拉组装
            populatePagingSelection: function () {
                var pagingSelection = [];
                var pageArray = constant.page.pageSizeArrary;
                for (var i = 0 ; i < pageArray.length; i++) {
                    var selection = { id: pageArray[i], value: pageArray[i] };
                    pagingSelection.push(selection);
                }
                $scope.pageOptions.pagingSelection = pagingSelection;
            },

            //分页的时候改变数字
            pageIndexChanging: function () {
                if ($scope.pageOptions.pageIndex > $scope.pageOptions.totalPages) {
                    $scope.pagingOptions.pageIndex = $scope.pageOptions.totalPages;
                }
                if ($scope.pageOptions.pageIndex <= 0) {
                    $scope.pageOptions.pageIndex = 1;
                }

                $log.log('Page changed to: ' + $scope.pageOptions.pageIndex);
                refreshDataTable();
            },

            //每页显示的数据下拉改变
            pageSizeSelectionChanged: function () {
                $scope.pageOptions.pageSize = parseInt($scope.pageOptions.pageSizeString);
                refreshDataTable();
            },
        };



        (function initialize() {
            $log.debug('ackPaginationController.ctor()...');

            $scope.pagingService.populatePagingSelection();
        
        })();
    }
]);