//新增数据
function add() {
if (Index == undefined) {
row = { move_date: '', start_time: '', end_time: '', start_place: '', arrival_place: '', move_vehicle: '' };
$('#dg').datagrid('appendRow', row);
Index = $('#dg').datagrid('getRows').length - 1;
$('#dg').datagrid('selectRow', Index).datagrid('beginEdit', Index);
}//新建行结束
//回车时结束编辑,并开启新一行放在datagrid的onBeginEdit事件里
onBeginEdit: function (Index, row) {
var stayPlace = $("#dg_StaySchedule").datagrid('getEditor', { index: Index, field: 'stay_place' });
var stayAmount = $("#dg_StaySchedule").datagrid('getEditor', { index: Index, field: 'stay_amount' });
$(stayPlace.target).textbox('options').onChange = function (newValue, lodValue) {
//开启等待
MaskUtil.mask();
$.ajax({//根据条件值获取数据
type: "POST",
url: "url?stay_place=" + newValue + "&emp_title=" + $('#emp_title').textbox('getValue'),
dataType: 'json',
success: function (msg) {
//关闭等待
MaskUtil.unmask();
stayData = 0;
stayData = JSON.parse(msg.stay);
$(stayAmount.target).textbox('setValue', stayData);//查询的数据给列赋值
}
})
}
//回车时结束编辑,并开启新一行
$('.datagrid-editable .textbox,.datagrid-editable .datagrid-editable-input,.datagrid-editable .textbox-text').bind('keypress', function (e) {
var code = e.keyCode || e.which;
f (code == 13) {
//保存更改 第一次编辑可能不会改变值
var b = $('#dg').datagrid('validateRow', Index);
if (b == false) {
$('#dg').datagrid('selectRow', Index).datagrid('beginEdit', Index);
return;
}
$('#dg').datagrid('acceptChanges');
$('#dg').datagrid('endEdit', Index);
if (stayData > 0 && row.stay_amount > stayData) {
$.messager.confirm('操作提示', "提交的住宿费已超标准费用,标准住宿费用是:" + stayData + "元,是否继续?", function (r) {
if (r) {
$('#dg').datagrid('unselectRow', Index);
Index= undefined;
add();//新增方法
}
else {
$('#dg').datagrid('beginEdit', Index);
}
})
} else {
Index= undefined;
add();//新增方法
}
}
});
}