<%@ 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(){
            $("img").not(".upload_ico").each(function () {
                var num = 1 ;
                $(this).click(function () {
                    var flag = num%2;
                    if(flag == 1){
                        $(this).css("width","90%");
                        $(this).css("height","90%");
                        num++;
                    }else if(flag ==0){
                        $(this).css("width","50px");
                        $(this).css("height","50px");
                        num++;
                    }
                })
            });
        })
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }

            return false;
        }
        $(document).ready(function() {
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            /*laydate.render({
                elem: '#startTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });
            laydate.render({
                elem: '#endTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });
            laydate.render({
                elem: '#remindDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });
            laydate.render({
                elem: '#completeDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });*/
            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
            $("#taskNames").attr('disabled','disabled');
            $("#startTimes").attr('disabled','disabled');
            $("#endTimes").attr('disabled','disabled');
            $("#remindUsers").attr('disabled','disabled');
            $("#remindDates").attr('disabled','disabled');
            $("#completeUsers").attr('disabled','disabled');
            $("#completeDates").attr('disabled','disabled');
        });

        function setCompletedValue(){
            var ipts = $(":checkbox:checked").parents("tr").find("input:text");
            var ids = $(":checkbox:checked").parents("tr").find("input:hidden");
            var selects = $(":checkbox:checked").parents("tr").find("select");
            // 遍历input并使用val()方法获取值
            var ipt =ipts.map(function() {return $(this).val();}).get().join(", ");
            var select =selects.map(function() {return $(this).val();}).get().join(", ");
            var id =ids.map(function() {return $(this).val();}).get().join(", ");
            if(id == ""){
                top.layer.alert('请至少选择一条数据!', {icon: 0, title:'警告'});
                return;
            }
            var iptList =ipt.split(",");
            var selectList = select.split(",");
            $.ajax({
                type:'post',
                url:'${ctx}/workengineeringproject/workEngineeringProject/getProjectPlanRows',
                data:{
                    "ids":id,
                    "ipts":ipt,
            		"selects":select
                },
                success:function(data){
                    var d = JSON.parse(data);
                    if (d.str == "Success"){
                        parent.layer.msg(d.str,{icon:1});
                    }else {
                        parent.layer.msg(d.str,{icon:2});
                    }
                    location.reload();
                    /*$("#contractNum").val(d.contractNum);
                    $("#contractName").val(d.clientName);
                    $("#linkmanName").val(d.linkmanName);
                    $("#linkmanPhone").val(d.linkmanPhone);
                    $("#linkmanEmail").val(d.linkmanEmail);
                    $("#linkmanPosition").val(d.linkmanPosition);*/
                }
            })
        }

        function display1(){
            var id =$("#bidCompanyId")[0].defaultValue;
            $.get("${ctx}/workclientinfo/workClientInfo/selectLinkman", { clientId: id},
                function(data,textStatus){
                    data = data.body.list;
                    if(data !=null){
                        for (var i=0; i<data.length; i++){
                            addRow('#workClientLinkmanList', workClientLinkmanRowIdx, workClientLinkmanTpl, data[i]);
                            workClientLinkmanRowIdx = workClientLinkmanRowIdx + 1;
                        }
                    }
                });
        }

	</script>
</head>
<body class="gray-bg">
<div class="ibox-content">
	<sys:message content="${message}"/>
	<!-- 工具栏 -->
	<div class="row">
		<div class="col-sm-12">
			<div class="pull-left">
				<%--<button class="btn btn-white btn-sm" title="资格预审项目" onclick="rowAdd()"><i class="fa fa-plus"></i>&nbsp;新增</button>
                <table:removeRow id="contentTable"></table:removeRow><!-- 删除按钮 -->--%>
				<p>
					<%--<table:confirmCompletedRow id="contentTable" url="${ctx}/workengineeringproject/workEngineeringProject/confirmCompletedRow"></table:confirmCompletedRow><!-- 确认按钮 -->
				--%>
						<%--<table:removeRow id="contentTable"></table:removeRow>--%>
						<table:confirm id="contentTable"></table:confirm>
						<%--<button type="button" class="btn btn-sm btn-success" onclick="setCompletedValue()">确认完成</button>--%>
				</p>
			</div>
		</div>
	</div>

	<div class="row">
		<div class="col-sm-12">
			<form:form id="inputForm" modelAttribute="workEngineeringProject" action="${ctx}/workengineeringproject/workEngineeringProject/storePlan" method="post" enctype="multipart/form-data" class="form-horizontal">
				<form:hidden path="id"/>
				<sys:message content="${message}"/>

			<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
				<tbody>
				<table id="contentTable" class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
					<thead>
					<tr>
						<th> <input type="checkbox" class="i-checks"></th>
						<th>任务序号</th>
						<th>任务名称</th>
						<th>开始时间</th>
						<th>结束时间</th>
						<th>提醒人</th>
						<th>提醒时间</th>
						<th>完成人</th>
						<th>完成时间</th>
					</tr>
					</thead>
					<tbody id="workProjectPlans">
					<c:forEach items="${workEngineeringProject.workProjectPlans}" var="plan" varStatus="status">
						<c:if test="${plan.status eq 1}">
							<tr id="trId">
								<td>
									<i class="fa fa-check-circle"></i>
								</td>
								<td>
										${status.index+1}
								</td>
								<td>
										${plan.taskName}
								</td>
								<td>
									<fmt:formatDate value="${plan.startTime}" pattern="yyyy-MM-dd"/>
								</td>
								<td>
									<fmt:formatDate value="${plan.endTime}" pattern="yyyy-MM-dd"/>
								</td>
								<td>

									${plan.remindUser.name}
								</td>
								<td>
									<fmt:formatDate value="${plan.remindDate}" pattern="yyyy-MM-dd"/>
								</td>
								<td>
										${plan.completeUser.name}
								</td>
								<td>
									<fmt:formatDate value="${plan.completeDate}" pattern="yyyy-MM-dd"/>
									<input name="workProjectPlans[${status.index }].id" type="hidden" style="width:80px;" class="form-control required" value="${plan.id}"/>
								</td>
							</tr>
							<%--<tr id="trId">
								<td>
									已确认
									&lt;%&ndash;<input type="checkbox" id="${plan.id}" class="i-checks">&ndash;%&gt;
								</td>
								<td>
										${status.index+1}
								</td>
								<td>
									<input id="taskNames" name="workProjectPlans[${status.index }].taskName" type="text"  readonly="readonly" class="form-control required" value="${plan.taskName}"/>
								</td>
								<td>
									<input id="startTimes" name="workProjectPlans[${status.index }].startTime" type="text" readonly="readonly" maxlength="20" style="width:140px;" class="laydate-icondate form-control layer-date" value="<fmt:formatDate value="${plan.startTime}" pattern="yyyy-MM-dd"/>"/>
								</td>
								<td>
									<input  id="endTimes" name="workProjectPlans[${status.index }].endTime" type="text" readonly="readonly" maxlength="20" style="width:140px;" class="laydate-icondate form-control layer-date" value="<fmt:formatDate value="${plan.endTime}" pattern="yyyy-MM-dd"/>"/>
								</td>
								<td>
									<select id="remindUsers" name="workProjectPlans[${status.index}].remindUser.id" readonly="readonly" class="form-control m-b">
										<c:forEach items="${users}" var="list" >
											<option value="${list.id}" ${list.id==plan.remindUser.id?'selected':''}>${list.name}</option>
										</c:forEach>
									</select>
								</td>
								<td>
									<input id="remindDates" name="workProjectPlans[${status.index}].remindDate" type="text" readonly="readonly" maxlength="20" style="width:140px;" class="laydate-icondate form-control layer-date" value="<fmt:formatDate value="${plan.remindDate}" pattern="yyyy-MM-dd"/>"/>
								</td>
								<td>
									<select id="completeUsers" name="workProjectPlans[${status.index}].completeUser.id" readonly="readonly" class="form-control m-b">
										<c:forEach items="${userList}" var="list" >
											<option value="${list.id}" ${list.id==plan.completeUser.id?'selected':''}>${list.name}</option>
										</c:forEach>
									</select>
								</td>
								<td>
									<input id="completeDates" name="workProjectPlans[${status.index}].completeDate" type="text" readonly="readonly" maxlength="20" style="width:140px;" class="laydate-icondate form-control layer-date" value="<fmt:formatDate value="${plan.completeDate}" pattern="yyyy-MM-dd"/>"/>
									<input name="workProjectPlans[${status.index }].id" type="hidden" style="width:80px;" class="form-control required" value="${plan.id}"/>
								</td>
							</tr>--%>
						</c:if>
						<c:if test="${plan.status eq 0}">
							<tr id="trId">
								<td>
									<input type="checkbox" id="${plan.id}" class="i-checks">
								</td>
								<td>
										${status.index+1}
								</td>
								<td>
									<input name="workProjectPlans[${status.index }].taskName" type="hidden" class="form-control required" value="${plan.taskName}"/>
										${plan.taskName}
								</td>
								<td>
									<input name="workProjectPlans[${status.index}].startTime" type="hidden" value="<fmt:formatDate value="${plan.startTime}" pattern="yyyy-MM-dd"/>" class="form-control layer-date laydate-icon " readonly="readonly" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
									<fmt:formatDate value="${plan.startTime}" pattern="yyyy-MM-dd"/>
								</td>
								<td>
									<fmt:formatDate value="${plan.endTime}" pattern="yyyy-MM-dd"/>
									<input class="form-control layer-date laydate-icon " type="hidden" readonly="readonly" name="workProjectPlans[${status.index}].endTime" value="<fmt:formatDate value="${plan.endTime}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
								</td>
								<td>
									<%--<select id="${status.index}333" name="workProjectPlans[${status.index}].remindUser.id" class="form-control m-b">
										<option value="" label=""> </option>
										<c:forEach items="${users}" var="list" >
											<option value="${list.id}" ${list.id==plan.remindUser.id?'selected':''}>${list.name}</option>
										</c:forEach>
									</select>--%>
									${plan.remindUser.name}
										<input name="workProjectPlans[${status.index}].remindUser.id" type="hidden" class="form-control required" value="${plan.remindUser.id}"/>
								</td>
								<td><fmt:formatDate value="${plan.remindDate}" pattern="yyyy-MM-dd"/>
									<input class="form-control layer-date laydate-icon " type="hidden"  readonly="readonly" name="workProjectPlans[${status.index}].remindDate" value="<fmt:formatDate value="${plan.remindDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">

									</td>
								<td>
									<select id="${plan.id}233" name="workProjectPlans[${status.index}].completeUser.id" class="form-control m-b">
										<option value="" label=""> </option>
										<c:forEach items="${userList}" var="list" >
											<option value="${list.id}" ${list.id==plan.completeUser.id?'selected':''}>${list.name}</option>
										</c:forEach>
									</select>
								</td>
								<td>
									<input class="form-control layer-date laydate-icon " type="text"  readonly="readonly" name="workProjectPlans[${status.index}].completeDate" value="<fmt:formatDate value="${plan.completeDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">

									<input name="workProjectPlans[${status.index }].id" type="hidden" style="width:80px;" class="form-control required" value="${plan.id}"/>
								</td>
							</tr>
						</c:if>
					</c:forEach>
					<c:if test="${projectPlanList == 0}">
						<tr>
							<td colspan="6">暂无数据</td>
						</tr>
					</c:if>
					</tbody>
				</table>
				<br/><br/>
				<tr>
					<td class="width-35" colspan="3">
						<table id="listAttachment"  style="text-align: center;width: 100%;margin-top:10px;"  class="table table-striped table-bordered table-condensed" >
							<tr>
								<%--<td>序号</td>--%><td>文件名</td><td>上传人</td><td>上传时间</td><td>操作</td>
							</tr>
								<c:forEach items="${workAttachmentList}" var="attachment" varStatus="status">
									<tr>
									<%--<td>${status.index + 1}</td>--%>
									<%--<c:choose>
										<c:when test="${fn:containsIgnoreCase(attachment.attachmentName,'jpg')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'png')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'gif')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'jpeg')}">
											<td><img src="${attachment.url}" width="50" height="50" alt="${attachment.attachmentName}"/></td>
										</c:when>
										<c:otherwise>
											<c:choose>
												<c:when test="${fn:containsIgnoreCase(attachment.attachmentName,'pdf')}">
													<td><a href="${attachment.url}">${attachment.attachmentName}</a></td>
												</c:when>
												<c:otherwise>
													<td><a href="javascript:void(0)" onclick="openDialogViewPre('预览','${ctx}/previewController/previewUrl?fileUrl=${attachment.url}','80%','80%')">${attachment.attachmentName}</a></td>
												</c:otherwise>
											</c:choose>
										</c:otherwise>
									</c:choose>--%>
										<c:choose>
											<c:when test="${fn:containsIgnoreCase(attachment.attachmentName,'jpg')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'png')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'gif')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'bmp')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'jpeg')}">
												<td><img src="${attachment.url}" width="50" height="50" alt="${attachment.attachmentName}"/></td>
											</c:when>
											<c:otherwise>
												<c:choose>
													<c:when test="${fn:containsIgnoreCase(attachment.attachmentName,'pdf')}">
														<td><a href="javascript:void(0)" onclick="preview('预览','${attachment.url}','80%','80%','1')">${attachment.attachmentName}</a></td>
													</c:when>
													<c:otherwise>
														<%--<td><a href="javascript:void(0)" onclick="POBrowser.openWindow('${ctx}/previewController/previewUrl?fileUrl=${workClientAttachment.url}','80%','80%')">${workClientAttachment.attachmentName}</a></td>--%>
														<%--<td><a href="javascript:void(0)" onclick="POBrowser.openWindow('/ruihua/openword','80%','80%')">${workClientAttachment.attachmentName}</a></td>--%>
														<td><a href="javascript:void(0)" onclick="preview('预览','${attachment.url}','80%','80%')">${attachment.attachmentName}</a></td>
														<%--<td><a href="javascript:void(0)" onclick="POBrowser.openWindow('/ruihua/openexcel','80%','80%')">${workClientAttachment.attachmentName}</a></td>--%>
														<%--<td><a href="javascript:void(0)" onclick="POBrowser.openWindow('/ruihua/openppt','80%','80%')">${workClientAttachment.attachmentName}</a></td>--%>

													</c:otherwise>
												</c:choose>
											</c:otherwise>
										</c:choose>
									<td>${attachment.attachmentUser}</td>
									<td><fmt:formatDate value="${attachment.createDate}" pattern="yyyy-MM-dd"/></td>
									<td>
										<a href="${ctx}/workfullmanage/workFullManage/downLoadAttach?file=${attachment.url}" class="btn btn-success btn-xs">下载</a>
										<c:if test="${attachment.createBy.id eq fns:getUser().id}">
											<a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,'${ctx}/workengineeringproject/workEngineeringProject/deleteFileFromAliyun?attachmentId=${attachment.id}&id=${workEngineeringProject.id}&type=2')" class="btn btn-danger btn-xs" >删除</a>
										</c:if>
									</td>
							</tr>
						</c:forEach>
						</table>
					</td>
				</tr>

				</tbody>
			</table>

			</form:form>
</body>
</html>