<%@ 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;
        var count = 0;
        $(document).ready(function() {
            if($("#createDate").val()==null || $("#createDate").val()==''){
                $("#createDate").val(getNowFormatDate());
            }
            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);
                    }
                }
            });

         /*   laydate.render({
                elem: '#createDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                format: 'yyyy-MM-dd',
                type : 'date'
            });*/


        });
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            $("#inputForm").attr("action","${ctx}/workieavetemplate/workIeaveTemplate/save");
            if(validateForm.form()){

                $("#inputForm").submit();
                return true;
            }else {
                parent.layer.msg("信息未填写完整!", {icon: 5});
            }
            return false;
        }

        function deleteRow(obj,index){
            $(obj).parent().parent().remove();
            str[index] = " ";
            mon[index] = 0;

        }
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            month = (month < 10)?"0"+month:month;
            strDate = (strDate < 10)?"0"+strDate:strDate;
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }

        function addRow(list, idx, tpl, row){
            var idx1 = $("#workMonthlyPlanThisList tr").length;
            bornTemplete(list, idx, tpl, row, idx1);
        }
        function bornTemplete(list, idx, tpl, row, idx1){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row,
                order:idx1 + 1
            }));
            $(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() == ""){
                delFlag.val("1");
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤销删除");
                $(obj).parent().parent().addClass("error");
                $(obj).parent().parent().addClass("hide");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }

        function selectUserInfo(data){
            console.info(data);
                        addRow('#workIeaveTemplateUserList', workIeaveTemplateUserListRowIdx, workIeaveTemplateUserListTpl);
                        workIeaveTemplateUserListRowIdx = workIeaveTemplateUserListRowIdx + 1;
                        var row = workIeaveTemplateUserListRowIdx - 1 ;
                        $("#"+"workIeaveTemplateUserList"+row+"_auditor").val(data.userId);
                        $("#"+"workIeaveTemplateUserList"+row+"_1").val(data.officeName);
                        $("#"+"workIeaveTemplateUserList"+row+"_2").val(data.name);
        }

        function openDialogreUser(title,url,width,height,target){

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

            }
            top.layer.open({
                type: 2,
                area: ['90%','90%'],
                title:title,
                skin:"two-btns",
                name:'friend',
                content: encodeURI("${ctx}/workieavetemplate/workIeaveTemplate/gridSelectUser?url=${ctx}/workieavetemplate/workIeaveTemplate/gridSelectUser&isAll=true&type=null&isSingle=true") ,
                btn: ['确定', '关闭'],
                yes: function(index, layero){
                    var iframeWin = layero.find('iframe')[0].contentWindow; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var item = iframeWin.getSelectedItem();
                    if(item == "-1"){
                        return;
                    }
                        selectUserInfo(item);
                    top.layer.close(index);//关闭对话框。

                },
                cancel: function(index){
                }
            });
        }
	</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">
		<form:form id="inputForm" modelAttribute="workIeaveTemplate" action="${ctx}/workieavetemplate/workIeaveTemplate/save" method="post" class="form-horizontal" >
			<form:hidden path="id"/>
			<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">公司名称：</label>
					<div class="layui-input-block with-icon">
                        <div class="input-group">
						<sys:treeselect id="branchOffice" name="branchOffice" value="${workIeaveTemplate.branchOffice}" labelName="branchOfficeName" labelValue="${workIeaveTemplate.branchOfficeName}"
										title="分公司" url="/workieavetemplate/workIeaveTemplate/treeDataCompany?type=2" cssClass="form-control required layui-input" allowClear="true" notAllowSelectParent="false"/>
					</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">
						<input id="createDate" name="createDate" readonly="true" type="text"  maxlength="20" class="laydate-icondate form-control layer-date  layui-input laydate-icon"
							   value="<fmt:formatDate value="${workIeaveTemplate.createDate}" 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 href="javascript:void(0)" onclick="openDialogreUser('选择用户', '${ctx}/workieavetemplate/workIeaveTemplate/gridSelectUser','80%','80%')" class="nav-btn nav-btn-add" ><i class="fa fa-plus"></i>&nbsp;选择</a>
				</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="200px">审核部门</th>
							<th width="200px">审核人</th>
							<th width="150px">审核项目</th>
							<th width="200px">操作</th>
						</tr>
						</thead>
						<tbody id="workIeaveTemplateUserList">
						<c:if test="${not empty workIeaveTemplate.workIeaveTemplateUserList}">
							<c:forEach items="${workIeaveTemplate.workIeaveTemplateUserList}" var="workIeaveTemplateUser" varStatus="index">
								<tr id="workIeaveTemplateUserList${index.index}">
									<td class="hide">
										<input id="workIeaveTemplateUserList${index.index}_id" name="workIeaveTemplateUserList[${index.index}].id" type="hidden" value="${workIeaveTemplateUser.id}"/>
										<input id="workIeaveTemplateUserList${index.index}_templateId" name="workIeaveTemplateUserList[${index.index}].templateId" type="hidden" value="${workIeaveTemplateUser.templateId}"/>
										<input id="workIeaveTemplateUserList${index.index}_auditor" name="workIeaveTemplateUserList[${index.index}].auditor" type="hidden" value="${workIeaveTemplateUser.auditor}"/>
										<input id="workIeaveTemplateUserList${index.index}_delFlag" name="workIeaveTemplateUserList[${index.index}].delFlag" type="hidden" value="0"/>
									</td>
									<td>
										<input id="workIeaveTemplateUserList${index.index}_1"  readonly="true"   type="text" value="${workIeaveTemplateUser.officeName}"   class="form-control "/>
									</td>
									<td>
										<input id="workIeaveTemplateUserList${index.index}_2"  readonly="true"   type="text" value="${workIeaveTemplateUser.userName}"   class="form-control "/>
									</td>
									<td>
										<input id="workIeaveTemplateUserList${index.index}_3" name="workIeaveTemplateUserList[${index.index}].comment"     type="text" value="${workIeaveTemplateUser.comment}"   class="form-control "/>
									</td>
									<td class="text-center op-td" >
										<span class="op-btn op-btn-delete" id="workIeaveTemplateUserList${index.index}_span" onclick="delRow(this, '#workIeaveTemplateUserList${index.index}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
					<script type="text/template" id="workIeaveTemplateUserListTpl">//<!--
                                    <tr id="workIeaveTemplateUserList{{idx}}">
                                        <td class="hide">
                                            <input id="workIeaveTemplateUserList{{idx}}_id" name="workIeaveTemplateUserList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
                                            <input id="workIeaveTemplateUserList{{idx}}_templateId" name="workIeaveTemplateUserList[{{idx}}].templateId" type="hidden" value="{{row.templateId}}"/>
                                            <input id="workIeaveTemplateUserList{{idx}}_auditor" name="workIeaveTemplateUserList[{{idx}}].auditor" type="hidden" value="{{row.workStaffBasicInfo.auditor}}"/>
                                            <input id="workIeaveTemplateUserList{{idx}}_delFlag" name="workIeaveTemplateUserList[{{idx}}].delFlag" type="hidden" value="0"/>
                                        </td>
                                        <td>
                                            <input id="workIeaveTemplateUserList{{idx}}_1"   name="workIeaveTemplateUserList[{{idx}}].officeName" type="text" value="{{row.officeName}}"  readonly="true"   class="form-control "/>
                                        </td>
                                        <td>
                                            <input id="workIeaveTemplateUserList{{idx}}_2"  name="workIeaveTemplateUserList[{{idx}}].userName" type="text" value="{{row.userName}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workIeaveTemplateUserList{{idx}}_3"  name="workIeaveTemplateUserList[{{idx}}].comment" type="text" value="{{row.comment}}"    class="form-control "/>
                                        </td>

                                        <td class="text-center op-td" >
                                            {{#delBtn}}<span class="op-btn op-btn-delete" id="workIeaveTemplateUserList{{idx}}_span" onclick="delRow(this, '#workIeaveTemplateUserList{{idx}}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>{{/delBtn}}
                                        </td>
                                    </tr>//-->
					</script>
					<script type="text/javascript">
                        var workIeaveTemplateUserListRowIdx = ${fn:length(workIeaveTemplate.workIeaveTemplateUserList)}, workIeaveTemplateUserListTpl = $("#workIeaveTemplateUserListTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                        if($("#id").val()){
                            workIeaveTemplateUserListIdx = ${fn:length(workIeaveTemplate.workIeaveTemplateUserList)};
                        }
                        $(document).ready(function() {
                        });
					</script>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>

	</div>
</div>
</body>
</html>