<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>请假管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
          /*  var status=${leaveApply.status};
            if(status==6){
                $("#inputForm").attr("action","${ctx}/leaveapply/leaveApply/saveBackAudit");
            }else if(status==2){
                $("#inputForm").attr("action","${ctx}/leaveapply/leaveApply/saveAudit");
			}else if(status==10){
                $("#inputForm").attr("action","${ctx}/leaveapply/leaveApply/saveExtendAudit");
			}*/
            if(validateForm.form()){
                if(obj == 1){
                    $('#flag').val('yes');
                }else{
                    $('#flag').val('no');
                }
                $("#inputForm").submit();
                return true;
            }

            return false;
        }
        var validateForm;
        var count = 0;
        $(document).ready(function() {
            if($("#applyTime").val()==null || $("#applyTime").val()==''){
                $("#applyTime").val(getNowFormatDate());
            }
            $("#attachment_btn").click(function () {
                $("#attachment_file").click();
            });
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                rules:{
                },
                messages:{
                },
                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);
                    }
                }
            });

        });

        function insertTitle(tValue){
            var list = "${leaveApply.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 = "";
            var attachmentFlag = "114";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/leaveApply/"+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>
	<style>
		/*超过5个汉字，调整label的长度，以下是配套的*/
		.layui-item .layui-form-label{
			width:90px;
		}
		.form-group .layui-item .layui-input-block,
		.query .layui-input-block {
			margin-left: 116px;
		}
	</style>
</head>
<body>
<div class="single-form">
	<div class="container view-form">
		<form:form id="inputForm" modelAttribute="leaveApply" action="${ctx}/leaveapply/leaveApply/saveAudit" method="post" class="form-horizontal" >
			<form:hidden path="id"/>
			<form:hidden path="basicInfo.id"/>
			<form:hidden path="home"/>
			<form:hidden path="act.taskId"/>
			<form:hidden path="act.taskName"/>
			<form:hidden path="act.taskDefKey"/>
			<form:hidden path="act.procInsId"/>
			<form:hidden path="act.procDefId"/>
			<form:hidden id="flag" path="act.flag"/>
			<div class="form-group layui-row first">
				<div class="form-group-label"><h2>基础信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>姓名：</label>
					<div class="layui-input-block">
						<form:input id="name" path="basicInfo.name" htmlEscape="false" readonly="true"  class="form-control layui-input" />
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>请假编号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<form:input id="no" path="no" htmlEscape="false"  readonly="true"  class="form-control  layui-input"/>
							<span class="input-group-btn">
                                <label class="form-status"><c:choose><c:when test="${not empty leaveApply.status}">${fns:getDictLabel(leaveApply.status, 'leave_audit', '')}</c:when><c:otherwise>新增</c:otherwise></c:choose></label>
                             </span>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>工号：</label>
					<div class="layui-input-block">
						<form:input readonly="true" path="basicInfo.no" htmlEscape="false" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>员工状态：</label>
					<div class="layui-input-block">
						<form:input  path="basicInfo.status" htmlEscape="false" readonly="true"  class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>部门：</label>
					<div class="layui-input-block">
						<form:input readonly="true" path="basicInfo.office.name" htmlEscape="false" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>职级：</label>
					<div class="layui-input-block">
						<form:input  readonly="true" path="basicInfo.jobGrade.name" htmlEscape="false" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>申请日期：</label>
					<div class="layui-input-block">
						<input id="applyTime" name="applyTime" readonly="true" type="text"  maxlength="20" class="laydate-icondate form-control layer-date  layui-input laydate-icon"
							   value="<fmt:formatDate value="${leaveApply.applyTime}" pattern="yyyy-MM-dd"/>"/>
					</div>
				</div>
				<c:choose><c:when test="${leaveApply.status == 6 or leaveApply.status ==7 or leaveApply.status == 9 }">
					<div class="layui-item layui-col-sm6 status" >
						<label class="layui-form-label"><span class="require-item">*</span>销假日期：</label>
						<div class="layui-input-block">
							<input id="backTime" name="backTime" readonly="true" type="text"  maxlength="20" class="laydate-icondate form-control layer-date  layui-input laydate-icon query-group"
								   value="<fmt:formatDate value="${leaveApply.backTime}" pattern="yyyy-MM-dd"/>"/>
							<span class="group-sep">-</span>
							<input  htmlEscape="false" readonly="true"   class="form-control layui-input  query-group" value="${fns:getDictLabel(leaveApply.backStartType, 'date_type', '')}"/>
							<form:select cssStyle="display: none" path="backStartType" class="form-control  simple-select query-group">
								<form:options items="${fns:getDictList('date_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
							</form:select>
						</div>
					</div>
					<div class="layui-item layui-col-sm6 status">
						<label class="layui-form-label"><span class="require-item">*</span>销假对比：</label>
						<div class="layui-input-block">
							<form:input id="contrast" readonly="true" path="contrast" htmlEscape="false" class="form-control layui-input"/>
						</div>
					</div>

				</c:when>
					<c:otherwise>

					</c:otherwise>
				</c:choose>
				<div class="layui-item layui-col-sm12  with-textarea">
					<label class="layui-form-label">请假原因：</label>
					<div class="layui-input-block">
						<form:textarea path="reason" htmlEscape="false" rows="3" readonly="true"   maxlength="127" class="form-control "/>
					</div>
				</div>
			</div>
			<div class="form-group layui-row">
				<div class="form-group-label"><h2>假期详情</h2></div>
				<%--<div class="layui-item nav-btns ">
					<sys:treeselectlea id="exampleInfo" name="" value="" labelName="" labelValue="" title="假期类型" url="/leaveapply/leaveApply/treeDataTypeInfo"  cssClass="form-control  "
									   allowClear="true" notAllowSelectParent="true"/>
				</div>--%>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<table id="contentTable" class="table table-bordered table-condensed can-edit no-bottom-margin">
						<thead>
						<tr>
							<th width="150px">假期名称</th>
							<th width="150px">计假模式</th>
							<th width="150px" colspan="2" >开始时间</th>
							<th width="150px" colspan="2">结束时间</th>
							<th width="100px">请假天数</th>
						</tr>
						</thead>
						<tbody id="leaveDetailList">
						<c:if test="${not empty leaveApply.leaveDetailList}">
							<c:forEach items="${leaveApply.leaveDetailList}" var="leaveDetail" varStatus="index">
								<tr id="leaveDetailList${index.index}">
									<td class="hide">
										<input id="leaveDetailList${index.index}_id" name="leaveDetailList[${index.index}].id" type="hidden" value="${leaveDetail.id}"/>
										<input id="leaveDetailList${index.index}_leaveType" name="leaveDetailList[${index.index}].leaveType.id" type="hidden" value="${leaveDetail.leaveType.id}"/>
										<input id="leaveDetailList${index.index}_delFlag" name="leaveDetailList[${index.index}].delFlag" type="hidden" value="0"/>
										<input id="leaveDetailList${index.index}_flag" name="leaveDetailList[${index.index}].flag" type="hidden" value="${leaveDetail.flat}"/>
									</td>
									<td>
										<input id="leaveDetailList${index.index}_1"  readonly="true"   type="text" value="${leaveDetail.leaveType.name}"   class="form-control "/>
									</td>
									<td>
										<input id="leaveDetailList${index.index}_2"  readonly="true"   type="text" value="${fns:getDictLabel(leaveDetail.leaveType.model, 'fake_model', '')}"   class="form-control "/>
									</td>
									<td>
										<input idx="${index.index}" style="width: 150px" readonly="true"  id="leaveDetailList${index.index}_3" name="leaveDetailList[${index.index}].startTime"  type="text" maxlength="20" class="  form-control layui-input "
											   value="<fmt:formatDate value="${leaveDetail.startTime}" pattern="yyyy-MM-dd"/>"/>
										</input>
									</td>
									<td>
										<input id="leaveDetailList${index.index}_4" style="width: 150px" readonly="true"   type="text" value="${fns:getDictLabel(leaveDetail.startType, 'date_type', '')}"   class="form-control "/>
									</td>
									<td>
										<input idx="${index.index}" style="width: 150px" readonly="true"  id="leaveDetailList${index.index}_5" name="leaveDetailList[${index.index}].endTime"type="text" maxlength="20" class="  form-control  layui-input  "
											   value="<fmt:formatDate value="${leaveDetail.endTime}" pattern="yyyy-MM-dd"/>"/>
										</input>
									</td>
									<td>
										<input id="leaveDetailList${index.index}_6" style="width: 150px" readonly="true"   type="text" value="${fns:getDictLabel(leaveDetail.endType, 'date_type', '')}"   class="form-control "/>
									</td>
									<td>
										<input id="leaveDetailList${index.index}_7" onchange="getMoney(this.value)" name="leaveDetailList[${index.index}].days" type="text" value="${leaveDetail.days}" readonly="true"  class="form-control number "/>
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
					<table id="contentMoneys" class="table table-bordered table-condensed can-edit summary">
						<tr>
							<td  style="vertical-align:middle;width:300px;text-align: center;"><label><font color="red">*</font>请假时长：</label></td>
							<td >
								<input htmlEscape="false" id="longTime" name="longTime" value="${leaveApply.longTime}" readonly="true" class="form-control layui-input" />
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-group layui-row">
				<div class="form-group-label"><h2>历史详情</h2></div>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<table id="hisContentTable" class="table table-bordered table-condensed can-edit no-bottom-margin">
						<thead>
						<tr>
							<th width="200px">假期名称</th>
							<th width="200px">累计天数</th>
							<th width="200px">累计次数</th>
							<th width="200px">上限天数</th>
						</tr>
						</thead>
						<tbody id="hisLeaveDetailList">
						<c:if test="${not empty leaveApply.hisLeaveDetailList}">
							<c:forEach items="${leaveApply.hisLeaveDetailList}" var="leaveDetail" varStatus="index">
								<tr id="hisLeaveDetailList${index.index}">
									<td>
										<input id="hisLeaveDetailList${index.index}_1"  readonly="true"   type="text" value="${leaveDetail.name}"   class="form-control "/>
									</td>
									<td>
										<input id="hisLeaveDetailList${index.index}_2"  readonly="true"   type="text" value="${leaveDetail.sumDays}"   class="form-control "/>
									</td>
									<td>
									    <input id="hisLeaveDetailList${index.index}_3"   readonly="true" type="text" value="${leaveDetail.counts}"   class="form-control require"/>
								    </td>
									<td>
										<input id="hisLeaveDetailList${index.index}_4"  readonly="true"  type="text" value="${leaveDetail.days}"   class="form-control require"/>
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
				</div>
			</div>
			<div class="form-group layui-row">
				<div class="form-group-label"><h2>附件信息</h2></div>
				<div id="addFile_attachment" style="display: none" class="upload-progress">
					<span id="fileName_attachment" ></span>
					<b><span id="baifenbi_attachment" ></span></b>
					<div class="progress">
						<div id="jindutiao_attachment" class="progress-bar" style="width: 0%" aria-valuenow="0">
						</div>
					</div>
				</div>
				<input id="attachment_file" type="file" name="attachment_file" multiple="multiple" style="display: none;" onChange="if(this.value)insertTitle(this.value);"/>
				<span id="attachment_title"></span>
				<div class="layui-item layui-col-xs12" style="padding:0 16px;">
					<table id="upTable" class="table table-bordered table-condensed details">
						<thead>
						<tr>
								<%-- <th>序号</th>--%>
							<th>文件预览</th>
							<th>上传人</th>
							<th>上传时间</th>
							<th width="150px">操作</th>
						</tr>
						</thead>
						<tbody id="file_attachment">
						<c:forEach items="${leaveApply.workAttachments}" var = "workClientAttachment" varStatus="status">
							<tr>
									<%-- <td>${status.index + 1}</td>--%>
								<c:choose>
									<c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'jpg')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'png')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'gif')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'bmp')
                                                           or fn:containsIgnoreCase(workClientAttachment.attachmentName,'jpeg')}">
										<td><img src="${workClientAttachment.url}" width="50" height="50" onclick="openDialogView('预览','${ctx}/sys/picturepreview/picturePreview?url=${workClientAttachment.url}','90%','90%')" alt="${workClientAttachment.attachmentName}">
									</c:when>
									<c:otherwise>
										<c:choose>
											<c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'pdf')}">
												<td><a class="attention-info" href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%','1')">${workClientAttachment.attachmentName}</a></td>
											</c:when>
											<c:otherwise>
												<td><a class="attention-info" href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%')">${workClientAttachment.attachmentName}</a></td>
											</c:otherwise>
										</c:choose>
									</c:otherwise>
								</c:choose>
								<td>${workClientAttachment.createBy.name}</td>
								<td><fmt:formatDate value="${workClientAttachment.createDate}" type="both"/></td>
								<td class="op-td">
									<div class="op-btn-box" >
										<a href="javascript:location.href='${ctx}/workfullmanage/workFullManage/downLoadAttach?file='+encodeURIComponent('${workClientAttachment.url}');" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>
									</div>
								</td>
							</tr>
						</c:forEach>
						</tbody>
					</table>
				</div>
			</div>
			<div class="form-group layui-row">
				<div class="form-group-label"><h2>审批意见</h2></div>
				<div class="layui-item layui-col-xs12 with-textarea" >
					<label class="layui-form-label">审批意见：</label>
					<div class="layui-input-block">
						<form:textarea path="act.comment" class="form-control" rows="4" maxlength="127" />
					</div>
				</div>
			</div>
			<div class="form-group layui-row">
				<div class="form-group-label"><h2>审批流程</h2></div>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<act:flowChart procInsId="${leaveApply.act.procInsId}"/>
					<act:histoicFlow procInsId="${leaveApply.act.procInsId}"/>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>

</body>
</html>