<%@ 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">
        var validateForm;
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }

            return false;
        }
        $(document).ready(function() {
            $("#name").focus();
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    var len = $("#showPeo span").length;
                    if(len<=0){
                        parent.layer.msg("请选择审批人!",{icon:5});
                        return false;
                    }
                    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);
                    }
                }
            });
			//只做查看时，禁用掉以下标签
            if('${sessionScope.state}' =='disabled'){
                $('input,textarea,select').attr('disabled','<%=session.getAttribute("state")%>');
            }else if('${sessionScope.state}' !='disabled'){
                $('input,textarea,select').removeAttr('disabled');
            }
            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
        });
        function selectPeople(objId,objName){
            var showPeo = $("#showPeo").html();
            var len = $("#showPeo span").length;
            if(len > 4){
                parent.layer.msg("最多添加5个审批人",{icon:5})
                return;
            }
            var arr = [];
            var a = $("#showPeo span").each(function(){
                var dataId = $(this).attr("data-id");
                arr.push(dataId)
            })
            if(arr.indexOf(objId) != -1){
                parent.layer.msg("该审批人已被选择，不能重复选择！！！",{icon:5})
                return ;
            }
            showPeo = showPeo + '<span class="badge badge-success fontSpan" data-id="'+objId+'">'+objName+'&nbsp;&nbsp;&nbsp;' +
                '<i onclick=deletePeo(this) class="fa fa-close"></i><input type="hidden" name=adds['+len+'] value="'+objId+'"></span>';
            $("#showPeo").html(showPeo)
        }
        //删除选择的人员
        function deletePeo(obj){
            $(obj).parent().remove()
        }
        function insertTitle(tValue){
            var list = "${workSealForm.workAttachments}";
            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 = "68";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workSealForm/"+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);}
        }

	</script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
	<div class="ibox">
		<c:if test="${sessionScope.state!='disabled'}">
		<div class="ibox-title" style="height: 70px;">
			<h5>
				<ul class="nav nav-tabs">
					<li><a href="${ctx}/worksealform/workSealForm/list">用印信息</a></li>
					<li><a href="${ctx}/worksealform/workSealForm/workSealFormTodoList">待办任务</a></li>
					<li><a href="${ctx}/worksealform/workSealForm/workSealFormHistoricList">已办任务</a></li>
					<shiro:hasPermission name="worksealform:workSealForm:edit"><li class="active"><a href="${ctx}/worksealform/workSealForm/form?ids=0">用印申请</a></li></shiro:hasPermission>
				</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>
				<ul class="dropdown-menu dropdown-user">
					<li><a href="javascript:void(0)">选项1</a>
					</li>
					<li><a href="javascript:void(0)">选项2</a>
					</li>
				</ul>
				<a class="close-link">
					<i class="fa fa-times"></i>
				</a>
			</div>--%>
		</div>
		</c:if>
		<div class="ibox-content">
			<form:form id="inputForm" modelAttribute="workSealForm" action="${ctx}/worksealform/workSealForm/save" method="post" class="form-horizontal">
				<form:hidden path="id"/>
				<c:set var="id" value="${workSealForm.id}" />
				<c:set var="ids" value="${workSealForm.ids}" />
				<sys:message content="${message}"/>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>用印文件名称：</label>
					<div class="controls">
						<input id="documentName" name="documentName" type="text" class="form-control required" value="${workSealForm.documentName}"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>文件个数：</label>
					<div class="controls">
						<input id="documentCount" name="documentCount" type="text" class="form-control required" value="${workSealForm.documentCount}"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>申请时间：</label>
					<div class="controls">
						<input class="form-control layer-date laydate-icon required" id="applicationDate" name="applicationDate" readonly="readonly" value="<fmt:formatDate value="${workSealForm.applicationDate}" pattern="yyyy-MM-dd HH:mm:ss"/>" onclick="laydate({istime: false, format: 'YYYY-MM-DD'})">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>印章类型：</label>
					<div class="controls">
						<form:select path="sealType" class="form-control required">
							<form:options items="${fns:getMainDictList('seal_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>经办人：</label>
					<div class="controls">
						<sys:treeselect id="user" name="user" value="${workSealForm.user.id}" labelName="user.name" labelValue="${workSealForm.name}"
										title="用户" url="/sys/office/treeData?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>用印部门：</label>
					<div class="controls">
						<sys:treeselect id="office" name="office.id" value="${workSealForm.office.id}" labelName="office.name" labelValue="${workSealForm.officeName}"
										title="部门" url="/sys/office/treeData?type=2" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label"><font color="red">*</font>用印原因：</label>
					<div class="controls">
						<form:textarea path="reason" class="form-control required" rows="3" maxlength="20"/>
						<span class="help-inline"></span>
					</div>
				</div>
				<c:if test="${empty id}">
					<div class="control-group">
						<label class="control-label">抄送人：</label>
						<div id="CCId" class="controls">
							<sys:treeselect id="CCId" name="CCId" value="${workSealForm.CCId}" labelName="idNames" labelValue="${workSealForm.idNames}"
											title="用户" url="/sys/office/treeDataAll?type=3&isAll=false" cssClass="form-control" allowClear="true" checked="true" notAllowSelectParent="true"/>
							<span class="help-inline"></span>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label"><font color="red">*</font>审批人：</label>
						<div id="addida" class="controls">
							<sys:treeselectleave id="ida" name="ida" value="${workSealForm.ida}" labelName="idNamea" labelValue="${workSealForm.idNamea}"
											title="用户" url="/sys/office/treeDataAll?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
							<span class="help-inline"></span>
						</div>
						<div id="showPeo" class="controls">
						</div>
					</div>
				<div class="control-group">
					<label class="control-label">附件信息：</label>
					<div id="fileid" class="controls">
						<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_report" 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>
						<table id="workReportList"  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="${workSealForm.workAttachments}" 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,'bmp')
                                                               or fn:containsIgnoreCase(attachment.attachmentName,'jpeg')}">
											<td><img src="${attachment.url}" width="50" height="50" alt="${fns:abbr(attachment.attachmentName,30)}"/></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')"><span title="${attachment.attachmentName}">${fns:abbr(attachment.attachmentName,30)}</span></a></td>
												</c:when>
												<c:otherwise>
													<td><a href="javascript:void(0)" onclick="preview('预览','${attachment.url}','80%','80%')"><span title="${attachment.attachmentName}">${fns:abbr(attachment.attachmentName,30)}</span></a></td>
												</c:otherwise>
											</c:choose>
										</c:otherwise>
									</c:choose>
									<td>${attachment.attachmentUser}</td>
									<td><fmt:formatDate value="${attachment.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
									<td>
										<a href="javascript:location.href='${ctx}/workfullmanage/workFullManage/downLoadAttach?file='+encodeURIComponent('${attachment.url}');" class="btn btn-success btn-xs">下载</a>

									<%--<a href="${ctx}/workfullmanage/workFullManage/downLoadAttach?file=${attachment.url}" class="btn btn-success btn-xs">下载</a>--%>
										<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>
									</td>
								</tr>
							</c:forEach>
							</tbody>
						</table>
					</div>
				</div>
					<c:if test="${not empty ids}">
						<div class="form-actions">
							<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
							<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
						</div>
					</c:if>
				</c:if>
			</form:form>
		</div>
	</div>
</div>
<%
	session.removeAttribute("state");
%>
</body>
</html>

