// JavaScript Document
Ext.onReady(function(){
    Ext.BLANK_IMAGE_URL="../images/s.gif";
    Ext.QuickTips.init();
    
    
    var fields = ["id","name","engLishName","oldName","address"]; 
    
    var index=new Ext.grid.RowNumberer();
    
    var cm = new Ext.grid.ColumnModel([index,
     {header: '地名编号',dataIndex: 'id',sortable: true},
     {header: '地名名称',dataIndex: 'name',sortable: true},
     {header: '罗马字母拼写',dataIndex: 'engLishName',sortable: true},
     {header: '别名',dataIndex: 'oldName',sortable: true},
     {header: '所属城市',dataIndex: 'address',sortable: true}]); 
     
    // create the Data Store
    var store = new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({   
		    url:"sreach.aspx?sreach=true", 
		    method:"POST"  
	    }), 
        reader:new Ext.data.JsonReader({  
            root:'data',
            totalProperty:'totalCount',
            remoteSort: true,
            fields:fields
        })
    });
    
        /*var cstore= new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({   
		    url:"city.aspx?sreach=true", 
		    method:"POST"  
	    }), 
        reader:new Ext.data.JsonReader({  
            root:'data',
            fields:["city"]
        })
    });
    
   cstore.load();
    
    var astore= new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({   
		    url:"cityarea.aspx?sreach=true&&city=", 
		    method:"POST"  
	    }), 
        reader:new Ext.data.JsonReader({  
            root:'data',
            fields:["areaId","area"]
        })
    });
    
    astore.load();
    
    var ctstore= new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({   
		    url:"city_type.aspx?sreach=true", 
		    method:"POST"  
	    }), 
        reader:new Ext.data.JsonReader({  
            root:'data',
            fields:["c_TypeId","c_TypeName"]
        })
    });
    
    ctstore.load();
    
    var ctustore= new Ext.data.Store({
        proxy:new Ext.data.HttpProxy({   
		    url:"city_type_unit.aspx?sreach=true", 
		    method:"POST"  
	    }), 
        reader:new Ext.data.JsonReader({  
            root:'data',
            fields:["c_unitId","c_unitName"]
        })
    });
    
    ctustore.load();*/
    
    var RoomTypeRightClick=new Ext.menu.Menu
        ({
                items:
                [{
                    text:'查看详细',
                    iconCls:'edit',
                    handler:Edit
                },{
                    text:'刷新',
                    iconCls:'refresh',
                    handler:Refersh
                }]
         });

    var grid = new Ext.grid.GridPanel({
        renderTo:'sreachdn',
        cm:cm,
        height:550,
        title:'查询列表',
        store: store,
        loadMask: true,
        columnLines: true,
        viewConfig:{   
		columnsText:"显示/隐藏列",   
		sortAscText:"正序排列",   
		sortDescText:"倒序排列",   
		forceFit:true  
	    },
	    bbar:new Ext.PagingToolbar({
			store:store,
			pageSize:25,
		    emptyMsg:"没有数据显示",
		    displayInfo: true,
		    displayMsg: '当前第 {0} - {1} 条,总数 {2}',
		    prevText:"上一页",
			nextText:"下一页",
			refreshText:"刷新",
			lastText:"最后页",
			firstText:"第一页",
			beforePageText:"当前",
			afterPageText:"共{0}页"
		}),
		tbar:[{
            text: '市级:',
            anchor:'95%'
        },{
             xtype:"combo",
             width:70,
             id:'cityCombo',
             name:'city',
             allowBlank:false,
             blankText:"必选项",
             emptyText:'所有市级',
             allowBlank:false,
             blankText:"必选项",
             editable: false, 
             hiddenName:'city',
             store:new Ext.data.SimpleStore({
	                            data:[["cs","长沙市"],["zz","株洲市"],["xt","湘潭市"],["hy","衡阳市"],["sy","邵阳市"],
	                            ["yy","岳阳市"],["cd","常德市"],["zjj","张家界市"],["yiy","益阳市"],["cz","郴州市"],
	                            ["yz","永州市"],["hh","怀化市"],["ld","娄底市"],["xx","湘西土家族苗族自治州"]],
	                            fields:["city","cityName"]
	                            }),
	         tpl: '<tpl for="."><div ext:qtip="查询市级--{cityName}" class="x-combo-list-item">{cityName}</div></tpl>',
	         displayField:"cityName",
	         mode:"local",
	         valueField:"city",
	         triggerAction:"all",
	         lazyInit : true,
             anchor:'95%'
        },{
            text: '类别:',
            anchor:'95%'
        },{
             xtype:"combo",
             width:70,
             id:'typeCombo',
             name:'c_TypeId',
             allowBlank:false,
             blankText:"必选项",
             emptyText:'所有类别',
             editable: false, 
             hiddenName:'c_TypeId',
             store:new Ext.data.SimpleStore({
	                            data:[["1","单位"],["2","行政区"],["3","群众自治组织"],["4","居民点"],["5","建筑物"],["6","道路"],["7","河流"],
	                            ["8","湖泊"],["9","山峰"],["10","山脉"],["11","旅游景点"]],
	                            fields:["c_TypeId","c_TypeName"]
	                            }),
	         tpl: '<tpl for="."><div ext:qtip="查询类别--{c_TypeName}" class="x-combo-list-item">{c_TypeName}</div></tpl>',
	         displayField:"c_TypeName",
	         mode:"local",
	         valueField:"c_TypeId",
	         triggerAction:"all",
	         lazyInit : true,
	         anchor:'95%'
        },{
            text: '单位类别:',
            anchor:'95%'
        },{
             xtype:"combo",
             width:70,
             id:'unitCombo',
             name:'c_unitId',
             emptyText:'所有单位类别',
             editable: false, 
             hiddenName:'c_unitId',
             store:new Ext.data.SimpleStore({
	                            data:[["1","休闲娱乐场所"],["2","宾馆酒店"],["3","医院"],["4","政府机关"],["5","汽车服务"],["6","车站码头"],["7","邮政电信"],
	                            ["8","银行"],["9","商业网点"],["10","学校"],["11","各级政府驻地"],["12","公司单位"],["13","运动场地"]],
	                            fields:["c_unitId","c_unitName"]
	                            }),
	         tpl: '<tpl for="."><div ext:qtip="查询单位类别--{c_unitName}" class="x-combo-list-item">{c_unitName}</div></tpl>',
	         displayField:"c_unitName",
	         mode:"local",
	         valueField:"c_unitId",
	         triggerAction:"all",
	         lazyInit : true,
	         anchor:'95%'
        },{
            text: '关键字:',
            anchor:'95%'
        },{
            xtype: 'textfield',
            width:100,
            id:'likeUnitName',
            name: 'likeUnitName',
            emptyText:'请输入关键字',
            anchor:'95%'
        },{
            text:'查询',
            tooltip:'按输入条件查询',
            iconCls:'sreach',
            handler:Sreach
        }],listeners:{
            'contextmenu':function(e)
            {
                e.stopEvent();
            },
            'rowcontextmenu':function(grid,rowIndex,e)
            {
                e.stopEvent();
                RoomTypeRightClick.showAt(e.getXY());
            }
		}
	});
	
    
    Ext.getCmp("typeCombo").on("select",function(){
        if(Ext.getCmp("typeCombo").getValue()!="1")
        {
            Ext.getCmp("unitCombo").reset();
            Ext.getCmp("unitCombo").disable();
        }else
        {
            Ext.getCmp("unitCombo").enable();
        }
    });
	
	function Sreach()
	{
	    var city=Ext.getCmp("cityCombo").getValue();
	    var areaId=-1;
	    var c_TypeId=Ext.getCmp("typeCombo").getValue();
	    var c_unitId=Ext.getCmp("unitCombo").getValue();
	    var likeUnitName=Ext.getCmp("likeUnitName").getValue();
	    
	    
	    if(c_TypeId==""|| city=="")
	    {
	        Ext.Msg.alert("提 示","类别必选项,建议您多选择几项");
	    }else{
	        store.on('beforeload', function(store) {   
	        store.baseParams={
	        city:city,
	        areaId:areaId,
	        c_TypeId:c_TypeId,
	        c_unitId:c_unitId,
	        likeUnitName:likeUnitName};} );
	        store.load({params:{start:0, limit:25}});
	    }
	}
	
	function Edit()
	{
	    var row = grid.getSelectionModel().getSelections();
        var count=row.length;
        var delId="";
        var city="";
        var typeId="";
        if(count==0)
        {
             Ext.Msg.alert("提 示","请选中查看行");
             return;
        }else if(count>1)
        {
             Ext.Msg.alert("提 示","只能查看单行");
             return;
        }else
        {
            delId=row[0].data.id;
            city=Ext.getCmp("cityCombo").getValue();
            typeId=Ext.getCmp("typeCombo").getValue();
        }
       switch(typeId)
       {
            case '1':
                window.open("dWInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '2':
                window.open("xingZhengQuInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '3':
                window.open("qunZhuInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '4':
                window.open("zhuMingDeInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '5':
                window.open("jianZhuWuInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '6':
                window.open("daoLuInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '7':
                window.open("heLiuInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '8':
                window.open("hePoInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '9':
                window.open("shanFengInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '10':
                window.open("shanMaiInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
            case '11':
                window.open("jingDianInfo.aspx?id="+delId+"&&city="+city+"&&typeId="+typeId,"new");
                break;
       }
	}
	
	function Refersh()
	{
	    store.reload();
	}
	 
	grid.render();
});
