<style type="text/css">
.fieldset_s{border: 1px #dedede solid;padding: 19px; color: #0E2D5F;}
.fieldset_s legend {color: #000;}
</style>
<div id="acc_toolbar">
<div style="padding:13px 6px 16px 6px;">
<!--<fieldset class="fieldset_s">
<legend>信息查询</legend>
<label for="acc_date_begin">发生日期:</label>
<input id="acc_date_begin" type="text" class="easyui-datebox" style="width:100px;"> 至
<input id="acc_date_end" type="text" class="easyui-datebox" style="width:100px;">
<label for="acc_client"> 客户/学员名称:</label>
<input id="acc_client" type="text" style="width:100px;">
<label for="acc_staff"> 业务员:</label>
<input id="acc_staff" type="text" style="width:100px;">
<label for="acc_project"> 项目课程:</label>
<input id="acc_project" class="easyui-textbox" style="width:100px;">
<a href="javascript:void(0)" onclick="javascript:getquerydata();" onkeydown="return enterSubmit(this,event);" class="easyui-linkbutton c4" data-options="iconCls:'icon-search'" iconCls="icon-search" style="width:90px">搜 索</a>
<div id="dialogs" style="display:none;">
暂未启用
</div>
</fieldset>--> <div style="text-align:center;padding:9px 6px;">录入凭证</div>
<div>
凭证:<input class="easyui-textbox" type="text" name="voucher_no" value='记' data-options="width:40,required:true"> 字
<input class="easyui-textbox" type="text" name="voucher_no" value='001' data-options="width:50,required:true"> 号
日 期: <input class="easyui-datebox" type="text" name="voucher_date" data-options="required:true">
</div>
<br> </div>
<a href="javascript:void(0);" onclick="javascript:accounts_add();" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" >添加应收款</a>
<a href="javascript:void(0);" onclick="javascript:accounts_save();" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-save'">保存数据</a>
<a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'">删除</a>
<a href="javascript:void(0);" onclick="javascript:accounts_redo();" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-redo'">撤销</a>
<a href="javascript:void(0);" onclick="javascript:accounts_edit();" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'">修改</a>
<a href="javascript:void(0);" onclick="javascript:MoveUp();" class="easyui-linkbutton" data-options="plain:true">上移</a>
<a href="javascript:void(0);" onclick="javascript:MoveDown();" class="easyui-linkbutton" data-options="plain:true">下移</a>
</div>
<div class="easyui-panel" title="" style="width:99%;height:99%;padding:3px;border:0px;">
<table id="dgacount" class="easyui-datagrid"></table>
</div>
<div id="combogrid_bar">
<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'"></a>
</div>
<script type="text/javascript">
$(function(){
/*datagrid应收款管理*/ editRow=undefined; //定义全局变量
get_account_Datas();
textbox_staff(); //监听浏览器宽度变化,调整datagrid尺寸和布局
/* $(window).resize(function(){
$('#dgacount').datagrid('resize');
});
*/
//$("#search_toolbar").appendTo(".datagrid-toolbar");添加标签
// textbox_acc_client();
}); //键盘事件 暂未启用
function enterSubmit(src,e)
{
if (window.event) {keyPress = window.event.keyCode;}else{keyPress = e.which;};
if (keyPress==13) {alert('sdf');};
}
// datagrid重新加载数据acc_client:$("#acc_client").val
function getquerydata()
{
//获取 要查询的参数
var acc_date_begin = $("#acc_date_end").datebox("getValue");//注意日期的取值方式
var acc_date_end = $("#acc_date_end").datebox("getValue");
var acc_client = $("#acc_client").val();
var acc_staff = $("#acc_staff").val();
var acc_project = $("#acc_project").val(); alert(acc_date_begin);
$('#dgacount').datagrid('load',{
acc_date_begin:acc_date_begin //向后台传递的参数 });
} //
function textbox_acc_client()
{
$("#acc_client").textbox({
/*buttonText:'click',
iconCls:'icon-search',
onClickButton:function(e){ alertdialog();
},*/ icons:[{
iconCls:'icon-search',
handler:function(e){
var v=$(e.data.target).textbox('getValue');
var v=$(e.data.target).textbox('setText','小兵');
//alert(v?v:'空');
alertdialog();
}
}] })
} //
function textbox_staff()
{
$("#acc_staff").textbox({ icons:[{
iconCls:'icon-search',
handler:function(e){
var v=$(e.data.target).textbox('getValue');
alert(v?v:'空');
alertdialog();
}
}]
}
)
} function alertdialog()
{
$('#dialogs').dialog({
title: 'My Dialog',
width: 400,
height: 200,
closed: false,
cache: false,
modal: true
});
} //初始化datagrid的数据 function get_account_Datas(){
/*<?php //base_url()?>/static/data/test.json
<?php echo site_url();?>/bankinfo/selectAll
*/ $('#dgacount').datagrid({
title: '凭证信息管理',
collapsible: true,
url:'<?php //base_url()?>/static/data/vouher.json',//php文件中使用echo返回json数据 翻页的同时传递了page 和rows;
loadMsg:'数据加载中,请稍后......',
pagination:true,
pageNumber:1,
pageSize:10,
pageList:[6,10,16,26],
rownumbers:true,
singleSelect:true,
//pagePosition:top,
fit:true,//datagrid的适应父窗口
fitColumns:false,//自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动
striped:true,
//method:'post',
toolbar:'#acc_toolbar', onAfterEdit: function (rowIndex, rowData, changes) {
editRow = undefined;
},
onDblClickRow:function (rowIndex, rowData) { if (editRow != undefined) {
$("#dgacount").datagrid('endEdit', editRow);
} if (editRow == undefined) {
$("#dgacount").datagrid('beginEdit', rowIndex);
editRow = rowIndex;
}
},
onClickRow:function(rowIndex,rowData){ if (editRow != undefined) {
$("#dgacount").datagrid('endEdit', editRow); } }, columns:[[
{field:'summary',title:'<br>摘 要<br>',width:200,align:'center',
editor:{
type:'combobox',options:{
valueField:'month',
textField:'month',
method:'get',
url:'<?php base_url()?>/static/data/month.json',
height:50, }
},
styler: function(value,rowData,rowIndex){
return {style:'height:50px'}
},
}, {field:'inout_date',title:'<br>发生日期<br>',width:100,align:'center',hidden:true,
editor:{
type:'datebox',options:{
required:true, },
},
},
{field:'subjects',title:'会计科目 ',width:200,align:'right',
editor:{
type:'combobox',options:{
valueField:'month',
textField:'month',
method:'get',
url:'<?php base_url()?>/static/data/month.json',
height:50,
}
},
styler: function(value,rowData,rowIndex){
return {style:'height:50px'}
}, },{field:'ought_money',title:'借方金额 ',width:200,align:'right',
editor:{type:'numberbox',options:{
precision:2,
height:50,
}}, },
{field:'inout_money',title:'贷方金额 ',width:200,align:'right',
editor:{type:'numberbox',options:{
precision:2,
height:50,
}}
}, {field:'client_name',title:'客户/学员名称',width:100,align:'center',
editor:{
type:'combogrid',options:{
panelWidth:200,
idField:'related_id',
textField:'related_name',
mode:'remote',//远程获取数据
method:'get',
fitColumns:true,
//toolbar:'#combogrid_bar',
url:'<?php echo site_url();?>/relatedcompay/getcombogirdjson',
columns:[[
{field:'related_name',title:'客户/学员姓名',width:80},
{field:'related_programe',title:'项目课程',width:120}
]],
}
}
},
{field:'staff_id',title:'所属业务员/职员',width:100,align:'center',
editor:{
type:'combogrid',options:{
panelWidth:200,
idField:'staff_id',
textField:'name',
mode:'remote',//远程获取数据
method:'get',
fitColumns:true,
toolbar:'#combogrid_bar',
url:'<?php echo site_url();?>/departstaff/getStaffCombogridJson',
columns:[[
{field:'name',title:'姓名',width:80},
{field:'job_role',title:'项目课程',width:190}
]],
}
}
},
{field:'dept_id',title:'所属业务核算部门',width:160,align:'center',
editor:{
type:'text',options:{required:true, }
}
},
{field:'sys_id',title:'预设核算项目课程',width:160,align:'center',
editor:{
type:'combotree',options:{
url:'<?php echo site_url();?>/systemcode/getcomTreeJson',
}
}
}, {field:'account_id',title:'凭证ID',width:100,},
]]
}); } //添加应收款
function accounts_add(){
var dataB=$("#dgacount").datagrid('getData');
//alert('当前页数据量:'+data.rows.length);
var rowIndexs = dataB.rows.length;
if (editRow != undefined) {
$("#dgacount").datagrid('endEdit', editRow);
editRow=undefined;
}
if (editRow == undefined) {
$("#dgacount").datagrid('insertRow', {
index:rowIndexs,
row: {}
}); $("#dgacount").datagrid('beginEdit', rowIndexs);
editRow = rowIndexs;
}
} //撤销编辑操作
function accounts_redo() {
editRow = undefined;
$("#dgacount").datagrid('rejectChanges');
$("#dgacount").datagrid('unselectAll');
} //修改数据
function accounts_edit(){
var row = $("#dgacount").datagrid('getSelected');
//console.info(row);
if (row !=null) {
if (editRow != undefined) {
$("#dgacount").datagrid('endEdit', editRow);
}
if (editRow == undefined) {
var index = $("#dgacount").datagrid('getRowIndex', row);
$("#dgacount").datagrid('beginEdit', index);
editRow = index;
$("#dgacount").datagrid('unselectAll');
}
} else { }
} //保存数据
function accounts_save() { var $dg = $("#dgacount");
var rows = $dg.datagrid('getRows');
for ( var i = 0; i < rows.length; i++) {
$dg.datagrid('endEdit', i);
}
// $("#dgacount").datagrid('endEdit', 0);//结束编辑状态
//如果调用acceptChanges(),使用getChanges()则获取不到编辑和新增的数据。
//使用JSON序列化datarow对象,发送到后台。
//判断列值 是否为空
var mesg = '';
var rows = $("#dgacount").datagrid('getChanges');
console.info(rows);
if(rows.length<=0)
{
$.messager.alert('友情提示',' 无添加或修改的内容!<br><br>','warning');
return false;
}
if(rows)
{
$.each(rows,function(key,val){
if($.trim(rows[key]["client_name"])=='' || $.trim(rows[key]["client_name"])==undefined || $.trim(rows[key]["client_name"]) ==null)
{
mesg += '客户名称不能为空!<br><br>';
}
if($.trim(rows[key]["dept_id"])=='' || $.trim(rows[key]["dept_id"])==undefined || $.trim(rows[key]["dept_id"]) ==null)
{
mesg += '预设核算项目课程不能为空!<br><br>';
}
}); }
//alert(rows[0]["bank_name"]);
if(mesg!='')
{
$.messager.alert('友情提示',mesg,'warning');
return false;
} var rowstr = JSON.stringify(rows);
console.info(rowstr);
//alert(rowstr[bank_name]);//可获取到json数据
$.post('<?php echo site_url();?>/accounts/addaccounts', {adata:rowstr}, function (data) {
//alert(typeof(data)); //返回的是string类型 if(data)
{
$.messager.alert('友情提示',data,'info');
}else{
$.messager.alert('友情提示','数据格式填写错误!','error');
}
//$('#zijin').html(data); // 数据测试
$("#dgacount").datagrid('reload'); //执行成功后刷新当前页数据 });
} function onClickRow(index){
if (editIndex != index){
if (endEditing()){
$('#dgacount').datagrid('selectRow', index)
.datagrid('beginEdit', index);
editIndex = index;
} else {
$('#dgacount').datagrid('selectRow', editIndex);
}
}
} //上移
function MoveUp() {
var row = $("#dgacount").datagrid('getSelected');
var index = $("#dgacount").datagrid('getRowIndex', row);
mysort(index, 'up', 'dgacount'); }
//下移
function MoveDown() { var row = $("#dgacount").datagrid('getSelected');
var index = $("#dgacount").datagrid('getRowIndex', row);
mysort(index, 'down', 'dgacount'); }
function mysort(index, type, gridname) {
if ("up" == type) {
if (index != 0) {
var toup = $('#' + gridname).datagrid('getData').rows[index];
var todown = $('#' + gridname).datagrid('getData').rows[index - 1];
$('#' + gridname).datagrid('getData').rows[index] = todown;
$('#' + gridname).datagrid('getData').rows[index - 1] = toup;
$('#' + gridname).datagrid('refreshRow', index);
$('#' + gridname).datagrid('refreshRow', index - 1);
$('#' + gridname).datagrid('selectRow', index - 1);
}
} else if ("down" == type) {
var rows = $('#' + gridname).datagrid('getRows').length;
if (index != rows - 1) {
var todown = $('#' + gridname).datagrid('getData').rows[index];
var toup = $('#' + gridname).datagrid('getData').rows[index + 1];
$('#' + gridname).datagrid('getData').rows[index + 1] = todown;
$('#' + gridname).datagrid('getData').rows[index] = toup;
$('#' + gridname).datagrid('refreshRow', index);
$('#' + gridname).datagrid('refreshRow', index + 1);
$('#' + gridname).datagrid('selectRow', index + 1);
}
} }
//分页
function getpages()
{ $("#dgacount").datagrid().datagrid("getPager").pagination({
displayMsg:'当前显示从sdf第{from}条到{total}条记录',
buttons:[{
iconCls:'icon-search',
handler:function(){
alert('search');
}
},{
iconCls:'icon-add',
handler:function(){
alert('add');
}
},{
iconCls:'icon-edit',
handler:function(){
alert('edit');
}
}
]
}) }
function reload_combogrid(targetgrid)
{
targetgrid.combogrid('reload');
}
</script>