版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/han_xiaoxue/article/details/79916230
由于之前的文章详细些了jsp/controller的写法,此文忽略。只写js
JS
var isShow = false;
$(function(){
index.init();
})
var index = {
init:function(){
index.doSearch();
},
doSearch:function(){
$("#product").datagrid({
// var param = sy.serializeObject($("#productfrom"));获取参数(下拉选条件等)
// queryParams:param,传参数
columns:[[
{ field :'check',checkbox : true,sortable : false,width:'7%'},//选择框(小方块)
{field:'matter',title:'待办范围',width:"15%",align:'center'},
{field:'content',title:'待办内容',width:"15%",align:'center'},
{field:'insertTime',title:'提交时间',width:"15%",align:'center'},
{field:'insertUserName',title:'提交人',width:"15%",align:'center'},
{field:'state',title:'处理状态',width:"15%",align:'center'},
{field:'caozuo',title:'操作',width:"15%",align:'center',formatter:function(value,row,index){
var str = '<a href="#" onclick="showTeamPeriod(\''+index+'\',\''+row.state+'\',true,\''+row.dbid+'\')">▼ 团期管理</a>';
return '<br>'+str;
}},
{field:'dbid',title:'dbid',hidden:true}
]],
rownumbers:true,
autoRowHeight:true,
striped:true,
nowrap:false,
fit:false,
checkOnSelect:false,
loadMsg:'加载中 请稍后...',
pagination:true,
pageList:[2,10,15,20],
pageNumber:1,
url:contextPath+'/orderCommission/selectAgencyOrderTeamList.do?permission_Key='+permissionKey+'&state=1234567890099',
loadFilter:function(data){//显示数据并分页
datas = {'total':0 , 'rows':[]};
if(data.succ){
datas.total = data.data.total;
datas.rows = data.data.list;
}else{
$.messager.alert("错误提示",data.msg);
}
return datas;
},
onCheck:function(rowIndex,rowData){//选中小方块
console.log(rowIndex+" "+rowData);
},
onUncheck:function(rowIndex,rowData){//取消选中小方块
console.log(rowIndex+" .. "+rowData);
},
//设置展开的团期子表
view: detailview,
detailFormatter:function(index,row){
return '<div style="padding:5px;width:1200px" ><div id="teamInfo1" >'+
'<a id="addTeamPeriod" class="caissa-btn02" onclick="addNewTeam(\''+row.dbid+'\')" href="javascript:void(0);">新增团期</a> '+
'<input name="stateAll'+index+'" onclick="clickTeamStateAll('+index+')" class="teamCheckall" type="checkbox" value="all"/>全部状态 '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_7'].code+'"/>'+teamStates['TEAM_STATE_7'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_1'].code+'"/>'+teamStates['TEAM_STATE_1'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_4'].code+'"/>'+teamStates['TEAM_STATE_4'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_5'].code+'"/>'+teamStates['TEAM_STATE_5'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_6'].code+'"/>'+teamStates['TEAM_STATE_6'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_2'].code+'"/>'+teamStates['TEAM_STATE_2'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_3'].code+'"/>'+teamStates['TEAM_STATE_3'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_8'].code+'"/>'+teamStates['TEAM_STATE_8'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_9'].code+'"/>'+teamStates['TEAM_STATE_9'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_10'].code+'"/>'+teamStates['TEAM_STATE_10'].name+' '+
'<input name="state'+index+'" onclick="clickTeamState('+index+')" class="teamCheckbox" type="checkbox" value="'+teamStates['TEAM_STATE_11'].code+'"/>'+teamStates['TEAM_STATE_11'].name+' '+
'<table class="caissa-tb-line01 caissa-mart5 caissa-alignce">'+
'<tr><td class="caissa-alignle" colspan="10" style="background:#C1C1C1; height:30px">'+
'<input hidden="true" id="allTeamPeriod'+index+'" type="checkbox" value="all"/>'+
'<a href="#" class="caissa-btn08" onclick="publishTeam('+index+');">上架</a>'+
'<a href="#" class="caissa-btn08" onclick="unPublishTeam('+index+');">下架</a>'+
'<a href="#" class="caissa-btn08" onclick="submitTeam('+index+');">提交审核</a>'+
'<a href="#" class="caissa-btn08" onclick="deleteTeam('+index+');">删除</a>'+
'<a href="#" class="caissa-btn08" onclick="batchTeamDelete();">批量删除</a>'+
'<a href="#" class="caissa-btn08" onclick="showEditTeamWin(\''+row.dbid+'\');">批量修改团期</a>'+
'<a href="#" class="caissa-btn08" onclick="batchUpdateTeamStock(\''+row.dbid+'\');">批量调整库存</a>'+
'<a href="#" class="caissa-btn08" onclick="addTotoList('+index+');">增加待办事项</a>'+
'</td></tr></table>'+
'</div> <table id="teamSubGrid"></table></div>';
},
onExpandRow: function(index,row){
var ddv = $(this).datagrid('getRowDetail',index).find('#teamSubGrid');
//teamIdUnCheck.splice(0,teamIdUnCheck.length);
//teamIdCheck.splice(0,teamIdCheck.length);
ddv.datagrid({
idField:'dbid',
url:contextPath+'/orderCommission/selectAgencyOrderTeamList.do?permission_Key='+permissionKey+'&state=1234567890099',
columns:[[
{ field :'check',checkbox : true,sortable : false,width:'7%'},//选择框(小方块)
{field:'matter',title:'待办范围',width:"15%",align:'center'},
{field:'content',title:'待办内容',width:"15%",align:'center'},
{field:'insertTime',title:'提交时间',width:"15%",align:'center'},
{field:'insertUserName',title:'提交人',width:"15%",align:'center'},
{field:'state',title:'处理状态',width:"15%",align:'center'},
{field:'caozuo',title:'操作',width:"15%",align:'center',formatter:function(value,row,index){
var str = '<a href="#" onclick="showTeamPeriod(\''+index+'\',\''+row.state+'\',true,\''+row.dbid+'\')">▼ 团期管理</a>';
return '<br>'+str;
}},
{field:'dbid',title:'dbid',hidden:true}
]],
checkOnSelect:false,
onResize:function(){
$('#product').datagrid('fixDetailRowHeight',index);
},
onLoadSuccess:function(){/*
teamIdUnCheck.clear();
teamIdCheck.clear();
setTimeout(function(){
$('#product').datagrid('fixDetailRowHeight',index);
},0);
if($("#allTeamPeriod"+index).attr("checked") == 'checked'){
$(this).datagrid('checkAll');
}else{
$(this).datagrid('uncheckAll');
}
disDetailCheck(index);
//重置高度
$(this).datagrid('resize', {
height : "350px"
});
$("#product").datagrid('resize', {
height : "880px"
});
var h = $(document).height()-$(window).height()-((10-index)*37);
$(document).scrollTop(h);
*/},
rownumbers:true,
autoRowHeight:true,
striped:true,
nowrap:false,
fit:false,
fitColumns:true,
height:'auto',
loadMsg:'加载中 请稍后...',
pagination:true,
pageList:[2,10,15,20],
pageNumber:1,
loadFilter:function(resp){//数据和分页
datas = {'total':0,'rows':[]};
datas.total = resp.data.total;
datas.rows = resp.data.list;
// datas.total = resp.total;
// datas.rows = resp.list;
return datas;
},
onUncheck:function(rowIndex,rowData){
// teamIdCheck.remove(rowData.dbid);
// teamIdUnCheck.put(rowData.dbid,rowData.state);
},
onCheck:function(rowIndex,rowData){
// teamIdUnCheck.remove(rowData.dbid);
// teamIdCheck.put(rowData.dbid,rowData.state);
},
onCheckAll:function(rows){
//解决页面勾选datagrid 的全选 teamids 为空的问题
// isAllSelectDatagrid=true;
},
onUncheckAll:function(rows){
// isAllSelectDatagrid=false;
},
queryParams:{
/* productId:row.dbid,
states:getTeamState(index)*/
}
});
$('#product').datagrid('fixDetailRowHeight',index);
}
});
}
}
function showTeamPeriod(index,state,isOpen,dbid){
if(!isShow){
console.log(1);
//根据传入的dbid和页面勾选的所有产品的dbid做判断,如果相同,则表明当前行是选中的
var isCheck = false;
var rows = $('#product').datagrid('getChecked');
if(rows != null && rows.length > 0 ){
console.log(2);
for(i=0;i<rows.length;i++){
if(dbid == rows[i].dbid){
isCheck = true
break;
}
}
}
if(isCheck == 'true' || isCheck == true){
console.log(3);
//将团期状态设置为不可勾选 "input[name=stateAll"+index+"]
$("input[name=state"+index+"]").attr('disabled',true);
$("input[name=stateAll"+index+"]").attr('disabled',true);
//选中所有团期,并且不可编辑
/*$("#allTeamPeriod"+index).attr("checked",true);
$("#allTeamPeriod"+index).attr('disabled',true);*/
}else{
console.log(4);
$("input[name=state"+index+"]").attr('disabled',false);
$("input[name=stateAll"+index+"]").attr('disabled',false);
//选中所有团期,并且不可编辑
/*$("#allTeamPeriod"+index).attr("checked",false);
$("#allTeamPeriod"+index).attr('disabled',false);*/
}
if('true' == isOpen || isOpen == true){//此方法是判断父行是什么状态 子行就把什么状态默认勾选上
console.log(5);
//这个方法在jsp页面
var teamState = selectByProductState(state);
$("input[name=state"+index+"]").each(function(){
if(teamState == $(this).attr("value")){
$(this).attr("checked",true);
}
});
}
//设置全局变量的值
selectIndex = index;
selectState = state;
productId = dbid;
isShow = true;
$("#product").datagrid('expandRow',index);//加载子表格
$("#product").datagrid('resize', { //将父表格变高
height : "880px"
});
}else if(isShow){
console.log(6);
if(dbid == productId){
//再次点击团队管理,这个时候,收回展开的团期列表,清空之前设置好的全局变量的值
isShow = false;
$("#product").datagrid('collapseRow',selectIndex);
selectIndex = ''; //设置全局变量的值
selectState = '';
productId = '';
}else{
//再次点击团队管理,这个时候,收回展开的团期列表,清空之前设置好的全局变量的值
isShow = false;
$("#product").datagrid('collapseRow',selectIndex);
showTeamPeriod(index,state,'true',dbid)
}
$("#product").datagrid('resize', {
height : "450px"
});
}
}