Source: control/PagingBar.js

/**
 * Created by seeker910 on 2017/6/16.
 */
Rsd.define('Rsd.control.PagingBar', {
    extend: 'Rsd.control.ToolBar',
    requires:[
        'Rsd.control.NumberIndex',
        'Rsd.control.Svg'
    ],
    xtype: 'paging-bar',
    cls: 'x-paging-bar',
    margin: '5 0 5 0',
    position:'0 0 0 0',
    width: '100%',
    header: false,
    height: 40,
    svgs:{
        first:{
            viewBox:"0 0 1024 1024",
            path:"M842.666667 864c-8.533333 0-14.933333-2.133333-21.333334-8.533333l-341.333333-309.333334c-6.4-6.4-10.666667-14.933333-10.666667-23.466666 0-8.533333 4.266667-17.066667 10.666667-23.466667l341.333333-309.333333c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133333 44.8L548.266667 522.666667l315.733333 285.866666c12.8 10.666667 14.933333 32 2.133333 44.8-6.4 6.4-14.933333 10.666667-23.466666 10.666667zM512 864c-8.533333 0-14.933333-2.133333-21.333333-8.533333L149.333333 546.133333c-6.4-6.4-10.666667-14.933333-10.666666-23.466666 0-8.533333 4.266667-17.066667 10.666666-23.466667L490.666667 189.866667c12.8-12.8 34.133333-10.666667 44.8 2.133333 12.8 12.8 10.666667 34.133333-2.133334 44.8L217.6 522.666667 533.333333 808.533333c12.8 12.8 14.933333 32 2.133334 44.8-6.4 6.4-14.933333 10.666667-23.466667 10.666667z"
        },
        previous:{
            viewBox:"0 0 1024 1024",
            path:"M384 512L731.733333 202.666667c17.066667-14.933333 19.2-42.666667 4.266667-59.733334-14.933333-17.066667-42.666667-19.2-59.733333-4.266666l-384 341.333333c-10.666667 8.533333-14.933333 19.2-14.933334 32s4.266667 23.466667 14.933334 32l384 341.333333c8.533333 6.4 19.2 10.666667 27.733333 10.666667 12.8 0 23.466667-4.266667 32-14.933333 14.933333-17.066667 14.933333-44.8-4.266667-59.733334L384 512z"
        },
        next:{
            viewBox:"0 0 1024 1024",
            path:"M731.733333 480l-384-341.333333c-17.066667-14.933333-44.8-14.933333-59.733333 4.266666-14.933333 17.066667-14.933333 44.8 4.266667 59.733334L640 512 292.266667 821.333333c-17.066667 14.933333-19.2 42.666667-4.266667 59.733334 8.533333 8.533333 19.2 14.933333 32 14.933333 10.666667 0 19.2-4.266667 27.733333-10.666667l384-341.333333c8.533333-8.533333 14.933333-19.2 14.933334-32s-4.266667-23.466667-14.933334-32z"
        },
        last:{
            viewBox:"0 0 1024 1024",
            path:"M544 522.666667c0-8.533333-4.266667-17.066667-10.666667-23.466667L192 189.866667c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733334 285.866667L149.333333 808.533333c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466667 10.666667 8.533333 0 14.933333-2.133333 21.333333-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666zM864 499.2l-341.333333-309.333333c-12.8-12.8-34.133333-10.666667-44.8 2.133333-12.8 12.8-10.666667 34.133333 2.133333 44.8l315.733333 285.866667-315.733333 285.866666c-12.8 12.8-14.933333 32-2.133333 44.8 6.4 6.4 14.933333 10.666667 23.466666 10.666667 8.533333 0 14.933333-2.133333 21.333334-8.533333l341.333333-309.333334c6.4-6.4 10.666667-14.933333 10.666667-23.466666 0-8.533333-4.266667-17.066667-10.666667-23.466667z"
        }
    },
    //indexChanged:'',
    pagingOpt:{pageSize:100,pageIndex:0,pageCount:0,totalCount:0},
    /**
     * @description 分页大小 列表
     */
    pageSizeList:[20,50,100,200],
    items: [
        {xtype: 'svg', tip: '第一页',handler:'firstPage',border:true, cls: ['x-btn', 'x-first'], width: 30, label:{visible:true}},
        {xtype: 'svg', tip: '上一页', handler:'previousPage',border:true, cls: ['x-btn','x-previous'], width: 30, label:{visible:true}},
        {xtype: 'number-index',id:'_pageNumber',header:{visible:false}, width: 260,selectedChanged:'goTo', margin: '0 2 0 2'},
        {xtype: 'svg', tip: '下一页', handler:'nextPage',border:true,cls: ['x-btn','x-next'], width: 30, label:{visible:true}},
        {xtype: 'svg', tip: '最后一页',handler:'lastPage',border:true,cls:['x-btn','x-last'], width: 30,label:{visible:true}},  
        {
            xtype: 'combobox', id:'_pageSize',
            tip: '用于分页的每页记录条数值',
            label:{text:'每页记录数:',position:'left',width:100},
            selectedItemChanged:'onPageSizeChanged',
            margin: '0 2 0 2',
            height:30,
            border:false,
            value:100,
            dataSource:[{text:20,value:20},{text:50,value:50},{text:100,value:100}],
            width: 170
        },
        {xtype: 'label', id: '_pageCount',label:{content:'跳转至',position:'right'},text: '共 {0} 页,',cls:'x-label', border: false, width:110,height:30},
        {xtype: 'text',id:'_padeIndex', tip: '要跳转到的页码', label:{content:'页',position:'right',width:30,space:5},height:26,width: 90},
        {xtype: 'link', tip: '点击跳转到指定页',label:null,text:'【转到】',handler:'setPageIndex',style:{textAlign: 'center'}, width:80,height:30},
        {xtype: 'label', id: '_msg', text: '信息',cls:'x-label', border: false, flex:250,height:30} 
    ],
    /**
     *
     *  */
    constructor: function PagingBar(config) {
     
        config = config || {};
        this.apply(config);

        this.items[0].dataSource = this.svgs['first'];
        this.items[1].dataSource = this.svgs['previous'];
        this.items[3].dataSource = this.svgs['next'];
        this.items[4].dataSource = this.svgs['last'];

        var list = this.pageSizeList||[];
        var _ds = [];
        for(var i in list)
        {
            if(Rsd.isObject(list[i]))
            {
                _ds.push({text:list[i].text,value:list[i].value});
            }
            else
            {
                _ds.push({text:list[i],value:list[i]});
            }
            
        }
        this.getItemById('_pageSize').dataSource = _ds;
         
    },
    /**
    *
     */
    goTo:function goTo(index) {

        var _pagingOpt = this.getPaging();
        var _index = index - 1;
        if(_pagingOpt.pageIndex == _index)
        {
            return ;
        }
        _pagingOpt.pageIndex = _index;

        if (Rsd.isString(this.indexChanged)) {
            this.funApplyByIOC(this.indexChanged, [_pagingOpt]);
        }

        if (Rsd.isFunction(this.indexChanged)) {
            this.indexChanged.call(this, _pagingOpt);
        }
    },
    /**
     * */
    previousPage: function () {

        if (this.pagingOpt.pageIndex > 0) {
            this.goTo(this.pagingOpt.pageIndex - 1);
        }
        else {
            Rsd.showPopup("已经是第一页");
        }
    },
    /**
     * 
     */
    nextPage: function () {

        if (this.pagingOpt.pageIndex < (this.pagingOpt.pageCount - 1)) {
            this.goTo(this.pagingOpt.pageIndex + 1);
        }
        else {
            Rsd.showPopup("已经是最后一页");
        }

    },
    /**
     * 
     */
    firstPage: function () {
        if (this.pagingOpt.pageIndex == 0) {
            Rsd.showPopup("已经是第一页");
            return;
        }
        this.goTo(1);
    },
    /**
     * 
     */
    lastPage: function () {

        if (this.pagingOpt.pageIndex == this.pagingOpt.pageCount - 1) {
            Rsd.showPopup("已经是最后一页");
            return;
        }
        this.goTo(this.pagingOpt.pageCount);
    },
    /**
     * 
     */
    setPageIndex:function()
    {
        var _pIndex = this.getItemById('_padeIndex').value;
        if(!Rsd.isNumber(_pIndex))
        {
            Rsd.showMessage("输入页码不是有效值。");
            return ;
        }

        this.goTo(_pIndex);
    },
    /**
    *
    * */
    onPageSizeChanged:function onPageSizeChanged(v,e)
    {
        if(v)
        {
            this.pagingOpt.pageSize = v.value||100;
        }

    },
    /**
    * */
    getPaging:function getPaging() {
        return this.pagingOpt;
    },
    /**
    *
    * */
    setPaging:function setPaging(pagingOpt) {

        Rsd.apply(this.pagingOpt, pagingOpt);
        delete this.pagingOpt.where;
        delete this.pagingOpt.sort;

        var _pIndex = this.pagingOpt.pageIndex ||0;
        var _pSize = this.pagingOpt.pageSize || 100;
        var _pCount = this.pagingOpt.pageCount;
        var _total = this.pagingOpt.totalCount;

        var number = this.getItemById('_pageNumber');
        number.value = _pIndex + 1;
        var _list = [];
        for(var i=0;i< _pCount ;i++)
        {
            _list.push(i+1);
        }
        number.valueList = _list; 
        number.bind();

        var _s = _pIndex * _pSize + 1;
        var _e =_pSize + _pIndex * _pSize;
        var _t = _total;
        if(_e > _t)
        {
            _e = _t;
        }

        this.getItemById('_msg').setText('{0}-{1} / {2}'.format(_s,_e,_t ));
        this.getItemById('_pageCount').setText('共'+_pCount+'页,') ;
        this.getItemById('_pageSize').setValue(_pSize) ;
    }

},function(type){
    var _indexChangedGetter = function () {

        return this.___indexChanged;
    };

    var _indexChangedSetter = function (value) {

        this.___indexChanged = value;

    }

    this.defineProperty(type,"indexChanged", _indexChangedGetter, _indexChangedSetter,false);

});