XmjfEditGrid = Ext.extend(Ext.grid.Panel, {
_proId:0,
_baseParam:{},
constructor : function(_config) {
if (_config == null)
_config = {};
Ext.apply(this, _config);
var _width = window.screen.width * 0.8;
if(this._winProId)
this._proId = this._winProId;
// this['rowEditing'] = Ext.create('Ext.grid.plugin.RowEditing', {
// clicksToMoveEditor: 1,
// autoCancel: false
// });
this.cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
});
this._baseParam = {
process : this._process,
start : 1
};
if(this._proId)
this._baseParam.proId = this._winProId;
this["store"] = {
// autoLoad : true,
proxy : {
type : 'ajax',
url : "xmgk/xmjf-manage.action",
extraParams : this._baseParam,
reader : {
type : 'json',
root : 'rows',
totalProperty : "totalCount"
}
},
model : 'xmjf',
listeners : {
'load' : {
fn : this.loadHander,
scope : this
}
}
};
this['columns'] = [
// {
// header : "主键",
// dataIndex : "guId"
// },
{
text : '科目名称',
flex : 1,
dataIndex : 'name'
// editor: {
// allowBlank: false
// }
}, {
text : '预算金额',
flex : 1,
dataIndex : 'ysje'
// ,
// editor: {
// allowBlank: false
// }
}, {
text : '第一年',
flex : 1,
hidden: true ,
hideable: false,
dataIndex : 'year1',
editor: {
xtype: 'numberfield',
minValue:0
}
}, {
text : '第二年',
flex : 1,
hidden: true ,
hideable: false,
dataIndex : 'year2',
editor: {
xtype: 'numberfield',
minValue:0
}
},{
text : '第三年',
flex : 1,
hidden: true ,
hideable: false,
dataIndex : 'year3',
editor: {
xtype: 'numberfield',
minValue:0
}
}, {
text : '第四年',
flex : 1,
hideable: false,
hidden: true ,
dataIndex : 'year4',
editor: {
xtype: 'numberfield',
minValue:0
}
}, {
text : '第五年',
flex : 1,
hideable: false,
hidden: true ,
dataIndex : 'year5',
editor: {
xtype: 'numberfield',
minValue:0
}
},{
text : '第六年',
flex : 1,
hidden: true ,
hideable: false,
hidden: true ,
dataIndex : 'year6',
editor: {
xtype: 'numberfield',
minValue:0
}
},{
text : '第七年',
flex : 1,
//id : 'sex',
dataIndex : 'year7',
hideable: false,
hidden: true ,
editor: {
xtype: 'numberfield',
minValue:0
}
}, {
text : '第八年',
flex : 1,
hideable: false,
hidden: true ,
dataIndex : 'year8',
editor: {
xtype: 'numberfield',
minValue:0
}
}, {
text : '第九年',
flex : 1,
hideable: false,
hidden: true ,
dataIndex : 'year9',
editor: {
xtype: 'numberfield',
minValue:0
// allowBlank: false
}
},{
text : '第十年',
flex : 1,
hideable: false,
hidden: true ,
hideable: false,
hidden: true ,
dataIndex : 'year10',
editor: {
xtype: 'numberfield',
minValue:0
// allowBlank: false
}
},{
text : '备注',
flex : 1,
dataIndex : 'bz',
editor: {
// allowBlank: false
}
}]
XmjfEditGrid.superclass.constructor.call(this, {
height : this._height||330,
autoScroll: true,
// title : '项目经费',
width :_width,
plugins: [this.cellEditing],
tbar : [ {
text : "保存",
iconCls : "tbnt_save",
handler : this.onSave,
scope : this
}],
viewConfig : {
stripeRows : true,
enableTextSelection : true
},
listeners:{
"beforeedit":function(iEventobj){
var col = iEventobj.row;//获取行
var record = iEventobj.record;//获取当前选中的这个单元格所在的一行数据
var isEdit = record.get("isEdit");//判断是否编辑的列值
if("false"==isEdit){
return false;//表示不可以编辑
}else
{
var field = iEventobj.field;
if(field == 'name')
{
return false;//表示不可以编辑
}
}
} ,
edit:function(obj,a,b)
{
if(a.column.text == '备注')
{
return;
}
var _store = this.store;
this.editHandler(_store,a);
//
}
}
});
if(this._data.jhsc > 0)
{
for(i=1;i<=this._data.jhsc ;i++)
{
this.columns[i+1].hidden = false;
}
}
},
editHandler:function(store,obj)
{
var colIndex = obj.colIdx;
var rowIndex = obj.rowIdx;
if(obj.value == NaN || obj.value == '')
{
obj.value = 0;
}
var record = store.getAt(rowIndex);
var parentId = record.get('parentId');
this.updateRow(store,obj);
this.updateParent(store,parentId,obj);
},
updateRow:function(store,obj)
{
var rowIndex = obj.rowIdx;
var record = store.getAt(rowIndex);
var oldValue = obj.originalValue;
var newValue = obj.value;
var ysje = record.get('ysje');
record.set('ysje',ysje - oldValue + parseFloat(newValue));
},
updateParent : function(store,parentId,obj)
{
if(null == parentId || parentId == '' )
return;
var colIndex = obj.colIdx;
var rowIndex = obj.rowIdx;
var record = store.getAt(rowIndex);
var oldValue = obj.originalValue;
var newValue = obj.value;
var parRecord = store.findRecord('guId',parentId);
if(!parRecord)
console.log(parentId);
var value = parRecord.get(obj.field) + parseFloat(newValue) - oldValue;
parRecord.set(obj.field,value);
parentId = parRecord.get('parentId');
var value = parRecord.get('ysje') + parseFloat(newValue) - oldValue;
parRecord.set('ysje',value);
this.updateParent(store,parentId,obj);
},
onAddRow : function(){
var _ps = new XmMember();
var _index = this.store.getCount()-1;
this.store.insert(_index,_ps);
},
onBlurHandler : function(_field){
_field._lastVal = _field.value;
// return ;
},
onSave : function(){
var guId = null;
//判断是在win中 还是在tab 中
if(this._winForm)
{
guId = this._winProId;
var zys = this._winForm.getForm().findField('zys').getValue();
var ysjeSum = this.store.getAt(31).get('ysje');
if(zys!=ysjeSum)
{
alert('项目经费表的预算与项目预算不一致,请确认!');
return;
}
var yss = new Array();
var years = new Array();
for(i=1;i<=this._data.jhsc;i++)
{
yss.push(this._winForm.getForm().findField('ys'+i).getValue());
years.push(this.store.getAt(31).get('year'+i));
if(yss[i-1]!=years[i-1])
{
alert('项目经费表的第'+i+'年预算总额与项目预算不一致,请确认!');
return;
}
}
}
// else
// {
// guId = this._tab._topPanel._grid.getSelectionModel().selected.items[0].get('proId');
// var zys = this._tab._topPanel._grid.getSelectionModel().selected.items[0].get('zys');
// var ysjeSum = this.store.sum('ysje');
// if(zys!=ysje)
// {
// alert('项目经费表的预算与项目预算不一致,请确认!');
// return;
// }
// var yss = new Array();
// var years = new Array();
// for(i=1;i<=10;i++)
// {
// yss.push(this._tab._topPanel._grid.getSelectionModel().selected.items[0].get('ys'+i));
// years.push(this.store.sum('year'+i));
//
// if(yss[i-1]!=years[i-1])
// {
// alert('项目经费表的第'+i+'年预算总额与项目预算不一致,请确认!');
// return;
// }
// }
//
// }
//
var _res= this.store.data.items;
var _data = '';
Ext.each(_res,function(_item,_index,_allItems){
if(_item.get("name").length>0){
if(_data.length==0){
_data+='[';
}
if(_data.length>1)
_data+=',';
_data+= Ext.encode(_item.data);
//_count++;
}
});
if(_data.length>0)
_data+=']';
else{
warningMesg({
msg : '请录入经费信息!'
});
return;
}
var _grid = this;
ajaxRequest( {
url : 'xmgk/xmjf-manage!save.action',
params : {
proId:guId,
data : _data
},
callBack : function(returnData) {
_grid.store.load();
}
});
}
});
extjs editgrid 财务经费计算 单元格编辑 根据父子关系 递归计算求和赋值
最新推荐文章于 2017-12-22 10:17:32 发布