代碼事例

/**
 * 訂單錄入
 */
var pageSizeVal = 20;
taoexpo.user.userManage = function() {
 Ext.onReady(function() {
  Ext.QuickTips.init();
  // 記錄json對應設置(如果json數據只有值沒有名稱,需要)
  //var data = [['1','sales', '43729050','cherry','SH','159*','26465','SH,BJ']]; 
  var data = [];
  
  /*******************************************************************
   * 列表標題以及數據顯示設置
   ******************************************************************/
  var colModel = new Ext.grid.ColumnModel( [
                                           
    new Ext.grid.RowNumberer(), {
     header : 'id',
     dataIndex : 'id',
     hidden : true
    },{
     header : "姓名",
     sortable : false,
     dataIndex : 'name'
    },
    {
     header : "密碼",
     sortable : false,
     dataIndex : 'password'
    }, {
     header : "手機號",
     sortable : false,
     dataIndex : 'mobile'
    }]);
  
 var record=Ext.data.Record.create([
   {
   name : 'id'
   }, {
    name : 'name'
   } ,{
    name : 'password'
   },{
       name : 'mobile'
   }
 ]);
 
 var reader= new Ext.data.JsonReader({
  root : "userList",
  fields : record
 });

  /*******************************************************************
   * 獲取數據
   ******************************************************************/
  var dataStore = new Ext.data.Store( {
   proxy : new Ext.data.HttpProxy({
    url : getContextPath()+'/userManager.htm'
  }),
     reader : reader
  
  });
  
  /*******************************************************************
   * 獲取roleList數據
   ******************************************************************/
  var roleList = new Ext.data.JsonStore({       
   url:getContextPath()+'/selectRole.htm',
      root:'userList',
      fields:['roleId','roleName'],
      autoLoad:true        
  })
  
  /*******************************************************************
   * 設置檢索參數
   ******************************************************************/
  dataStore.on('beforeload', function(dataStore) {
//   var para = {
//    cardNo : ''
//   };
//   Ext.apply(dataStore.baseParams, para);
  });
  /*******************************************************************
   * 加載第一頁信息
   ******************************************************************/
  dataStore.load( {
   params : {
    start : 0,
    limit : 10
   }
  });

  /**
   * 按鈕定義
   */
  var getApplyNoButton = new Ext.Button({
   
   text : '查詢',
   width : 100,
   handler : function(){
    infoForm.getForm().submit({
      timeout:60000,
         waitMsg:'正在查詢,請稍後...',
         failure:function(form,action){        
         Ext.Msg.alert("failure","查詢失敗!");
         },
         success:function(form,action){
             var dataManage = action.result.userList;
                            dataStore.loadData(action.result);
 
         }       
   });
   }
 
  });
  var findAttachmentButton = new Ext.Button({
   text : '查詢全部',
   width : 100,
   handler : function(){
    infoForm.getForm().reset();
    infoForm.getForm().submit({
      timeout:60000,
         waitMsg:'正在查詢,請稍後...',
         failure:function(form,action){        
         Ext.Msg.alert("failure","查詢失敗!");
         },
         success:function(form,action){
           var dataManage = action.result.userList;
                          dataStore.loadData(action.result);

         }       
   });
   }   
  });
  /*******************************************************************
   * 翻頁條定義
   ******************************************************************/
  var bbar = new Ext.PagingToolbar({
      store: dataStore,
      pageSize:pageSizeVal,
      displayInfo:true,
      displayMsg : '顯示第{0}條到{1}條記錄,一共{2}條'
     });
  
  /*******************************************************************
   * 列表定義
   ******************************************************************/
  var grid = new Ext.grid.GridPanel( {
   width:'auto',
      height : document.body.clientHeight-200,
   id : 'button-grid',
   store : dataStore,
   cm : colModel,
   stripeRows : true,
   viewConfig : {
    forceFit : true
   },
   //工具條
   tbar : [{
    text: '添加',
    iconCls:'add',
    tooltip:'新增一個用戶',
    handler : function(){
     taoexpo.user.userManage.addUserBasic(dataStore);
    }
   },
   {
    text: '編輯',
    iconCls : 'edit',
    handler : function(){
    var selectRecord = grid.getSelectionModel()
     .getSelected();
   if (null == selectRecord) {
    Ext.MessageBox.alert("提示", "至少選擇一條數據!");
   } else {
    taoexpo.user.userManage.edit(dataStore,selectRecord,roleList);
   }
  
    }
   },
   {
    text: '刪除',
    iconCls:'remove',
    tooltip:'刪除一條記錄',
    handler : function(){     
     taoexpo.user.userManage.deleteUser(dataStore,grid);     
    }
   }
   ],
   // 菜單條
   loadMask : {
    msg : '數據加載中,請稍侯……'
   },
   // 分頁條
   bbar : bbar,
   frame : true,
   title : '',
   iconCls : 'icon-grid'
  });
/**
 * 角色下拉列表查詢
 */
  var roleStore = new Ext.data.JsonStore({
   url:getContextPath()+'/selectRole.htm',
      root:'userList',
      fields:['roleId','roleName']  
  
  });
  roleStore.load();
  
  
/**
 * 行所下拉列表查詢
 */ 
  
  var branchStore = new Ext.data.JsonStore({
   url:getContextPath()+'/selectBranch.htm',
      root:'userList',
      fields:['branchId','branchId']  
  
  });
  branchStore.load(); 
 
 
  /**
   * 訂單內容信息
   */
  var infoForm = new Ext.FormPanel({
   url : getContextPath()+'/userManager.htm',
   labelAlign : 'right',
   layout : 'form',
   labelSeparator : ':',
   width : document.body.clientWidth > PANELMINWIDTH?document.body.clientWidth-230:PANELMINWIDTH-20,
//   height : document.body.clientHeight,
   items : [{
    title : '條件查詢',
    xtype : 'fieldset',
    layout : 'column',
    buttonAlign : 'center',
    collapsible : true,
    height : 100,
    buttons : [getApplyNoButton,findAttachmentButton],
    items : [{
     columnWidth : .33,
     layout : 'form',
     items : [{
        xtype : 'textfield',
        fieldLabel : '姓名',
        name : 'name',
        width : 140,
        value : '',
        readOnly : false
       }]
        
    },{
     columnWidth : .33,
     layout : 'form',
     items : [{
        xtype : 'textfield',
        fieldLabel : '手機號',
        name : 'mobile',
        width : 140,
        hidden : false
       }]
    }]
   },grid]
  });
  /***********************************************************************
   * 容器panel定義
   **********************************************************************/
  var containerPanel = new Ext.Panel({
     layout : 'column',
     frame : true,
     applyTo : 'userManage_div',
     id : 'containerPanel',
     width : document.body.clientWidth > PANELMINWIDTH
       ? document.body.clientWidth-200
       : PANELMINWIDTH,
     height : document.body.clientHeight,
     items : [infoForm]
    });
  /***********************************************************************
   * 頁面寬度高度自適應處理
   **********************************************************************/
  Ext.EventManager.onWindowResize(function(w, h) {
     try {
      if (document.body.clientWidth > PANELMINWIDTH) {
       containerPanel.setWidth(document.body.clientWidth-200);
      } else {
       containerPanel.setWidth(PANELMINWIDTH);
      }

     } catch (e) {
     }

    });

 });
};
taoexpo.user.userManage();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章