<%@ 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">
		var validateForm;
		function doSubmit(obj){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(obj == 1){
                $('#flag').val('1');
            }else{
                $('#flag').val('2');
            }
		  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: '#contractStartTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });
            laydate.render({
                elem: '#contractEndTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });

            laydate.render({
                elem: '#tryEndTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });

            laydate.render({
                elem: '#transactTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                event: 'focus' //响应事件。如果没有传入event，则按照默认的click
            });
            $("#attachment_btn").click(function () {
                if($("#file_attachment tr").length>0){
                    top.layer.alert('仅可以上传一个附件', {icon: 0});
                    return;
                }
                $("#attachment_file").click();
            });
            /*$("input[name='renew']").on('ifChecked', function(event){
                var radioVal = $(this).val();
                console.log(radioVal+"----------radioVal");
                if(radioVal == 1){
                    //不续签
                }else{
                    //续签
                }
            });*/
            if("${workRelationship.renew}" == "1"){
                $("#renew1").iCheck('check')
            }else{
                $("#renew").iCheck('check')
            }
		});
        function insertTitle(tValue){
            var list = "${workRelationship.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 = "108";
            console.log(file);
            var timestamp=new Date().getTime();

            var storeAs = "attachment-file/workRelationship/"+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);}
        }
        function addRow(list, idx, workClientLinkmanTpl, row) {
            $(list).append(Mustache.render(workClientLinkmanTpl, {
                idx: idx, delBtn: true, row: row
            }));
            $(list + idx).find("select").each(function () {
                $(this).val($(this).attr("data-value"));
            });
            $(list + idx).find("input[type='checkbox'], input[type='radio']").each(function () {
                var ss = $(this).attr("data-value").split(',');
                for (var i = 0; i < ss.length; i++) {
                    if ($(this).val() == ss[i]) {
                        $(this).attr("checked", "checked");
                    }
                }
            });

        }
        function delRow(obj, prefix){
            var id = $(prefix+"_id");
            var delFlag = $(prefix+"_delFlag");
            if (id.val() == ""){
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).parent().parent().hide();
                $(obj).html("&divide;").attr("title", "撤回删除");
                $(obj).parent().parent().addClass("error");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }
        function selectUserInfo(id) {
            $.ajax({
                type:'post',
                data:{
                    "id":id
                },
                url:'${ctx}/workregularapply/workRegularApply/userInfo',
                success:function(data){
                    setUserInfo(data);
                }
            })
            setValuee(id);
        }
        function setValuee(obj){
            $('#workClientLinkmanList').html("");
            var rId = "${workRelationship.id}";
            //console.log(rId+"-------------");
            $.get("${ctx}/workrelationship/workRelationship/selectStaffUser", { rId:rId,sId: obj},
                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 setUserInfo(obj){
            $("#sNo").val(obj.no);
           // $("#basicInfoId").val(obj.id);
            //$("#name").val(obj.name);
            $("#sStatus").val(obj.status);
            $("#sIdCard").val(obj.idCard);
            $("#sOffice").val(obj.office.name);
            $("#sJobGrade").val(obj.jobGrade.name);
            $("#entryDate").val(obj.entryDate);
            $("#baseSalary").val(obj.salary);
        }
	</script>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workRelationship" action="${ctx}/workrelationship/workRelationship/saveAudit" method="post" class="form-horizontal">
		<form:hidden path="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"/>
			<%--<input name="renew" type="hidden" value="0">--%>
		<sys:message content="${message}"/>
			<div class="form-group layui-row first lw16">
				<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 with-icon">
						<div class="input-group">
						<%--<sys:gridSelectUserRship id="sId" name="workStaffBasicInfo.id" value="${workRelationship.workStaffBasicInfo.id}" labelName="workStaffBasicInfo.name" labelValue="${workRelationship.workStaffBasicInfo.name}"
											title="用户" url="${ctx}/sys/office/gridSelectUser" cssClass="form-control required layui-input" isAll="true" type="null"  isSingle="true"></sys:gridSelectUserRship>--%>
							<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.workStaffBasicInfo.name}"/>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">工号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.workStaffBasicInfo.no}"/>
							<span class="input-group-btn">
                            <label class="form-status"><c:choose><c:when test="${not empty workRelationship.status}">${fns:getDictLabel(workRelationship.status, 'audit_state', '')}</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">员工状态：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.workStaffBasicInfo.status}"/>
						<%--<form:select path="projectType" class="form-control required simple-select"  onChange="changeTypeExplain(this)">
							<form:option value="" label=""/>
							<form:options items="${fns:getDictList('bidProjectType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>--%>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">身份证号码：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.workStaffBasicInfo.idCard}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">部门：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.workStaffBasicInfo.office.name}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">职级：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.jobGrade}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">基本工资：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.pay}"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">入职日期：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input"
							   value="<fmt:formatDate value="${workRelationship.workStaffBasicInfo.entryDate}" pattern="yyyy年MM月dd日"/>"/>
						<%--input class="laydate-icondate layui-input form-control layer-date laydate-icon required"
							   id="contractDate" name="contractDate" value="<fmt:formatDate value="${workContractInfo.contractDate}"
							    pattern="yyyy-MM-dd"/>">--%>
					</div>
				</div>
			</div>

			<div class="form-group layui-row lw16">
				<div class="form-group-label"><h2>合同详情</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">是否续签：</label>
					<div class="layui-input-block">
						<c:if test="${workRelationship.renew eq 0}">
							<input  htmlEscape="false" value="续签" readonly="true" class="form-control layui-input"/>
						</c:if>
						<c:if test="${workRelationship.renew eq 1}">
							<input  htmlEscape="false" value="不续签" readonly="true" class="form-control layui-input"/>
						</c:if>
						<%--<input type="hidden"  name="renew" value="${workRelationship.renew}"/>--%>
					</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 htmlEscape="false"  readonly="true" class="form-control layui-input" value="${workRelationship.contractNum}"/>
					</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  htmlEscape="false" value="${fns:getDictLabel(workRelationship.contractType, 'relsp_cType', '')}" 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">
						<input  htmlEscape="false" value="${fns:getDictLabel(workRelationship.contractLimit, 'contract_limit', '')}" 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">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input"
							   value="<fmt:formatDate value="${workRelationship.contractStartTime}" pattern="yyyy年MM月dd日"/>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">合同终止日期：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input"
							   value="<fmt:formatDate value="${workRelationship.contractEndTime}" pattern="yyyy年MM月dd日"/>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label">试用期结束日期：</label>
					<div class="layui-input-block">
						<input htmlEscape="false"  readonly="true" class="form-control layui-input"
							   value="<fmt:formatDate value="${workRelationship.tryEndTime}" pattern="yyyy年MM月dd日"/>"/>
					</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 htmlEscape="false"  readonly="true" class="form-control layui-input"
							   value="<fmt:formatDate value="${workRelationship.transactTime}" pattern="yyyy年MM月dd日"/>"/>
					</div>
				</div>


			</div>

			<div class="form-group layui-row">
				<div class="form-group-label"><h2>附件信息</h2></div>
					<%--<div class="layui-item nav-btns">
                        <a id="attachment_btn" class="nav-btn nav-btn-add" title="添加附件"><i class="fa fa-plus"></i>&nbsp;添加附件</a>
                    </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 width="150px">操作</th>
						</tr>
						</thead>
						<tbody id="file_attachment">

						<c:forEach items="${workRelationship.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}"></td>
									</c:when>
									<c:otherwise>
										<c:choose>
											<c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'pdf')}">
												<td><a href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%','1')">${workClientAttachment.attachmentName}</a></td>
											</c:when>
											<c:otherwise>
												<td><a 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(encodeURIComponent('${workClientAttachment.url}'));" class="op-btn op-btn-download"><i class="fa fa-download"></i>&nbsp;下载</a>

										<%--<c:if test="${workClientAttachment.createBy.id eq fns:getUser().id}">
											<a href="javascript:void(0)" onclick="deleteFileFromAliyun(this,'${ctx}/sys/workattachment/deleteFileFromAliyun?url=${workClientAttachment.url}&id=${workClientAttachment.id}&type=2','addFile')" class="op-btn op-btn-delete" ><i class="fa fa-trash"></i>&nbsp;删除</a>
										</c:if>--%>
									</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 nav-btns">
					<a class="nav-btn nav-btn-add" onclick="addRow('#workClientLinkmanList', workClientLinkmanRowIdx, workClientLinkmanTpl);workClientLinkmanRowIdx = workClientLinkmanRowIdx + 1;" title="新增"><i class="fa fa-plus"></i>&nbsp;新增</a>
				</div>--%>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<table id="contentTable2" class="table table-bordered table-condensed details">
						<thead>
						<tr>
							<th>合同编号</th>
							<th>合同类型</th>
							<th>合同期限</th>
							<th>合同起始日期</th>
							<th>合同终止日期</th>
							<th>办理日期</th>
							<th width="160px">附件</th>
						</tr>
						</thead>
						<tbody id="workClientLinkmanList">
						<c:forEach items="${workRelationship.workRelationships}" var="buyDetails" varStatus="status">
							<tr>
								<td>${buyDetails.contractNum}</td>
								<td>${fns:getDictLabel(buyDetails.contractType, 'relsp_cType', '')}</td>
								<td>${fns:getDictLabel(buyDetails.contractLimit, 'contract_limit', '')}</td>
								<td><fmt:formatDate value="${buyDetails.contractStartTime}" pattern="yyyy-MM-dd"/></td>
								<td><fmt:formatDate value="${buyDetails.contractEndTime}" pattern="yyyy-MM-dd"/></td>
								<td><fmt:formatDate value="${buyDetails.transactTime}" pattern="yyyy-MM-dd"/></td>
								<%--试用期结束时间<td><fmt:formatDate value="${buyDetails.tryEndTime}" pattern="yyyy-MM-dd"/></td>--%>

									<c:forEach items="${buyDetails.workAttachments}" var = "workClientAttachment" varStatus="status">
										<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}"></td>
											</c:when>
											<c:otherwise>
												<c:choose>
													<c:when test="${fn:containsIgnoreCase(workClientAttachment.attachmentName,'pdf')}">
														<td><a href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%','1')">${workClientAttachment.attachmentName}</a></td>
													</c:when>
													<c:otherwise>
														<td><a href="javascript:void(0)" onclick="preview('预览','${workClientAttachment.url}','90%','90%')">${workClientAttachment.attachmentName}</a></td>
													</c:otherwise>
												</c:choose>
											</c:otherwise>
										</c:choose>
									</c:forEach>
							</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-sm12 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" />
						<input type="file" name="upload_files" style="display: none;">
					</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="${workRelationship.act.procInsId}"/>
					<act:histoicFlow procInsId="${workRelationship.act.procInsId}"/>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>