<%@ 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() {
			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);
					}
				}
			});
            getCurrentDocumentHei()
		});
        function addRow(list, idx, tpl, row){
            var idx2 = $("#workCommunicateRecords tr").length;
            if(list == '#workCommunicateRecords'){
                bornTemplete(list, idx, tpl, row, idx2);
            }
        }
        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");
//                    }
//                }
//            });
            getCurrentDocumentHei()
        }
        function delRow(obj, prefix,othis){
            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).parent().parent().removeClass("error");
            }
            getCurrentDocumentHei(othis)
        }
        function getCurrentDocumentHei(obj){
            var height = $(document).outerHeight();
            if(height < 410){
                height = height + 350;
            }
            var hei = 0;
            if(obj){
                hei = $(obj).find("tr").eq(0).height() || 0;
            }
            parent.$("#controltype").attr("height",(height - hei) +"px")
        }
	</script>
</head>
<body class="hideScroll">
		<form:form id="inputForm" modelAttribute="workCommunicateRecord" action="${ctx}/workcommunicaterecord/workCommunicateRecord/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<input type="hidden" name="projectId" id="projectId">
		<a class="btn btn-white btn-sm addBtn" onclick="addRow('#workCommunicateRecords', workCommunicateRecordsRowIdx, workCommunicateRecordsTpl);workCommunicateRecordsRowIdx = workCommunicateRecordsRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
		<table id="contentTable2" class="table table-striped table-bordered table-condensed">
			<thead>
			<tr>
				<th><font color="red">*</font>序号</th>
				<th><font color="red">*</font>日期</th>
				<th><font color="red">*</font>沟通内容</th>
				<th><font color="red">*</font>沟通方式</th>
				<th><font color="red">*</font>反馈意见</th>
				<th>备注</th>
				<th width="150px">操作</th>
			</tr>
			</thead>
			<tbody id="workCommunicateRecords">
			<c:if test="${not empty workCommunicateRecord.workCommunicateContentList}">
				<c:forEach items="${workCommunicateRecord.workCommunicateContentList}" var="workCommunicateRecord" varStatus="index">
					<tr id="workCommunicateContentList${index.index}">
						<td class="hide">
							<input id="workCommunicateContentList${index.index}_id" name="workCommunicateContentList[${index.index}].id" type="hidden" value="${workCommunicateRecord.id}"/>
							<input id="workCommunicateContentList${index.index}_delFlag" name="workCommunicateContentList[${index.index}].delFlag" type="hidden" value="0"/>
						</td>
						<td>
							<input id="workCommunicateContentList${index.index}_contentNumber"  name="workCommunicateContentList[${index.index}].contentNumber" type="text" value="${workCommunicateRecord.contentNumber}"    class="form-control required"/>
						</td>

						<td>
							<input id="workCommunicateContentList${index.index}_contentDate" name="workCommunicateContentList[${index.index}].contentDate" onclick="laydate({istime: false,format: 'YYYY-MM-DD'})" value="<fmt:formatDate value="${workCommunicateRecord.contentDate}" pattern="yyyy-MM-dd"/>"    class="laydate-icon form-control layer-date required"/>
						</td>
						<td>
							<input id="workCommunicateContentList${index.index}_contentDetail" name="workCommunicateContentList[${index.index}].contentDetail" type="text" value="${workCommunicateRecord.contentDetail}"    class="form-control required"/>
						</td>
						<td>
							<input id="workCommunicateContentList${index.index}_contentWay" name="workCommunicateContentList[${index.index}].contentWay" type="text" value="${workCommunicateRecord.contentWay}"    class="form-control required"/>
						</td>
						<td>
							<input id="workCommunicateContentList${index.index}_contentFeedback" name="workCommunicateContentList[${index.index}].contentFeedback" type="text" value="${workCommunicateRecord.contentFeedback}"    class="form-control required"/>
						</td>
						<td>
							<input id="workCommunicateContentList${index.index}_remarks" name="workCommunicateContentList[${index.index}].remarks" type="text" value="${workCommunicateRecord.remarks}"    class="form-control"/>
						</td>
						<td class="text-center" style="width:80px;">
							<button class="btn btn-danger btn-xs" onclick="delRow(this, '#workCommunicateContentList${index.index}','#workCommunicateRecords')" title="删除"><i class="fa fa-trash"></i> 删除</button>
						</td>
					</tr>
				</c:forEach>
			</c:if>
			</tbody>
		</table>
		<script type="text/template" id="workCommunicateRecordsTpl">//<!--
		<tr id="workCommunicateContentList{{idx}}">
			<td class="hide">
				<input id="workCommunicateContentList{{idx}}_id" name="workCommunicateContentList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
				<input id="workCommunicateContentList{{idx}}_delFlag" name="workCommunicateContentList[{{idx}}].delFlag" type="hidden" value="0"/>
			</td>
			<td>
				<input id="workCommunicateContentList{{idx}}_contentNumber"  name="workCommunicateContentList[{{idx}}].contentNumber" type="text" value="{{row.contentNumber}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workCommunicateContentList{{idx}}_contentDate"  name="workCommunicateContentList[{{idx}}].contentDate" onclick="laydate({istime: false,format: 'YYYY-MM-DD'})" value="{{row.contentDate}}"    class="laydate-icon form-control layer-date required"/>
			</td>
			<td>
				<input id="workCommunicateContentList{{idx}}_contentDetail" name="workCommunicateContentList[{{idx}}].contentDetail" type="text" value="{{row.contentDetail}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workCommunicateContentList{{idx}}_contentWay" name="workCommunicateContentList[{{idx}}].contentWay" type="text" value="{{row.contentWay}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workCommunicateContentList{{idx}}_contentFeedback" name="workCommunicateContentList[{{idx}}].contentFeedback" type="text" value="{{row.contentFeedback}}"    class="form-control required"/>
			</td>
			<td>
				<input id="workCommunicateContentList{{idx}}_remarks" name="workCommunicateContentList[{{idx}}].remarks" type="text" value="{{row.remarks}}"    class="form-control"/>
			</td>

			<td class="text-center" style="width:80px;">
				{{#delBtn}}<button class="btn btn-danger btn-xs" onclick="delRow(this, '#workCommunicateContentList{{idx}}','#workCommunicateRecords')" title="删除"><i class="fa fa-trash"></i> 删除</button>{{/delBtn}}
			</td>
		</tr>//-->
		</script>
		<script type="text/javascript">
			var workCommunicateRecordsRowIdx = 0, workCommunicateRecordsTpl = $("#workCommunicateRecordsTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
			if($("#id").val()){
                workCommunicateRecordsRowIdx = ${fn:length(workCommunicateRecord.workCommunicateContentList)};
			}
		</script>

		<table class="table table-bordered  table-condensed dataTables-example dataTable no-footer">
		   <tbody>
				<tr>
					<td class="width-15 active"><label class="pull-right"><font color="red">*</font>沟通记录人员：</label></td>
					<td class="width-35">
						<sys:treeselect id="comUser" name="comUser.id" value="${workCommunicateRecord.comUser.id}" labelName="comUser.name" labelValue="${workCommunicateRecord.comUser.name}"
							title="用户" url="/sys/office/treeData?type=3" cssClass="form-control required" allowClear="true" notAllowSelectParent="true"/>
					</td>
				</tr>
		 	</tbody>
		</table>
	</form:form>
</body>
</html>