请问 如果 我想实现出库和入库和下面四个在一行显示怎么改?

来源:互联网 发布:淘宝零点抢购攻略 编辑:程序博客网 时间:2024/06/10 13:46
(function(){
    Ext.define('InventoryModelList', {
        extend : 'Ext.data.Model',
        idProperty : 'id',
        fields : [ {
            name : 'id',
            type : 'int'
        }, 'serialNum', 'shareName', 'venderName' ,'brandName','modelName', 'enabled',
            {
                name: 'userRealName',
                mapping: 'user.realName'
            },
            {
                name: 'agentRealName',
                mapping: 'agent.realName'
            },
            {
                name: 'productTitle',
                mapping: 'product.title'
            },
            'monthDeal',{
                name : 'createTime',
                type : 'date',
                dateFormat : 'Y-m-d H:i:s'
            },{
                name: 'releaseTime',
                type: 'date',
                dateFormat: 'Y-m-d H:i:s'
            },{
                name : 'type',
                type : 'boolean'
            },{
                name : 'status',
                type : 'int'
            }  ]
    });


    var store = Ext.create('Ext.data.Store', {
        model : 'InventoryModelList',
        autoLoad : true,
        remoteSort : true,
        pageSize : globalPageSize,
        proxy : {
            type : 'ajax',
            url : appBaseUri + '/sys/inventory/getInventoryList',
            // extraParams : me.extraParams || {},
            reader : {
                type : 'json',
                root : 'data',
                totalProperty : 'totalRecord',
                successProperty : "success"
            }
        },
        sorters : [ {
            property : 'id',
            direction : 'DESC'
        } ]
    });


    if(Ext.platformTags.classic){
        function getInventorySelection(grid){
            var result = {};
            var selected_items = grid.getSelectionModel().selected.items;
            if(selected_items.length == 0){
                return null;
            }
            result['serialNumStr'] = selected_items.map(function(v){return v.data.serialNum}).join(',');
            result['selected_ids'] = selected_items.map(function(v){return v.data.id});


            if(selected_items[0].data.agent != null){
                result['agentUserId'] = selected_items[0].data.agent.id;
            }
            if(selected_items[0].data.user != null){
                result['userId'] = selected_items[0].data.user.id;
            }
            if(selected_items[0].data.product != null){
                result['productId'] = selected_items[0].data.product.id;
            }


            return result;
        }


        Ext.define('App.AddInventoryWindow', {
            extend : 'Ext.window.Window',
            constructor : function(config) {
                config = config || {};
                var productSelector = Ext.create('Forestry.app.ui.Component.ProductSelector', {
                    fieldLabel: '产品类目',
                    name: 'product',
                    allowBlank: false
                });
                Ext.apply(config, {
                    title : '产品入库',
                    width : 350,
                    height : 400,
                    bodyPadding : '10 5',
                    modal : true,
                    layout : 'fit',
                    items : [ {
                        xtype : 'form',
                        fieldDefaults : {
                            labelAlign : 'left',
                            labelWidth : 90,
                            anchor : '100%'
                        },
                        items : [
                            {
                                name : "cmd",
                                xtype : "hidden",
                                value : 'new'
                            }, {
                                xtype : 'hiddenfield',
                                name : 'id'
                            }, {
                                xtype : 'combobox',
                                fieldLabel : '厂家',
                                valueField : 'ItemValue',
                                displayField : 'ItemText',
                                margin : '5,0,0,0',
                                typeAhead : false,
                                queryMode : 'remote',
                                emptyText : '请选择...',
                                allowBlank : true,
                                editable : false
                            }, {
                                xtype : 'combobox',
                                fieldLabel : '品牌',
                                name : 'shareArray',
                                id : 'cmbShare',
                                valueField : 'ItemValue',
                                displayField : 'ItemText',
                                margin : '5,0,0,0',
                                typeAhead : false,
                                queryMode : 'remote',
                                emptyText : '请选择...',
                                allowBlank : true,
                                editable : false
                            }, {
                                xtype : 'combobox',
                                fieldLabel : '型号',
                                valueField : 'ItemValue',
                                displayField : 'ItemText',
                                margin : '5,0,0,0',
                                typeAhead : false,
                                queryMode : 'remote',
                                emptyText : '请选择...',
                                allowBlank : true,
                                editable : false
                            },
                            productSelector,
                            {
                                xtype : 'textfield',
                                name : 'serialNum',
                                margin : '5,0,0,0',
                                fieldLabel : '序列号',
                                allowBlank: false,
                                maxLength : 16
                            },
                            {
                                xtype: 'numberfield',
                                name: 'count',
                                fieldLabel: '数量',
                                minValue: 1,
                                value: 1,
                                allowBlank: false
                            }
                        ],
                        buttons : [ '->', {
                            id : 'addinventorywindow-save',
                            text : '保存',
                            iconCls : 'icon-save',
                            width : 80,
                            handler : function(btn, eventObj) {
                                var window = btn.up('window');
                                var form = window.down('form').getForm();
                                if (form.isValid()) {
                                    window.getEl().mask('数据保存中,请稍候...');
                                    var vals = form.getValues();


                                    Ext.Ajax.request({
                                        url : appBaseUri + '/sys/inventory/saveInventory',
                                        params : {
                                            id : vals['id'],
                                            cmd : vals['cmd'],
                                            serialNum: vals['serialNum'],
                                            count: vals['count'],
                                            productId: vals['product']
                                        },
                                        method : "POST",
                                        success : function(response) {
                                            if (response.responseText != '') {
                                                var res = Ext.JSON.decode(response.responseText);
                                                if (res.success) {
                                                    var msg = res.message != null ? res.message : '操作成功';
                                                    Ext.Msg.alert('操作成功', msg);
                                                    Ext.getCmp('inventory-grid').getStore().reload();
                                                    window.close();
                                                } else {
                                                    Ext.Msg.alert('错误提示', res.message);
                                                }
                                            }
                                        },
                                        failure : function(response) {
                                            Ext.Msg.alert('错误提示', '操作失败!');
                                        }
                                    });
                                    window.getEl().unmask();
                                }
                            }
                        }, {
                            id : 'addinventorywindow-cancel',
                            text : '取消',
                            iconCls : 'icon-cancel',
                            width : 80,
                            handler : function() {
                                this.up('window').close();
                            }
                        }, '->' ]
                    } ]
                });
                App.AddInventoryWindow.superclass.constructor.call(this, config);
            }
        });


        Ext.define('Forestry.app.inventory.InventoryList', {
            extend : 'Ext.grid.Panel',
            id : 'inventory-grid',
            region : 'center',
            initComponent : function() {
                var me = this;


                var columns = [
                    {
                        text : '序列号',
                        dataIndex : 'serialNum',
                        width : 150
                    },{
                        text : '产品类目',
                        dataIndex : 'productTitle',
                        width : '10%'
                    },{
                        text : '厂家',
                        dataIndex : 'venderName',
                        width : '5%'
                    },{
                        text : '品牌',
                        dataIndex : 'brandName',
                        width : '5%'
                    },{
                        text : '型号',
                        dataIndex : 'modelName',
                        width : '5%'
                    },{
                        text : '代理商',
                        dataIndex : 'agentRealName',
                        width : '5%'
                    },{
                        text: '用户',
                        dataIndex:'userRealName',
                        width: '5%'
                    },{
                        text : '是否开通',
                        dataIndex : 'type',
                        width : '5%',
                        renderer: function(value){
                            return value ? '是' : '否';
                        }
                    },{
                        text : '状态',
                        dataIndex : 'enabled',
                        width : '5%',
                        renderer: function(value){
                            return value ? '已启用' : '未启用';
                        }
                    },{
                        text : '月交易额',
                        dataIndex : 'monthDeal',
                        width : '5%'
                    },{
                        text : '入库时间',
                        dataIndex : 'createTime',
                        width : '10%',
                        formatter: 'date("Y-m-d H:i:s")'
                    },{
                        text: '出库时间',
                        dataIndex: 'releaseTime',
                        width: '10%',
                        formatter: 'date("Y-m-d H:i:s")'
                    }];


                
                 var userSelector = Ext.create('Forestry.app.ui.Component.UserSelector', {
                    id: 'user_id',
                    fieldLabel: '用户',
                    userType: 'normal'
                });
                var agentSelector = Ext.create('Forestry.app.ui.Component.UserSelector', {
                    id: 'agent_id',
                    fieldLabel: '代理商',
                    userType: 'agent'
                });
                var productSelector = Ext.create('Forestry.app.ui.Component.ProductSelector', {
                    id: 'product_id',
                    fieldLabel: '产品'
                });
                
                var receiveInventoryBtn = {
                    xtype : 'button',
                    text : '入库',
                    iconCls : 'x-fa fa-plus',
                    width : 70,
                    handler : function(btn, eventObj) {
                        var win = new App.AddInventoryWindow({});
                        win.show();
                    }
                };
                var distributeInventoryBtn = {
                    xtype : 'button',
                    text : '出库',
                    iconCls : 'x-fa fa-minus',
                    width : 70,
                    handler : function(btn, eventObj) {
                        var result = getInventorySelection(me);
                        if(result == null){
                            Ext.Msg.alert('错误提示', '请选择终端!');
                            return;
                        }


                        var win = Ext.create('Forestry.app.inventory.AssignInventoryWindow', {
                            selected_ids: result['selected_ids']
                        });
                        var form = win.down('form').getForm();
                        var countField = form.findField('count');
                        console.log('field', countField);
                        if(result['selected_ids'].length > 1){
                            countField.setDisabled(true);
                        }


                        var params = {
                            'serialNum': result['serialNumStr']
                        };
                        if(result['agentUserId'] != undefined){
                            params['agentUserId'] = result['agentUserId'];
                        }
                        if(result['userId'] != undefined){
                            params['user_id'] = result['userId'];
                        }
                        if(result['productId'] != undefined){
                            params['product'] = result['productId'];
                        }
                        console.log(result);


                        form.setValues(params);
                        console.log(form);
                        win.show();
                    }
                };





                var ttoolbarItems =[ 
                {
                        xtype: 'container',
                        layout: 'vbox',
                        items:[
                            {
                                xtype: 'toolbar',
                                items:[
              {                  
                    xtype : 'textfield',
                    id : 'serialNum',
                    fieldLabel : '序列号',
  //                  labelWidth : 60,
    //                width : '10%'
                },
                
                   {
                xtype: 'datefield',
                id : 'createTime',
                fieldLabel : '入库开始时间',
                //labelWidth : 60,
                    //width : '10%'
               
                },{
                xtype: 'datefield',
                id : 'releaseTime',
                fieldLabel : '入库结束时间',
                //lableWidth : 60,
                   //width : '10%'
               }
               ]
                },
                {
                 xtype:'toolbar',
                 items: [ 


                    userSelector,
                    agentSelector,
                    productSelector,
               ]
               }, 
                
                {
                    xtype: 'toolbar',
                    items: [
                      
               {
                    xtype : 'button',
                    text : '查询',
                    iconCls : 'x-fa fa-search',
                    width : 70,
                    handler : function(btn, eventObj) {
                        var searchParams = {
                            serialNum : Ext.getCmp('serialNum').getValue(),
                            createTime : Ext.getCmp('createTime').getValue(),
                            releaseTime : Ext.getCmp('releaseTime').getValue(),
                            normalUserId: Ext.getCmp('user_id').getValue(),
                            agentId: Ext.getCmp('agent_id').getValue(),
                            productId: Ext.getCmp('product_id').getValue(),
                            
                        
                        };
                        Ext.apply(store.proxy.extraParams, searchParams);
                        store.loadPage(1);
                    }
                }, {
                    xtype : 'button',
                    text : '重置',
                    iconCls : 'x-fa fa-undo',
                    width : 70,
                    handler : function(btn, eventObj) {
                        Ext.getCmp('serialNum').setValue(null);
                        Ext.getCmp('createTime').setValue(null);
                        Ext.getCmp('releaseTime').setValue(null);
                        Ext.getCmp('user_id').setValue(null);
                        Ext.getCmp('agent_id').setValue(null);
                        Ext.getCmp('product_id').setValue(null);
                        
                        store.proxy.extraParams = {};
                        store.reload();
                    }
                }, {
                    xtype: 'button',
                    text: '出库撤销',
                    handler: function(){
                        var result = getInventorySelection(me);
                        if(result == null){
                            Ext.Msg.alert('错误提示', '请选择终端!');
                            return;
                        }


                        var window = Ext.create('Forestry.app.inventory.CancelAssignmentWindow', {
                            selected_ids: result['selected_ids']
                        });
                        var form = window.down('form').getForm();
                        var params = {
                            'serialNum': result['serialNumStr']
                        };


                        form.setValues(params);
                        window.show();
                    }
                }, {
                    xtype : 'button',
                    text : '删除',
                    iconCls : 'x-fa fa-remove',
                    width : 70,
                    handler : function(btn, eventObj) {
                        var grid = Ext.getCmp("inventory-grid");
                        if (grid.getSelectionModel().getSelection().length > 0) {
                            var id = grid.getSelectionModel().getSelection()[0].get('id');
                            globalObject.confirmTip('删除的记录不可恢复,继续吗?', function(btn) {
                                if (btn == 'yes') {
                                    grid.getEl().mask("数据删除中,请稍候...");
                                    Ext.Ajax.request({
                                        url : appBaseUri + '/sys/inventory/deleteInventory',
                                        params : {
                                            id : id
                                        },
                                        method : "POST",
                                        success : function(response) {
                                            if (response.responseText != '') {
                                                var res = Ext.JSON.decode(response.responseText);
                                                if (res.success) {
                                                    globalObject.msgTip('操作成功');
                                                    grid.getStore().reload();
                                                } else {
                                                    Ext.Msg.alert('错误提示', res.message);
                                                }
                                            }
                                            grid.getEl().unmask();
                                        },
                                        failure : function(response) {
                                            grid.getEl().unmask();
                                            Ext.Msg.alert('错误提示', '操作失败!');
                                        }
                                    });
                                }
                            });
                        }else {
                            Ext.Msg.alert('提示', '请选择一条宝贝记录');
                        }
                    }
                  }
                  
                
                ]
                }
                ]
                }
                ];
                if(globalObject.haveActionMenu(me.cButtons, 'ReceiveInventory')){
                    ttoolbarItems.splice(3, 0, receiveInventoryBtn);
                }
                if(globalObject.haveActionMenu(me.cButtons, 'DistributeInventory')){
                    ttoolbarItems.splice(3, 0, distributeInventoryBtn);
                }
                var ttoolbar = Ext.create('Ext.toolbar.Toolbar', {
                    items : ttoolbarItems
                });




                Ext.apply(this, {
                    store : store,
                    tbar : ttoolbar,
                    bbar : Ext.create('Ext.PagingToolbar', {
                        store : store,
                        displayInfo : true
                    }),
                    columns : columns,
                    selModel: Ext.create('Ext.selection.CheckboxModel')
                });


                store.loadPage(1);


                this.callParent(arguments);
            
            }
        });
       
    }else{
        Ext.define('Forestry.app.inventory.InventoryList', {
            extend: 'Ext.grid.Grid',
            height: '100%',
            requires: [
                'Ext.grid.plugin.Editable',
                'Ext.grid.plugin.ViewOptions',
                'Ext.grid.plugin.PagingToolbar',
                'Ext.grid.plugin.SummaryRow',
                'Ext.grid.plugin.ColumnResizing',
                'Ext.grid.plugin.MultiSelection',
                'Ext.grid.plugin.RowExpander'
            ],
            store: store,
            shadow: true,
            rowLines: true,
            itemConfig:{
                body:{
                    tpl:'<div style="color:#aaa;">代理商:{agentRealName}<br/>用户:{userRealName}<br/>入库时间:{createTime:date("Y-m-d H:i:s")}<br/>出库时间:{releaseTime:date("Y-m-d H:i:s")}</div>'
                }
            },
            columns: [
                {
                    text: '序列号',
                    dataIndex: 'serialNum',
                    width: window.innerWidth*0.6
                },
                {
                    text: '产品',
                    dataIndex: 'productTitle',
                    width: window.innerWidth*0.4
                }
            ],
            plugins: [{
                type: 'grideditable'
            }, {
                type: 'gridviewoptions'
            }, {
                type: 'pagingtoolbar'
            }, {
                type: 'summaryrow'
            }, {
                type: 'columnresizing'
            }, {
                type: 'rowexpander'
            }]
        });
    }


})();
0 0