<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>待办页面</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/layer-v2.3/laydate/laydate.js"></script>
	<script type="text/javascript">
        function openDialogre(title,url,width,height,target,button){
            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            var split = button.split(",");
            top.layer.open({
                type: 2,
                area: [width, height],
                title: title,
                maxmin: true, //开启最大化最小化按钮
                content: url ,
                btn: split,
                btn1: function(index, layero){
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    if(iframeWin.contentWindow.doSubmit(1) ){
                        // top.layer.close(index);//关闭对话框。
                        setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                    }
                },
                btn2:function(index,layero){
                    if(split.length==2){return}
                    var body = top.layer.getChildFrame('body', index);
                    var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var inputForm = body.find('#inputForm');
                    var top_iframe;
                    if(target){
                        top_iframe = target;//如果指定了iframe，则在改frame中跳转
                    }else{
                        top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                    }
                    inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                    if(${not empty flag}){
//                        var comment = iframeWin.contentWindow.document.getElementById('act.comment').value;
//                        if(!comment){
//                            parent.layer.msg('请填写审核意见',{icon:5});
//                            return false;
//                        }
						if(split.length==4) {
                            iframeWin.contentWindow.document.getElementById('flag').value = 'no1'
                        }else {
                            iframeWin.contentWindow.document.getElementById('flag').value = 'no'
						}
                        iframeWin.contentWindow.document.getElementById('inputForm').submit()
                        setTimeout(function(){top.layer.close(index)}, 100);
                    }else{
                        if(split.length==4) {
                            iframeWin.contentWindow.document.getElementById('flag').value = 'no1'
                        }else {
                            iframeWin.contentWindow.document.getElementById('flag').value = 'no'
                        }
                        if(iframeWin.contentWindow.doSubmit(2) ){
                            // top.layer.close(index);//关闭对话框。
                            setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                        }
                    }
                },
                btn3: function(index,layero){
                    if(split.length == 3){return}
                        var body = top.layer.getChildFrame('body', index);
                        var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        var inputForm = body.find('#inputForm');
                        var top_iframe;
                        if(target){
                            top_iframe = target;//如果指定了iframe，则在改frame中跳转
                        }else{
                            top_iframe = top.getActiveTab().attr("name");//获取当前active的tab的iframe
                        }
                        inputForm.attr("target",top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示
                        if(${not empty flag}){
//                        var comment = iframeWin.contentWindow.document.getElementById('act.comment').value;
//                        if(!comment){
//                            parent.layer.msg('请填写审核意见',{icon:5});
//                            return false;
//                        }
							iframeWin.contentWindow.document.getElementById('flag').value = 'no2'
                            iframeWin.contentWindow.document.getElementById('inputForm').submit()
                            setTimeout(function(){top.layer.close(index)}, 100);
                        }else{
                            iframeWin.contentWindow.document.getElementById('flag').value = 'no2';
                            if(iframeWin.contentWindow.doSubmit(3) ){
                                // top.layer.close(index);//关闭对话框。
                                setTimeout(function(){top.layer.close(index)}, 100);//延时0.1秒，对应360 7.1版本bug
                            }
                        }
				},
				btn4:function(index){

				}
            });

        }
	</script>
	<style>
		.shows .input-group{
			width: 78%!important;
		}
		.form-group shows{
			width: auto;
		}
		#beginContractDate{
			width:200px;
		}
		#endContractDate{
			width:200px;
		}
	</style>

	<script type="text/javascript">
        function formSubmit($document,inputForm,index){
            var validateForm = $($document.getElementById(inputForm)).validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $($document.getElementById("#messageBox")).text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            if(validateForm.form()){
                var loadingMessage = parent.layer.load(0, {shade: false,opacity:0.1});
                $($document.getElementById(inputForm)).ajaxSubmit({
                    success:function(data) {
                        top.layer.close(index);
                        history.go(0);
                        parent.layer.msg("审批完成！！！",{icon:6});
                        parent.layer.close(loadingMessage);
                    }
                });
            }
        }
	</script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
	<div class="ibox">
		<div class="ibox-title" style="height: 70px;">
			<h5>
				<ul class="nav nav-tabs">
					<li ><a href="${ctx}/ruralProject/ruralProjectRecords/list">项目登记列表</a></li>
					<li class="active"><a href="${ctx}/ruralProject/ruralProjectRecords/toDoList">待办任务</a></li>
					<li><a href="${ctx}/ruralProject/ruralProjectRecords/queryCompleteList">已办任务</a></li>
					<li><a href="${ctx}/ruralProject/ruralProjectRecordsAlter/list">项目变更列表</a></li>
				</ul>
			</h5>
			<%--<div class="ibox-tools">
				<a class="collapse-link">
					<i class="fa fa-chevron-up"></i>
				</a>
				<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
					<i class="fa fa-wrench"></i>
				</a>

			</div>--%>
		</div>

		<div class="ibox-content">
			<sys:message content="${message}"/>

			<!--查询条件-->
			<div class="row">
				<div class="col-sm-12">
					<form:form id="searchForm" modelAttribute="act" action="${ctx}/ruralProject/ruralProjectRecords/toDoList" method="get" class="form-inline">
						<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
						<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
						<table:sortColumn id="orderBy" name="orderBy" value="${page.orderBy}" callback="sortOrRefresh();"/><!-- 支持排序 -->
						<div class="form-group">
							<label>创建时间：</label>
							<input class="form-control layer-date laydate-icon" id="beginDate" name="beginDate" value="<fmt:formatDate value="${act.beginDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
							　--　
							<input class="form-control layer-date laydate-icon" id="endDate" name="endDate" value="<fmt:formatDate value="${act.endDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
						</div>
					</form:form>
					<br/>
				</div>
			</div>

			<!-- 工具栏 -->
			<div class="row">
				<div class="col-sm-12">
					<%--<div class="pull-left">
                        <shiro:hasPermission name="workcontractinfo:workContractInfo:add">
                            <table:addRow url="${ctx}/workcontractinfo/workContractInfo/form" title="合同管理"></table:addRow><!-- 增加按钮 -->
                        </shiro:hasPermission>
                        <shiro:hasPermission name="workcontractinfo:workContractInfo:edit">
                            <table:editRow url="${ctx}/workcontractinfo/workContractInfo/form" title="合同管理" id="contentTable"></table:editRow><!-- 编辑按钮 -->
                        </shiro:hasPermission>
                        <shiro:hasPermission name="workcontractinfo:workContractInfo:del">
                            <table:delRow url="${ctx}/workcontractinfo/workContractInfo/deleteAll" id="contentTable"></table:delRow><!-- 删除按钮 -->
                        </shiro:hasPermission>
                        <shiro:hasPermission name="workcontractinfo:workContractInfo:import">
                            <table:importExcel url="${ctx}/workcontractinfo/workContractInfo/import"></table:importExcel><!-- 导入按钮 -->
                        </shiro:hasPermission>
                        <shiro:hasPermission name="workcontractinfo:workContractInfo:export">
                               <table:exportExcel url="${ctx}/workcontractinfo/workContractInfo/export"></table:exportExcel><!-- 导出按钮 -->
                           </shiro:hasPermission>
                       <button class="btn btn-white btn-sm " data-toggle="tooltip" data-placement="left" onclick="sortOrRefresh()" title="刷新"><i class="glyphicon glyphicon-repeat"></i> 刷新</button>

                        </div>--%>
					<div class="pull-right">
						<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="search()" ><i class="fa fa-search"></i> 查询</button>
						<button  class="btn btn-primary btn-rounded btn-outline btn-sm " onclick="reset()" ><i class="fa fa-refresh"></i> 重置</button>
					</div>
				</div>
			</div>

			<!-- 表格 -->
			<table id="contentTable" class="table table-striped table-bordered table-hover table-condensed dataTables-example dataTable" >
				<thead>
				<tr>
					<%--<th style="text-align: center;"> <input type="checkbox" class="i-checks"></th>--%>
					<th style="text-align: left;"  class="sort-column contractNum">审批类型</th>
					<th style="text-align: left;"  class="sort-column contractNum">项目编号</th>
					<th style="text-align: left;"  class="sort-column name" >项目名称</th>
						<th  class="sort-column u.name">项目负责人</th>
						<th  class="sort-column wci.name">合同名称</th>
						<th  class="sort-column wct.name">委托方</th>
						<th style="text-align: left;"  class="sort-column projectStatus">项目状态</th>
					<th style="text-align: left;">操作</th>
				</tr>
				</thead>
				<tbody>
				<c:choose>
					<c:when test="${not empty list}">
						<c:forEach items="${list}" var="projectRecords">

							<c:set var="task" value="${projectRecords.act.task}" />
							<c:set var="vars" value="${projectRecords.act.vars}" />
							<c:set var="procDef" value="${projectRecords.act.procDef}" /><%--
				<c:set var="procExecUrl" value="${act.procExecUrl}" /> --%>
							<c:set var="status" value="${projectRecords.act.status}" />
							<tr>
									<%--<td> <input type="checkbox" id="${workContractInfo.id}" class="i-checks"></td>--%>
								<td>
										${projectRecords.auditType}
								</td>
								<td><a  href="#" onclick="openDialogView('查看项目', '${ctx}/ruralProject/ruralProjectRecords/view?id=${projectRecords.id}','80%', '80%')">
										${projectRecords.projectId}
								</a>
								</td>
								<td>
									<a  href="#" onclick="openDialogView('查看项目', '${ctx}/ruralProject/ruralProjectRecords/view?id=${projectRecords.id}','80%', '80%')">
											${projectRecords.projectName}
									</a>
								</td>
								<td class="max-width-100">
									<c:forEach items="${projectRecords.projectLeaders}" var="leader" varStatus="status">
										<c:choose>
											<c:when test="${status.last}">${leader.name}</c:when>
											<c:otherwise>${leader.name},</c:otherwise>
										</c:choose>
									</c:forEach>
								</td>
								<td>
										${projectRecords.workContractInfo.name}
								</td>
									<%--<td>
                                            ${workContractInfo.chargeCompanyName}
                                    </td>--%>
								<td>
										${projectRecords.workContractInfo.client.name}
								</td>
								<td>
										${fns:getDictLabel(projectRecords.projectStatus, 'audit_state', '')}
								</td>
								<%--<td>
										${projectRecords.createBy.name}
								</td>--%>
								<%--<td>--%>
										<%--${projectRecords.status}--%>
								<%--</td>--%>
								<td>
									<div style="text-align: center">
											<%--<shiro:hasPermission name="workcontractinfo:workContractInfo:view">
                                                <a href="${ctx}/workcontractinfo/workContractInfo/pass?id=${workContractInfo.id}&taskId=${task.id}&taskName=${fns:urlEncode(task.name)}&taskDefKey=${task.taskDefinitionKey}&procInsId=${task.processInstanceId}&procDefId=${task.processDefinitionId}&status=${status}" onclick="return confirmx('确认要通过该合同管理吗？', this.href)"   class="btn btn-info btn-xs"><i class="fa fa-search-plus"></i>通过</a>
                                            </shiro:hasPermission>
                                            <shiro:hasPermission name="workcontractinfo:workContractInfo:del">
                                                    <a href="${ctx}/workcontractinfo/workContractInfo/unpass?id=${workContractInfo.id}&taskId=${task.id}&taskName=${fns:urlEncode(task.name)}&taskDefKey=${task.taskDefinitionKey}&procInsId=${task.processInstanceId}&procDefId=${task.processDefinitionId}&status=${status}" onclick="return confirmx('确认要回退该合同管理吗？', this.href)"   class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 回退</a>
                                            </shiro:hasPermission>--%>
										<c:if test="${projectRecords.auditType eq '项目登记'}">
											<c:choose>
												<c:when test="${projectRecords.act.taskDefKey eq 'modifyApply'}">
                                                        <a href="#" onclick="openDialogre('调整项目', '${ctx}/ruralProject/ruralProjectRecords/modify?id=${projectRecords.id}','80%', '80%','','送审,关闭')" class="btn btn-success btn-xs" ><i class="fa fa-edit"></i> 任务办理</a>
                                                </c:when>
												<c:otherwise>
													<a href="javascript:void(0)" onclick="openDialogre('项目登记审批', '${ctx}/ruralProject/ruralProjectRecords/projectRecordsAudit?id=${projectRecords.id}&taskId=${task.id}&taskName=${fns:urlEncode(task.name)}&taskDefKey=${task.taskDefinitionKey}&procInsId=${task.processInstanceId}&procDefId=${task.processDefinitionId}&status=${status}','80%','80%','','同意,驳回,关闭')" class="btn btn-success btn-xs" >任务办理</a>
												</c:otherwise>
											</c:choose>
										</c:if>
										<c:if test="${projectRecords.auditType eq '项目变更'}">
                                            <c:choose>
                                            <c:when test="${projectRecords.act.taskDefKey eq 'modifyApply'}">
                                                <a href="#" onclick="openDialogre('调整项目', '${ctx}/ruralProject/ruralProjectRecordsAlter/modify?procInsId=${task.processInstanceId}','80%', '80%','','送审,关闭')" class="btn btn-success btn-xs" ><i class="fa fa-edit"></i> 任务办理</a>
                                            </c:when>
                                                <c:otherwise>
                                                <a href="javascript:void(0)" onclick="openDialogre('项目变更审批', '${ctx}/ruralProject/ruralProjectRecordsAlter/projectRecordsAudit?taskId=${task.id}&taskName=${fns:urlEncode(task.name)}&taskDefKey=${task.taskDefinitionKey}&procInsId=${task.processInstanceId}&procDefId=${task.processDefinitionId}&status=${status}','80%','80%','','同意,驳回,关闭')" class="btn btn-info btn-xs" > 任务办理</a>
                                                </c:otherwise>
                                            </c:choose>
										</c:if>
									</div>
								</td>
							</tr>
						</c:forEach>
					</c:when>
					<c:otherwise>
						<tr>
							<td colspan="12" align="center">暂无数据</td>
						</tr>
					</c:otherwise>
				</c:choose>

				</tbody>
			</table>

			<!-- 分页代码 -->
			<table:page page="${page}"></table:page>
			<br/>
			<br/>
		</div>
	</div>
</div>
</body>
</html>