/* 设置节点时限 */
function setTimeLimit(id,limit,workday){
	$(".processNodeDialog").load('/flowable/processDefinition/setTimeLimit?id='+id,function(){
		 $("#myModal-addprocessNodeInfor").modal("show");
		 
		 if(null!=limit){
				if(limit!=0){
					$('[name=timeLimit]').val(limit);
					$('#timeLimitBtn i').text(limit)
					
					
					if(workday){
						$('[name=workingDay]').val('true');
						$('#workingDayBtn i').text('工作日')
					}else{
						$('[name=workingDay]').val('false');
						$('#workingDayBtn i').text('自然日')
					}
				}
			}
	 });
}
$(function(){
	function loadData(){
		$('#processNodeList').setGridParam({
			mtype:'GET',
			url : '/flowable/processDefinition/doListFlowActDef',
			datatype : 'json',
			postData : {'procDefId':$("#procDefId").val()},
			page : 1
		});
		$('#processNodeList').trigger('reloadGrid');
	}
	function workingDayFmatter(cellvalue, options, rowObject) {
		if(null!=rowObject.timeLimit){
			if(rowObject.timeLimit==0){
				return '无时限';
			}
			if (rowObject.workingDay) {
				return rowObject.timeLimit + '个工作日'
			} else {
				return rowObject.timeLimit + '个自然日'
			}
		}else {
			return ''
		}
	}
	
	function operationFmatter(cellvalue, options, rowObject){
		if( $("#setTaskTimeLimit").length>0 ){
			return '<div class="operateIcon noHover"><p><span style="display: none;">设置任务时限</span><i class="operateIconfont operateIcon-xianshi" onclick="setTimeLimit('+rowObject.id+','+rowObject.timeLimit+','+rowObject.workingDay+')"></i></p></div>';
		}else{
			return ''
		}
	}
	
	sxUtil.jqGrid('#processNodeList',{
		colNames:['主键','序号','流程定义ID','任务KEY','任务名称','时限','操作'],
		colModel:[
			{name: 'id', label: '主键', hidedlg:true, hidden:true,sortable:false,title:false},
			{name: 'orderNumber', label: '序号', width:70,sortable:false,title:false},
			{name: 'processDefinitionId', label: '流程定义ID',sortable:false,align:'left',title:false},
            {name: 'activityKey', label: '任务KEY',sortable:false,align:'center',title:false},
            {name: 'activityName', label: '任务名称',sortable:false,align:'center',title:false},
            {name: 'timeLimit', label: '时限',formatter:workingDayFmatter,sortable:false,align:'center',title:false},
            {name: 'enabledDisplayNames', label: '操作',formatter:operationFmatter,sortable:false,align:'center',title:false}
		],
		height:'auto',
		mtype:'GET',
		url : '/flowable/processDefinition/doListFlowActDef',
		pager : '#processNodeListPage',
		multiselect: false,
		rownumbers:false,
		postData : {'procDefId':$("#procDefId").val()},
		page:mylistpage,
		loadError:function(){
			new $.zui.Messager('列表加载失败', {
			    type: 'warning',
			    time:1500
			}).show();
		},
		onPaging:function(pgButton){
			console.log(pgButton)
		}
	},true);
	//给序号列添加列头
	jQuery('#processNodeList').jqGrid('setLabel','rn', '序号', {  
       	'color' : 'white'  
   	}); 
	//刷新
	$('#refresh').click(function(){
		$('#processNodeList').jqGrid('setGridParam',{ 
            mtype:'GET',
            url : '/flowable/processDefinition/doListFlowActDef',
            postData: {'procDefId':$("#procDefId").val()},
            page:1 
        }).trigger('reloadGrid'); //重新载入
	});
	$(".newBackBtn").click(function(){
		$(".yk_rightcontent").load('/flowable/processDefinition/list')
	})
})
	