EditorGrid

/**
 * Created by IntelliJ IDEA.
 * User: Sartner
 * Date: 11-10-12
 * Time: 上午11:18
 * To change this template use File | Settings | File Templates.
 */
Ext.onReady(function() {
    Ext.BLANK_IMAGE_URL = '${pageContext.request.contextPath}/images/default/s.gif';
    Ext.QuickTips.init();
    Ext.form.Field.prototype.msgTarget = 'side';

    // --------------------  params  --------------------
    var _baseParams = {};

    var _paramPropertyArchivesId = GridInitUtil.getParamByName('propertyArchive_propertyArchivesId_EQUAL_Int');
    if (_paramPropertyArchivesId) {
        _baseParams['propertyArchive_propertyArchivesId_EQUAL_Int'] = _paramPropertyArchivesId;
    }
    var _stockNumber_GT_Double = GridInitUtil.getParamByName('stockNumber_GT_Double');
    if (_stockNumber_GT_Double) {
        _baseParams['stockNumber_GT_Double'] = _stockNumber_GT_Double;
    }

    var _stockNumber_LT_Double = GridInitUtil.getParamByName('stockNumber_LT_Double');
    if (_stockNumber_LT_Double) {
        _baseParams['stockNumber_LT_Double'] = _stockNumber_LT_Double;
    }


    //-----------------------------------------------------

    var stockJsonReader = new Ext.data.JsonReader({
        idProperty:'stockId',
        totalProperty : 'total',
        root : 'datas'
    }, [
        {name:'stock.stockId',mapping:'stockId'},
        {name:'stock.propertyArchive.propertyArchivesId',mapping:'propertyArchive_propertyArchivesId'},
        {name:'stock.propertyArchive.propertyName',mapping:'propertyArchive_propertyName'},
        {name:'stock.stockDate',mapping:'stockDate'},
        {name:'stock.stockNumber',mapping:'stockNumber'},
        {name:'stock.remainderStockNumber',mapping:'remainderStockNumber'},
        {name:'stock.receiverId',mapping:'receiverId'},
        {name:'stock.receiverName',mapping:'receiverName'},
        {name:'stock.remarks',mapping:'remarks'},
        {name:'storeType',mapping:'storeType'},
        {name:'stock.contractPrice',mapping:'contractPrice'},
        {name:'outStockAmount',mapping:'outStockAmount'},
        {name:'stock.propertyButStockId',mapping:'propertyButStockId'}
    ]);

    var stockStore = new Ext.data.Store({
        proxy : new Ext.data.HttpProxy({
            url : rootPath + '/stockAction!findAll.hx',
            method:'post'
        }),
        //remoteSort :true,
        reader : stockJsonReader
    });
    stockStore.baseParams=_baseParams;
    stockStore.on('load', function(_store, options) {
        setOutStockAmountTitle();
    });
    stockStore.load();

    var stockCM = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer,
        {
            header : '库存记录ID',
            dataIndex : 'stock.stockId',
            hidden:true
        },{
            header : '资产档案ID',
            dataIndex : 'stock.propertyArchive.propertyArchivesId',
            hidden:true
        },{
            header : '资产名称',
            dataIndex : 'stock.propertyArchive.propertyName'
        },{
            header : '出入库时间',
            width:60,
            dataIndex : 'stock.stockDate'
        },{
            header : '合同分项价',
            width:60,
            hidden:true,
            dataIndex : 'stock.contractPrice'
        },{
            header : '出入库数量',
            width:60,
            dataIndex : 'stock.stockNumber',
            renderer:function(value) {
                return Math.abs(value);
            }
        },{
            header : '剩余库存量',
            width:60,
            dataIndex : 'stock.remainderStockNumber'
        },{
            header : '出入库人ID',
            dataIndex : 'stock.receiverId',
            hidden:true
        },{
            header : '出入库人',
            dataIndex : 'stock.receiverName'
        },{
            header : '备注',
            dataIndex : 'stock.remarks',
            hidden:true
        },{
            header : '注明',
            width:30,
            dataIndex : 'storeType',
            hidden:true,
            renderer:function(value, metadata, record) {
                var stockNum = record.get('stock.stockNumber');
                if (stockNum < 0)
                    return '出库';
                else
                    return '入库';
            }
        }, {
            header : '采购审批ID',
            hidden:true,
            dataIndex : 'stock.propertyButStockId'
        }, {
            header : '<span id="outAmountSpan" style="color: red;">出库数量 (总计:0) </span>',
            dataIndex : 'outStockAmount',
            editor:{
                xtype:'numberfield',
                minValue:0,
                allowNegative :false,
                allowDecimals :false
            }
        }
    ]);

    stock_grid = new Ext.grid.EditorGridPanel({
        viewConfig : {
            forceFit : true
        },
        region:'center',
        cm:stockCM,
        store:stockStore,
        clicksToEdit :1,
        bbar : new Ext.PagingToolbar({
            pageSize : 20,
            store : stockStore,
            displayInfo : true,
            displayMsg : '显示第 {0} 条到第 {1} 条, 共 {2} 条记录 ',
            emptyMsg : '没有记录'
        })
    });

    var setOutStockAmountTitle = function() {
        outCount = 0;
        stockStore.each(function(record) {
            var _temp = record.get('outStockAmount');
            if (_temp) {
                outCount += (record.get('outStockAmount') - 0);
            }
        });
        document.getElementById('outAmountSpan').innerHTML = '出库数量 (总计:' + outCount + ')';
    }

    stock_grid.on('afteredit', function(e) {
        var _value = e.value;
        var _editRecord = e.record;
        var _remainderStockNumber = _editRecord.get('stock.remainderStockNumber');
        if (_value > _remainderStockNumber) {
            _value = _remainderStockNumber;
        }
        _editRecord.set('outStockAmount', _value);
        setOutStockAmountTitle();
    });

    // --------------------  view  --------------------

    var viewport = new Ext.Viewport({
        layout:'border',
        items:[stock_grid]
    });

})

 
阅读更多
个人分类: Ext
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭