一個常用的代碼範例

/**
 * 訂單錄入
 */
mortgage.userManager = 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 : 'role'
    }, {
     header : "員工號",
     sortable : false,
     dataIndex : 'staffId'
    }, {
     header : "姓名",
     sortable : false,
     dataIndex : 'name'
    },
    {
     header : "部門",
     sortable : false,
     dataIndex : 'dept'
    },   
    {
     header : "行所",
     sortable : false,
     dataIndex : 'branch'
    }, {
     header : "手機號",
     sortable : false,
     dataIndex : 'mobile'
    }, {
     header : "分機號",
     sortable : false,
     dataIndex : 'ext'
    }, {
     header : "下轄行所",
     sortable : false,
     dataIndex : 'befBranch'
    }]);
  
 var record=Ext.data.Record.create([
   {
   name : 'id'
   }, {
    name : 'role'
   }, {
    name : 'staffId'
   }, {
    name : 'name'
   } ,{
    name : 'dept'
   },   
   {
      name : 'branch'
   }, {
    name : 'mobile'
   }, {
    name : 'ext'
   }, {
    name : 'befBranch'
   }
 ]);
 
 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 nextPageButton = new Ext.Button(
    {
     text : '下一頁',
     disabled : true,
     handler : function() {

     }
    });
  var myMenuBar = [ '->', '-', nextPageButton ];
  
 
  /**
   * 按鈕定義
   */
  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 upbutton = new Ext.Button({
   text : '導出用戶列表',
   id : 'button1',
   name : 'button1',
   handler : function() {
//    infoForm.getForm().submit({
//     url : getContextPath()+'/downloadUserList.htm',
//      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 staffids = $("#staffids").val();
    var branchNo=$("input[name='branchNo']").val();    
    var staffNo=$("#staffNo").val();
    var branchs=$("input[name='branchs']").val();
    var roles = $("input[name='roles']").val(); 
 
     window.location.href = getContextPath()+'/downloadUserList.htm?staffids='+staffids+"&branchNo="+branchNo+"&staffNo="+staffNo+"&branchs="+branchs+"&roles="+roles;
   
   }
  });
  

  
  /*******************************************************************
   * 列表定義
   ******************************************************************/
  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(){
     mortgage.userManager.addUserBasic(dataStore);
    }
   },
   {
    text: '編輯',
    iconCls : 'edit',
    handler : function(){
    var selectRecord = grid.getSelectionModel()
     .getSelected();
   if (null == selectRecord) {
    Ext.MessageBox.alert("提示", "至少選擇一條數據!");
   } else {
    mortgage.userManager.edit(dataStore,selectRecord,roleList);
   }
  
    }
   },
   {
    text: '刪除',
    iconCls:'remove',
    tooltip:'刪除一條記錄',
    handler : function(){     
     mortgage.userManager.deleteUser(dataStore,grid);     
     
    }
   }
   ],
   // 菜單條
   loadMask : {
    msg : '數據加載中,請稍侯……'
   },
   // 分頁條
   bbar : myMenuBar,
   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-20:PANELMINWIDTH-20,
   height : document.body.clientHeight,
   items : [{
    title : '基礎信息',
    xtype : 'fieldset',
    layout : 'column',
    buttonAlign : 'center',
    collapsible : true,
    height : 130,
    buttons : [getApplyNoButton,findAttachmentButton,upbutton],
    items : [{
     columnWidth : .33,
     layout : 'form',
     items : [{
        xtype : 'textfield',
        fieldLabel : '員工號',
        name : 'staffids',
        id : 'staffids',
        width : 140,
        value : '',
        readOnly : false
       },{
        
         xtype : 'combo',
         fieldLabel : '行所',
         store : branchStore,
         forceSelection : true,
         width : 140,
         //emptyText : '請選擇',
         valueField : "branchId",
         displayField : "branchId",
         mode : 'remote',
         name : 'branchNo',
         value : '',
         hiddenName : 'branchNo',
         triggerAction : 'all'
       }]
        
    },{
     columnWidth : .33,
     layout : 'form',
     items : [{
        xtype : 'textfield',
        fieldLabel : '姓名',
        name : 'staffNo',
        id : 'staffNo',
        width : 140,
        hidden : false
       }, {
        xtype : 'combo',
        fieldLabel : '部門',
        store : new Ext.data.JsonStore({
         fields : [ 'name', 'value' ],
         baseParams:{typeId:'h'},
         root:'CodeBase',
         url:getContextPath()+'/CodeBase.htm',
         autoLoad:true
        }),
        forceSelection : true,
        width : 140,
        //emptyText : '請選擇',
        valueField : 'value',
        displayField : 'name',
        mode : 'remote',
        name : 'branchs',
        value : '',
        hiddenName : 'branchs',
        triggerAction : 'all'
       }]
    },{
     columnWidth : .33,
     layout : 'form',
     items : [{
      xtype : 'combo',
      fieldLabel : '角色',
      store : roleStore,
      forceSelection : true,
      width : 140,
      //emptyText : '請選擇',
      valueField : "roleId",
      displayField : "roleName",
      mode : 'remote',
      name : 'roles',
      value : '',
      hiddenName : 'roles',
      triggerAction : 'all'
     }]
    }]
   },{
    title : '查詢結果',
    xtype : 'fieldset',
    layout : 'column',
    bodyStyle : 'padding:5px,0px,2px,0px',
    collapsible : true,
    items : [ grid ]
   }]
  });
  /***********************************************************************
   * 容器panel定義
   **********************************************************************/
  var containerPanel = new Ext.Panel({
     layout : 'column',
     frame : true,
     applyTo : 'manage_grid_div',
     id : 'containerPanel',
     width : document.body.clientWidth > PANELMINWIDTH
       ? document.body.clientWidth
       : PANELMINWIDTH,
     height : document.body.clientHeight,
     items : [infoForm]
    });
  /***********************************************************************
   * 頁面寬度高度自適應處理
   **********************************************************************/
  Ext.EventManager.onWindowResize(function(w, h) {
     try {
      if (document.body.clientWidth > PANELMINWIDTH) {
       containerPanel.setWidth(document.body.clientWidth);
      } else {
       containerPanel.setWidth(PANELMINWIDTH);
      }

     } catch (e) {
     }

    });

 });
};
mortgage.userManager();

 

發佈了118 篇原創文章 · 獲贊 36 · 訪問量 76萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章