extjs4 点击按钮出现tree,选择一个节点,显示到文本框

来源:互联网 发布:青海省教育扶贫数据 编辑:程序博客网 时间:2024/06/05 02:15
        if (Ext.getCmp('addAddressWindow')) {
            Ext.getCmp('addAddressWindow').show();
        } else {
            Ext.create('Ext.Window', {
                title : '添加地区',
                width : 700,
                height : 400,
                layout : 'fit',
                draggable :false,
                modal : true,
                id : 'addAddressWindow',
                items : [
                    allform = new Ext.form.FormPanel({
                    id:'allform',
                    bodyPadding : 20,
                    autoScroll:true,
                    items : [
                    {
                        hideEmptyLabel :false,
                        xtype : 'displayfield',
                        value : '<span style=color:red>*</span>为必填选项'
                    },
                    {
                        xtype : 'fieldcontainer',
                        id : 'omsAddress',
                        width : 600,
                        padding : '0 0 10 0',
                        defaults : {
                            flex : 1
                        },
                        layout : 'table',
                        layoutConfig:{columns:3},
                        items : [{
                            fieldLabel : '&nbsp;&nbsp;所在地区',
                            xtype : 'textfield',
                            id : 'omsAddressParentName',
                            name : 'omsAddressParentName',
                            readOnlyCls : 'disable',
                            padding : '0 0 10 0',
                            width : 300,
                            readOnly: false
                        },{
                            xtype : 'displayfield',
                            hidden : true,
                            id : 'omsAddressParentId',
                            name : 'omsAddressParentId'
                        }, {
                            xtype : 'button',
                            text : '选择',
                            padding : '0 0 10 0',
                            handler : function(){
                                Ext.getCmp('chooseAddressId').show();
                            }
                        },{
                            xtype : 'button',
                            text : '取消选择',
                            padding : '0 0 10 0',
                            handler : function(){
                                //清空 所有的值
                                Ext.getCmp('omsAddressParentName').setValue('');
                                Ext.getCmp('omsAddressParentId').setValue('');
                                sureAddressName = '';
                                sureAddressSysId = '';
                                sureAddressLevel = '';
                            }
                        }]
                    },
                    Ext.create("Ext.panel.Panel",{
                        autoScroll:true,
                        id:'chooseAddressId',
                        layout : 'fit',
                        hidden:true,
                        width:600,
                        height:200,
                        items:[
                            sureTree = Ext.create("Ext.tree.Panel",{  
                                id:'chooseTreeId',
                                selModel: Ext.create('Ext.selection.CheckboxModel', {
                                    checkOnly: false
                                }),
                                listeners: {
                                    selectionchange: function(thiz, selections){
                                        if(selections.length==1){
                                            sureAddressName = selections[0].data.text;
                                            sureAddressSysId = selections[0].data.id;
                                            sureAddressLevel = selections[0].data.level;
                                        }
                                        sureAddressLength = selections.length;
                                    }
                                },
                                width:600,  
                                height:120,
                                singleExpand: true,  
                                rootVisible: false,  //默认不显示根节点
                                root: {  
                                    id:'root',
                                    leve:0,
                                    text: ''
                                },  
                                store:store1
                           }),
                            {
                                xtype : 'button',
                                id : 'btnSure',
                                height : 24,
                                text : '确定',
                                iconCls : 'icon-edit',
                                handler : function(){
                                    if(sureAddressLength==0){
                                        alert("请选择一个地址");    
                                    }else if(sureAddressLength>1){
                                        alert("只能选择一个地址");
                                    }else{
                                        Ext.getCmp('omsAddressParentName').setValue(sureAddressName);
                                        Ext.getCmp('omsAddressParentId').setValue(sureAddressSysId);
                                        Ext.getCmp('chooseAddressId').hide();
                                        sureAddressLength=0;
                                        Ext.getCmp('chooseTreeId').getStore().load();
                                    }
                                }
                            }
                        ]
                    }),
                    {
                        fieldLabel : '<span style=color:red>*</span>地址ID',
                        xtype : 'textfield',
                        id : 'omsAddressCode',
                        name : 'omsAddressCode',
                        padding : '0 0 10 0',
                        allowBlank : false,
                        blankText : "不能为空",
                        width : 300,
                        maxLength : 20,
                        maxLengthText : '最大长度不能超过20个字符!',
                        regex:/^[0-9|a-z|_|A-Z]+$/,
                        regexText:"地址id无效"
                    },
                    {
                        hideEmptyLabel :false,
                        xtype : 'displayfield',
                        value : '不超过20个字节(数字,字母和下划线组成)'
                    },
                    {
                        fieldLabel : '<span style=color:red>*</span>地区名称',
                        xtype : 'textfield',
                        id : 'omsAddressName',
                        name : 'omsAddressName',
                        padding : '0 0 10 0',
                        allowBlank : false,
                        blankText : "不能为空",
                        width : 300,
                        maxLength : 50,
                        maxLengthText : '最大长度不能超过50个字符!'
                    },
                    {
                        hideEmptyLabel :false,
                        xtype : 'displayfield',
                        value : '不超过50个字节'
                    },
                    {
                        fieldLabel : '邮编',
                        xtype : 'textfield',
                        id : 'omsAddressZip',
                        name : 'omsAddressZip',
                        padding : '0 0 10 0',
                        allowBlank : false,
                        blankText : "不能为空",
                        width : 300
                    },
                    {
                        fieldLabel: '&nbsp;&nbsp;虚拟仓库名(可多选)',
                           xtype: 'combo',
                        id: 'omsWarehouseAddress',
                        name: 'omsWarehouseAddress',
                        store:virtualWarehouseStore,
                        width:500,
                        displayField : 'omsVirtualWarehouseName',
                        valueField : 'omsVirtualWhSysId',
                        editable: false,
                        padding:'0 0 10 0',
                        multiSelect: true,
                        autoShow: true
                    },
                    {
                        xtype : 'fieldcontainer',
                        fieldLabel : '&nbsp;&nbsp;状态',
                        width : 300,
                        defaultType : 'radiofield',
                        padding : '0 0 10 0',
                        defaults : {
                            flex : 1
                        },
                        layout : 'hbox',
                        items : [{
                            boxLabel : '启用',
                            name : 'size',
                            inputValue : '1',
                            id : 'addressStatusRadio1',
                            checked : true
                        }, {
                            boxLabel : '禁用',
                            name : 'size',
                            inputValue : '0',
                            id : 'addressStatusRadio2'
                        }]
                    },
                    {
                    xtype : 'button',
                    text : '保存',
                    iconCls : 'icon-orderCancel',
                    handler : saveAddress
                    }]
                })]
            }).show();
        }
   

原创粉丝点击