| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- Ext.define('erp.view.pm.mes.CraftGridPanel',{
- extend: 'Ext.grid.Panel',
- alias: 'widget.erpGridPanel2',
- requires: ['erp.view.core.toolbar.Toolbar', 'erp.view.core.plugin.CopyPasteMenu'],
- region: 'south',
- layout : 'fit',
- id: 'grid',
- emptyText : $I18N.common.grid.emptyText,
- columnLines : true,
- autoScroll : true,
- store: [],
- columns: [],
- binds:null,
- bodyStyle: 'background-color:#f1f1f1;',
- plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
- clicksToEdit: 1,
- listeners:{
- beforeedit:function(e){
- var g=e.grid,r=e.record,f=e.field;
- if(g.binds){
- var bool=true;
- Ext.Array.each(g.binds,function(item){
- if(Ext.Array.contains(item.fields,f)){
- Ext.each(item.refFields,function(field){
- if(r.get(field)!=null && r.get(field)!=0 && r.get(field)!='' && r.get(field)!='0'){
- bool=false;
- }
- });
- }
- });
- return bool;
- }
- }
- }
- }), Ext.create('erp.view.core.plugin.CopyPasteMenu')],
- features : [Ext.create('Ext.grid.feature.GroupingSummary',{
- startCollapsed: true,
- groupHeaderTpl: '{name} (共:{rows.length}条)'
- }),{
- ftype : 'summary',
- showSummaryRow : false,//不显示默认合计行
- generateSummaryData: function(){
- // 避开在grid reconfigure后的计算,节约加载时间50~600ms
- return {};
- }
- }],
- GridUtil: Ext.create('erp.util.GridUtil'),
- BaseUtil: Ext.create('erp.util.BaseUtil'),
- necessaryField: '',//必填字段
- detno: '',//编号字段
- keyField: '',//主键字段
- mainField: '',//对应主表主键的字段
- dbfinds: [],
- caller: null,
- condition: null,
- gridCondition:null,
- initComponent : function(){
- if(!this.boxready) {
- if(this._buttons)
- this.bbar._buttons = this._buttons;// 在toolbar加入grid固定按钮
- var condition = this.condition;
- if(!condition){
- var urlCondition = this.BaseUtil.getUrlParam('gridCondition');
- urlCondition = urlCondition == null || urlCondition == "null" ? "" : urlCondition;
- gridCondition = (gridCondition == null || gridCondition == "null") ? "" : gridCondition;
- gridCondition = gridCondition + urlCondition;
- gridCondition = gridCondition.replace(/IS/g, "=");
- condition = gridCondition;
- }
- var gridParam = {caller: this.caller || caller, condition: this.gridCondition||condition, _m: 0};
- var master = getUrlParam('newMaster');
- if(master){
- gridParam.master = master;
- }
- this.getGridColumnsAndStore(this, 'common/singleGridPanel.action', gridParam, "");//从后台拿到gridpanel的配置及数据
- }
- this.callParent(arguments);
- if(!this.boxready) {
- if(this.allowExtraButtons)// 加载其它按钮
- this.on('reconfigure', this.loadExtraButton, this, {single: true, delay: 1000});
- this.on('summary', this.generateSummaryData, this, {single: true, delay: 1000});
- }
- },
- getEffectiveData: function(){
- var me = this;
- var effective = new Array();
- var s = this.store.data.items;
- for(var i=0;i<s.length;i++){
- var data = s[i].data;
- if(data[me.keyField] != null && data[me.keyField] != ""){
- effective.push(data);
- }
- }
- return effective;
- },
- setReadOnly: function(bool){
- this.readOnly = bool;
- },
- reconfigure: function(store, columns){
- var me = this,
- view = me.getView(),
- originalDeferinitialRefresh,
- oldStore = me.store,
- headerCt = me.headerCt,
- oldColumns = headerCt ? headerCt.items.getRange() : me.columns;
- if (columns) {
- columns = Ext.Array.slice(columns);
- }
- me.fireEvent('beforereconfigure', me, store, columns, oldStore, oldColumns);
- if (me.lockable) {
- me.reconfigureLockable(store, columns);
- } else {
- Ext.suspendLayouts();
- if (columns) {
- delete me.scrollLeftPos;
- headerCt.removeAll();
- headerCt.add(columns);
- }
- if (store && (store = Ext.StoreManager.lookup(store)) !== oldStore) {
- originalDeferinitialRefresh = view.deferInitialRefresh;
- view.deferInitialRefresh = false;
- try {
- me.bindStore(store);
- } catch ( e ) {
- }
- view.deferInitialRefresh = originalDeferinitialRefresh;
- } else {
- me.getView().refresh();
- }
- Ext.resumeLayouts(true);
- }
- me.fireEvent('reconfigure', me, store, columns, oldStore, oldColumns);
- this.fireEvent("summary", this);
- },
- generateSummaryData : function() {
- var store = this.store,
- columns = this.columns, s = this.features[this.features.length - 1],
- i = 0, length = columns.length, comp, bar = this.down('erpToolbar');
- if (!bar) return;
- //将feature的data打印在toolbar上面
- for (; i < length; i++ ) {
- comp = columns[i];
- if(comp.summaryType) {
- var tb = Ext.getCmp(comp.dataIndex + '_' + comp.summaryType);
- if(!tb){
- bar.add('-');
- tb = bar.add({
- id: comp.dataIndex + '_' + comp.summaryType,
- itemId: comp.dataIndex,
- xtype: 'tbtext'
- });
- }
- var val = s.getSummary(store, comp.summaryType, comp.dataIndex, false);
- if(comp.xtype == 'numbercolumn') {
- val = Ext.util.Format.number(val, (comp.format || '0,000.000'));
- }
- tb.setText(comp.text + ':' + val);
- }
- }
- },
- /**
- * Grid上一条
- */
- prev: function(grid, record){
- grid = grid || Ext.getCmp('grid');
- record = record || grid.selModel.lastSelected;
- if(record){
- //递归查找上一条,并取到数据
- var d = grid.store.getAt(record.index - 1);
- if(d){
- try {
- grid.selModel.select(d);
- return d;
- } catch (e){
- }
- } else {
- if(record.index - 1 > 0){
- return this.prev(grid, d);
- } else {
- return null;
- }
- }
- }
- },
- /**
- * Grid下一条
- */
- next: function(grid, record){
- grid = grid || Ext.getCmp('grid');
- record = record || grid.selModel.lastSelected;
- if(record){
- //递归查找下一条,并取到数据
- var d = grid.store.getAt(record.index + 1);
- if(d){
- try {
- grid.selModel.select(d);
- return d;
- } catch (e){
- }
- } else {
- if(record.index + 1 < grid.store.data.items.length){
- return this.next(grid, d);
- } else {
- return null;
- }
- }
- }
- },
- allowExtraButtons: false,// 加载其它按钮,从GridButton加载
- loadExtraButton: function() {
- var me = this;
- Ext.Ajax.request({
- url : basePath + "common/gridButton.action",
- params: {
- caller: caller
- },
- method : 'post',
- async: false,
- callback : function(options, success, response){
- var r = new Ext.decode(response.responseText);
- if(r.exceptionInfo){
- showError(r.exceptionInfo);
- }
- if(r.buttons){
- var buttons = Ext.decode(r.buttons), tb = me.down('#toolbar');
- if(tb) {
- Ext.each(buttons, function(b){
- try {
- tb.add({
- xtype: b.xtype,
- disabled: true,
- style: {
- marginLeft: '0'
- }
- });
- } catch(e) {
- tb.add({
- text: $I18N.common.button[b.xtype],
- id: b.xtype,
- cls: 'x-btn-gray',
- disabled: true
- });
- }
- });
- }
- }
- }
- });
- },
- getGridColumnsAndStore: function(grid, url, param, no){
- var me = this;
- grid.setLoading(true);
- Ext.Ajax.request({//拿到grid的columns
- url : basePath + url,
- params: param,
- async: (grid.sync ? false : true),
- method : 'post',
- callback : function(options,success,response){
- grid.setLoading(false);
- if (!response) return;
- var res = new Ext.decode(response.responseText);
- if(res.exceptionInfo){
- showError(res.exceptionInfo);return;
- }
- if(res.columns){
- var limits = res.limits, limitArr = new Array();
- if(limits != null && limits.length > 0) {//权限外字段
- limitArr = Ext.Array.pluck(limits, 'lf_field');
- }
- Ext.each(res.columns, function(column, y){
- // column有取别名
- if(column.dataIndex.indexOf(' ') > -1) {
- column.dataIndex = column.dataIndex.split(' ')[1];
- }
- //power
- if(limitArr.length > 0 && Ext.Array.contains(limitArr, column.dataIndex)) {
- column.hidden = true;
- }
- //renderer
- me.GridUtil.setRenderer(grid, column);
- //logictype
- me.GridUtil.setLogicType(grid, column, {
- headerColor: res.necessaryFieldColor
- });
- });
- //data
- var data = [];
- if(!res.data || res.data.length == 2){
- if (grid.buffered) {
- me.GridUtil.add10EmptyData(grid.detno, data);
- me.GridUtil.add10EmptyData(grid.detno, data);//添加20条空白数据
- } else {
- grid.on('reconfigure', function(){// 改为Grid加载后再添加空行,节约200~700ms
- me.GridUtil.add10EmptyItems(grid, 40, false);
- });
- }
- } else {
- data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
- data = me.parseData(data);
- }
- //store
- var store = me.GridUtil.setStore(grid, res.fields, data, grid.groupField, grid.necessaryField);
- //view
- if(grid.selModel && grid.selModel.views == null){
- grid.selModel.views = [];
- }
- //dbfind
- if(res.dbfinds && res.dbfinds.length > 0){
- grid.dbfinds = res.dbfinds;
- }
- //reconfigure
- if(grid.sync) {//同步加载的Grid
- grid.reconfigure(store, res.columns);
- grid.on('afterrender', function(){
- me.GridUtil.setToolbar(grid, grid.columns, grid.necessaryField, limitArr);
- });
- } else {
- //toolbar
- if (grid.generateSummaryData === undefined) {// 改为Grid加载后再添加合计,节约60ms
- me.GridUtil.setToolbar(grid, res.columns, grid.necessaryField, limitArr);
- }
- grid.reconfigure(store, res.columns);
- }
- if(grid.buffered) {//缓冲数据的Grid
- grid.verticalScroller = Ext.create('Ext.grid.PagingScroller', {
- activePrefetch: false,
- store: store
- });
- store.guaranteeRange(0, Math.min(store.pageSize, store.prefetchData.length) - 1);
- }
- var form = Ext.ComponentQuery.query('form');
- if(form && form.length > 0){
- grid.readOnly = form[0].readOnly;//grid不可编辑
- }
- } else {
- grid.hide();
- var form = Ext.ComponentQuery.query('form')[0];
- if(form && !form.isStatic) {
- if(form.items.items.length == 0) {
- form.on('afterload', function(){
- me.GridUtil.updateFormPosition(form);//字段较少时,修改form布局
- });
- } else {
- me.GridUtil.updateFormPosition(form);//字段较少时,修改form布局
- }
- }
- }
- }
- });
- },
- parseData:function(data){
- var arr = new Array();
- if (caller === 'Craft') {
- Ext.each(data,function(item){
- var o = new Object();
- for(var key in item){
- if(key == 'cd_updatedate' || key == 'cd_id' || key == 'cd_crid' || key == 'cd_stepno' ||
- key == 'cd_detno' || key == 'cd_stepcode' || key == 'cd_stepname'||key == 'cd_table'){
- o[key] = item[key];
- }else{
- o[key] = item[key]==-1?true:false;
- }
- }
- arr.push(o);
- });
- }else if (caller == 'STANDARDCRAFT') {
- Ext.each(data,function(item){
- var o = new Object();
- for(var key in item){
- if(key == 'sd_updatedate' || key == 'sd_id' || key == 'sd_scid' || key == 'sd_detno' ||
- key == 'sd_stepcode' || key == 'sd_stepname' || key == 'sd_stepno' || key == 'sd_nextstepcode'
- || key == 'sd_nextstepname' || key == 'sd_firststep'||key == 'sd_table'){
- o[key] = item[key];
- }else{
- o[key] = item[key]==-1?true:false;
- }
- }
- arr.push(o);
- });
- }
- return arr;
- }
- });
|