function init(){
var editRow = undefined;
var oldMoney = undefined;
$("#dg").datagrid({
url:"../foreignexchange/fexLedgerManager.do?method=queryApplyData&parentId="+parentId,
fitColumns:false,//自适应宽度,占满,不能和冻结列同时设置成true
striped:true, //斑马线效果
singleSelect:false, //是否单选
pagination:false,
height:140,
columns:[[
{field:"id", title:"主键", width:'10', align:"center",hidden:true},
{field:"applyNo", title:"申报单号", width:'250', align:"center",editor: { type: 'validatebox', options: { required: true } }},
{field:"exeMoneyString", title:"执行金额", width:'200', align:"center",editor: { type: 'moneybox', options: {precision:2, required: true } }},
{field:"exchangeRate", title:"执行汇率(%)", width:'210', align:"center",editor: { type: 'numberbox', options: {precision:5, required: true } }},
{field:"submitDate", title:"提交日期", width:'190', align:"center",editor: { type: 'datebox', options: { required: true } }},
{field:"executeDate", title:"执行日期", width:'190', align:"center",editor: { type: 'datebox', options: { required: true } }}
]],
toolbar: [{
text: '添加', iconCls: 'icon-add', handler: function () {
if (editRow != undefined) {
$("#dg").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
var submitDate = $("#submitDate").val();
$("#dg").datagrid('insertRow', {
index: 0,
row: {submitDate:submitDate}
});
$("#dg").datagrid('beginEdit', 0);
editRow = 0;
}
}
}, /*'-', {
text: '撤销', iconCls: 'icon-redo', handler: function () {
editRow = undefined;
$("#dg").datagrid('rejectChanges');
$("#dg").datagrid('unselectAll');
}
},*/ '-', {
text: '删除', iconCls: 'icon-remove', handler: function () {
var row = $("#dg").datagrid('getSelected');
if(row){
var index = $("#dg").datagrid("getRowIndex",row);
$("#dg").datagrid('deleteRow',index);
}else{
$("#dg").datagrid('endEdit', 0);
$("#dg").datagrid('deleteRow',0);
editRow = undefined;
}
}
}, '-', {
text: '修改', iconCls: 'icon-edit', handler: function () {
var row = $("#dg").datagrid('getSelected');
oldMoney = row.exeMoneyString;
if (row !=null) {
if (editRow != undefined) {
$("#dg").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
var index = $("#dg").datagrid('getRowIndex', row);
$("#dg").datagrid('beginEdit', index);
editRow = index;
$("#dg").datagrid('unselectAll');
}
} else {
}
}
}, '-', {
text: '保存', iconCls: 'icon-save', handler: function () {
var opeRow = editRow;
$("#dg").datagrid('endEdit', editRow);
var rows = $("#dg").datagrid('getChanges');
if(!rows ||rows.length==0){
alert("无修改数据,无需保存!");
return false;
}
var allRows = $("#dg").datagrid('getData');
var executeMoney = $("#executeMoney").val();
var sum = 0;
var money = 0;
$.each(allRows.rows,function(i,row){
row.parentId = parentId;
money = formatMeony(row.exeMoneyString);
sum+=money;
});
if(sum>executeMoney){
alert("执行金额超出台账登记执行金额!");
if(oldMoney){
$("#dg").datagrid('updateRow', {
index: opeRow,
row: {exeMoneyString:oldMoney}
});
}
$("#dg").datagrid('beginEdit', opeRow);
$("#dg").datagrid('unselectAll');
return false;
}
//新增
var addRows = $("#dg").datagrid('getChanges','inserted');
//修改
var updateRows = $("#dg").datagrid('getChanges','updated');
//删除
var delRows = $("#dg").datagrid('getChanges','deleted');
var addOrUpdate = $.merge(addRows,updateRows);
var addOrUpdateStr = JSON.stringify(addOrUpdate);
var delRowsStr = JSON.stringify(delRows);
$.ajax({
type:'post',
url:'../foreignexchange/fexLedgerManager.do',
data : {
"method" : $("#method").val(),
"addOrUpdateStr" : addOrUpdateStr,
"delRowsStr" : delRowsStr
},
cache:false,
dataType:'json',
success:function(data){
if(data.success){
alert(data.msg);
init();
}else{
alert(data.msg);
}
}
});
}
}],
onAfterEdit: function (rowIndex, rowData, changes) {
editRow = undefined;
},
onDblClickRow:function (rowIndex, rowData) {
if (editRow != undefined) {
$("#dg").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
$("#dg").datagrid('beginEdit', rowIndex);
editRow = rowIndex;
var row = $("#dg").datagrid('getSelected');
oldMoney = row.exeMoneyString;
}
},
onClickRow:function(rowIndex,rowData){
if (editRow != undefined) {
$("#dg").datagrid('endEdit', editRow);
}
}
});
}
function formatMeony(value){
var money =value;
var temp = money.split(",");
var result = "";
var value = 0;
var size = temp.length;
for (var j = 0; j < size; j++) {
result = result + temp[j];
}
value = parseFloat(result);
return value;
}