<%@ 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);
                    }
                }
            });
            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
        });


        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;
                        }
                    }
                });
        }

        function openBill(title,url,width,height,target,formId,eleId){
            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            top.layer.open({
                type: 2,
                area: [width, height],
                title: title,
                maxmin: true, //开启最大化最小化按钮
                content: url ,
                btn: ['确定','关闭'],
                yes: 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中展示
                    var $document = iframeWin.contentWindow.document;
                    formSubmit($document,formId,eleId,index);
                },
                cancel: function(index){
                }
            });
        }
        function formSubmit($document,inputForm,workProjectPlans,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);
                    }
                }
            });
            var data  = 'error'
            if(validateForm.form()){
                $($document.getElementById(inputForm)).ajaxSubmit({
                    success:function(data) {
                        var d = data;
                        parent.layer.msg(d.str,{icon:1});
                        top.layer.close(index)
                        location.reload();
                    }
                });
            }
        }

        function insertTitle(tValue){
            var list = "${workAttachmentList}";
            var size = (list.split('url')).length-1;
            var files = $("#attachment_file")[0].files;            for(var i = 0;i<files.length;i++) {                var file = files[i];
            var attachmentId = $("#id").val();
            var attachmentFlag = "4";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workProjectPlan/"+timestamp+"/"+file['name'];
            var uploadPath="http://gangwan-app.oss-cn-hangzhou.aliyuncs.com/"+storeAs;/*将这段字符串存到数据库即可*/
            var divId = "_attachment";
            $("#addFile"+divId).show();
            multipartUploadWithSts(storeAs, file,attachmentId,attachmentFlag,uploadPath,divId,size);}
            /*var formData = new FormData();
            formData.append("attachment_file",$("#attachment_file")[0].files[0]);
            formData.append("srcName","workEngineeringProject");
            formData.append("attachmentFlag","4");
            formData.append("id",$("#id").val());
            $.ajax({
                url:'${ctx}/sys/workattachment/uploadFiletoAly',
                type:"POST",
                data:formData,
                processData:false,
                contentType:false,
                cache:false,
                success:function(data){
                   if(data.status=="Success"){
                       parent.layer.msg("上传成功！",{icon:1});
                       var lenght = $("#workAttachments tr").length;
                       var str = '<tr id="trIdAdds">'+
                       '<td>'+(lenght+1)+'</td>'+
                       '<td>' ;
                       if (isContains("jpg,png,gif,bmp,jpeg",data.type)){
                           str = str +'<img src="'+data.url+'" width="50" height="50" alt="'+data.attachmentName+'"/>';
                       }else if(isContains("pdf",data.type)){
                           str = str + '<a href="javascript:void(0)" onclick="preview(\'预览\',\''+data.url+'\',\'800px\',\'500px\',\'1\')">'+data.attachmentName+'</a>';
                       }else {
                           str = str + '<a href="javascript:void(0)" onclick="preview(\'预览\',\''+data.url+'\',\'800px\',\'500px\')">'+data.attachmentName+'</a>';
                       }
                       str = str +'</td>'+
                       '<td>'+data.createByName+'</td>'+
                       '<td>'+data.createDate+
							   '<input name="workAttachments['+lenght+'].id" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.id+'"/>'+
							   '<input name="workAttachments['+lenght+'].attachmentId" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.attachmentId+'"/>'+
							   '<input name="workAttachments['+lenght+'].url" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.url+'"/>'+
							   '<input name="workAttachments['+lenght+'].attachmentName" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.attachmentName+'"/>'+
							   '<input name="workAttachments['+lenght+'].createBy.id" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.createBy+'"/>'+
							   '<input name="workAttachments['+lenght+'].type" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.type+'"/>'+
							   '<input name="workAttachments['+lenght+'].attachmentFlag" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="'+data.attachmentFlag+'"/>'+
						 '</td>'+
						'<td>'+
                       '<a href="${ctx}/workfullmanage/workFullManage/downLoadAttach?file='+data.url+'" class="btn btn-success btn-xs">下载</a>'+
                       '    <a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,\'${ctx}/workengineeringproject/workEngineeringProject/deleteFileFromAliyun?attachmentId='+data.id+'&url='+data.url+'&id=${workEngineeringProject.id}&type=2\')" class="btn btn-danger btn-xs" >删除</a>'+
                       '    </td>'+
                       '</tr>';
                       $(workAttachments).append(str);
                       $("img").not(".upload_ico").each(function () {
                           var num = 1 ;
                           $(this).live("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++;
                               }
                           })
                       });
                   }else {
                       parent.layer.msg("上传失败！",{icon:2});
                   }

                }
            });
            $("#attachment_title_div").remove();
            var t1 = tValue.lastIndexOf("\\");
            if(t1 >= 0 && t1 < tValue.length){
                $("#attachment_title").text(tValue.substring(t1+1));
                $("#attachment_title").after("<div id='attachment_title_div' style='float: right'>&nbsp;&nbsp;<span id='attachment_delete' onclick='attachment_del()'style='color: red ; cursor: pointer;'>x</span></div>");
            }*/
        }
        function attachment_del() {
            $("#attachment_file").val("");
            $("#attachment_title").text("");
            $("#attachment_delete").remove();
            $("#attachment_title_div").remove();
        }
        function deleteRowAll(obj){
            $.ajax({
                type:'post',
                url:'${ctx}/workengineeringproject/workEngineeringProject/deleteRow',
                data:{
                    "ids":obj
                },
                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();
                }
            })
        }
        function isContains(str, substr) {
            return str.indexOf(substr) >= 0;
        }

        function preview(title,url,width,height,type){
            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            var u = 'http://ow365.cn/?i=14411&furl='+url;
            if(type == 1){
                u = url;
            }
            parent.layer.open({
                type: 2,
                area: [width, height],
                title: title,
                maxmin: true, //开启最大化最小化按钮
                content:  u,
                btn: ['关闭'],
                cancel: function(index){
                }
            });
        }
	</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:removeRow url="${ctx}/workengineeringproject/workEngineeringProject/deleteRow" id="contentTable"></table:removeRow><!-- 删除按钮 -->

						&nbsp;
						<span onclick="openBill('添加','${ctx}/workengineeringproject/workEngineeringProject/addPlanRow?id=${workEngineeringProject.id}&businessType=${workEngineeringProject.businessType}','80%','80%',false,'inputForm','#workProjectPlans')" class="btn btn-primary btn-sm" ><i class="fa fa-plus"></i>添加</span>
					</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" 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" id="checkboxId" class="i-checks"></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"/>
										<input name="workProjectPlans[${status.index}].id" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.id}"/>
										<input name="workProjectPlans[${status.index}].completeUser" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.completeUser}"/>
										<%--<input name="workProjectPlans[${status.index}].completeDate" type="hidden" 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}].type" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.type}"/>
										<input name="workProjectPlans[${status.index}].status" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.status}"/>
										<input class="form-control layer-date laydate-icon required" type="hidden" name="workProjectPlans[${status.index}].completeDate" value="<fmt:formatDate value="${plan.completeDate}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
									</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>
									<td>
											${status.index+1}
									</td>
									<td>
										<input name="workProjectPlans[${status.index }].taskName" type="text" class="form-control required" value="${plan.taskName}"/>
									</td>
									<td>
										<input class="form-control layer-date laydate-icon " readonly="readonly" name="workProjectPlans[${status.index}].startTime" value="<fmt:formatDate value="${plan.startTime}" pattern="yyyy-MM-dd"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
										<%--<input id="startTime" 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 class="form-control layer-date laydate-icon " 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 +233}" 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>
									</td>
									<td>
										<input class="form-control layer-date laydate-icon " 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'})">
										<input name="workProjectPlans[${status.index}].id" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.id}"/>
										<input name="workProjectPlans[${status.index}].completeUser" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.completeUser}"/>
										<input class="form-control layer-date laydate-icon required" type="hidden" 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}].type" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.type}"/>
										<input name="workProjectPlans[${status.index}].status" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${plan.status}"/>
									</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-15 active"><label class="pull-left">上传附件表：</label></td>
					<td class="width-35" colspan="3">
						<div style="display: inline-block">
							<div id="addFile_attachment" style="display: none">
								<div>
									<span id="fileName_attachment" ></span>
									<b><span id="baifenbi_attachment" ></span></b>
								</div>
								<div>
									<div class="progress">
										<div id="jindutiao_attachment" class="progress-bar" style="width: 0%" aria-valuenow="0">
										</div>
									</div>
								</div>
							</div>
							<input id="attachment_file" type="file" name="attachment_file" multiple="multiple" style="display: none;" onChange="if(this.value)insertTitle(this.value);"/>
							<a id="attachment_btn" class="btn btn-info btn-xs" ><i class="fa fa-plus"></i> 添加附件</a>
							<span id="attachment_title"></span>
						</div>
					</td>
					<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" >
							<thead>
								<tr>
									<%--<td>序号</td>--%><td>文件名</td><td>上传人</td><td>上传时间</td><td>操作</td>
								</tr>
							</thead>
							<tbody id="file_attachment">
								<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>
										<input name="workAttachments[${status.index}].id" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${attachment.id}"/>
										<input name="workAttachments[${status.index}].url" type="hidden" readonly="readonly" maxlength="20" style="width:140px;" class="form-control" value="${attachment.url}"/>
									</td>
								</tr>
								</c:forEach>
							</tbody>
						</table>
					</td>
				</tr>
				<br/><br/>
				<tr>
					<td class="width-15 active"><label class="pull-left"><font color="red">*</font>变更原因：</label></td>
					<td class="width-35" colspan="3">
						<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control required"/>
					</td>
				</tr>
				<br/><br/>
				<table id="planTable" class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
					<thead>
						<tr>
							<th>序号</th>
							<th>变更人</th>
							<th>变更原因</th>
							<th>变更时间</th>
						</tr>
					</thead>
					<tbody id="planInfo">
						<c:forEach items="${workProjectPlanEdits}" var="planEdit" varStatus="status">

							<tr id="trIds">
								<td>${status.index + 1}</td>
								<td>${planEdit.updateBy.name}</td>
								<td>${planEdit.remarks}</td>
								<td><fmt:formatDate value="${planEdit.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
							</tr>
							</c:forEach>
							<c:if test="${projectPlanList == 0}">
								<tr>
									<td colspan="6">暂无数据</td>
								</tr>
							</c:if>
					</tbody>
				</table>
			</tbody>
		</table>

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