<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>群组管理</title>
	<meta name="decorator" content="default"/>
	<%--<style type="text/css">--%>
		<%--img {width:50px; height:50px;}--%>
	<%--</style>--%>
	<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);
					}
				}
			});
			
		});
        //上传图片
        function this_upload_image_button(index){
            // var length = $("#this_upload_image_div :file").length;
            // var this_item_id = 'this_upload_image_'+index;
            // var last_item_id = $('img[id^=this_upload_image_]:last').attr('id');
            // if(length==6 && this_item_id==last_item_id){
            //     top.layer.alert('最多上传5张图片',{icon:0,title:'系统提示'});
            //     return;
            // }
            $("#this_upload_file_"+index).click();
        }
        function this_upload_show_image(index){
            var obj =$("#this_upload_file_"+index)[0].files[0];
            var fileType = obj.type;
            var url ;
            if(fileType.endsWith("png")||fileType.endsWith("bmp")||fileType.endsWith("jpg")||fileType.endsWith("jpeg")){
                url = window.URL.createObjectURL(obj);
            }else {
                //需要置空
                // var file = $("#this_upload_file_"+index);
                // file.after(file.clone().val(""));
                // file.remove();
                // top.layer.alert('请上传*.png,*.bmp,*.jpg/jpeg格式的图片',{icon:0,title:'系统提示'});
                // return false ;
                $("#this_upload_msg").css({"color":"red"});
                this_close_img(index);
                return false ;
            }
            // $("#this_upload_image_"+index).attr("src",url);
            // var length = $("#this_upload_image_div :file").length;
            // var this_item_id = 'this_upload_image_'+index;
            // var last_item_id = $('img[id^=this_upload_image_]:last').attr('id');
            // if( this_item_id==last_item_id &&  length < 6 ){
            //     this_upload_image_append(index);
            //     this_add_x(index);
            // }
            $("#this_upload_msg").removeAttr("style");
            $("#this_upload_image_"+index).attr("src",url);
            var length = $("#this_upload_image_div :file").length;
            if( index == length &&  length < 1 ){
                this_upload_image_append(index);
                this_add_x(index);
            }else if(index == length && length ==1){
                var span = '<span id="this_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;height:20px;line-height:20px;font-size:20px;z-index:1;color: red;" onclick="this_close_img('+index+');">x</span>';
                $("#this_upload_image_1").before(span);
            }
        }
        function this_upload_image_append(index){
            var div1 = "<div id='this_upload_div_"+(index+1)+"'>";
            var img = '<img  id="this_upload_image_'+(index+1)+'" class="upload_ico" onclick="this_upload_image_button('+(index+1)+')" src = "${pageContext.request.contextPath}/static/uploadify/upload_ico.png" style="cursor:pointer;"/>';
            var input = '<input id="this_upload_file_'+(index+1)+'" type="file" style="display:none;" name="this_upload_files" onChange="this_upload_show_image('+(index+1)+')" /><br>';
            var div2 = "</div>";

            $("#this_upload_image_div").append(div1+img+input+div2);
        }
        function this_close_img(index) {
            $("#this_upload_div_"+index).remove();
            var length = $("#this_upload_image_div :file").length;
            if(length == 0){
                this_add_div();
            }else if(length == 1){
                var x = $("#this_upload_image_div").find("span").text();
                if("x" != x){
                    this_add_div();
                }
            }
        }
        function this_add_x(index) {
            // var span = '<span id="this_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;z-index:1;color: red;" onclick="this_close_img('+index+');">x</span>';
            // $("#this_upload_image_div").find("img:eq(-2)").before(span);
            var span = '<span id="this_upload_close_'+index+'" class="close_ico" style="cursor:pointer; position: absolute;top:-1px;right: -1px; display:inline-block;height:20px;line-height:20px;font-size:20px;z-index:1;color: red;" onclick="this_close_img('+index+');">x</span>';
            $("#this_upload_image_div").find("img:eq(-2)").before(span);
        }
        function this_add_div() {
            <%--var this_upload_div_1 =--%>
                <%--'<div id="this_upload_div_1" style="float: left;position:relative;width: 57px;height: 57px;" >'+--%>
                <%--'<img  id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/uploadify/upload_ico.png"  onclick="this_upload_image_button(1)"/>'+--%>
                <%--'<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)" /><br>'+--%>
                <%--'</div>';--%>
            <%--$("#this_upload_image_div").html("").append(this_upload_div_1);--%>
            var this_upload_div_1 =
                '<div id="this_upload_div_1" style="position:relative;">'+
                '<img  id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png"  onclick="this_upload_image_button(1)"/>'+
                '<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)" /><br>'+
                '</div>';
            $("#this_upload_image_div").html("").append(this_upload_div_1);
        }

        <%--//删除附件--%>
        <%--function delFile(id,attaId,attachmentUrl,obj) {--%>
            <%--var loadingMessage = parent.layer.load(0, {shade: [0.1,'#393d49']});--%>
            <%--var tr = $(obj).parent().parent();--%>
            <%--$.ajax({--%>
                <%--type:'POST',--%>
                <%--dataType:'json',--%>
                <%--url:'${ctx}/work/report/workReport/delFile',--%>
                <%--data:{"id":id,"attaId":attaId,"attachmentUrl":attachmentUrl},--%>
                <%--cache:false,--%>
                <%--success: function() {--%>
                    <%--//先修改序号，再删除--%>
                    <%--$(tr).nextAll().each(function (i,n) {--%>
                        <%--var num = $(n).find("td:first").text().trim();--%>
                        <%--$(n).find("td:first").text(parseInt(num)-1);--%>
                    <%--});--%>
                    <%--tr.remove();--%>
                    <%--parent.layer.msg("删除成功！！！",{icon:6});--%>
                    <%--parent.layer.close(loadingMessage);--%>
                <%--},--%>
                <%--error:function () {--%>
                    <%--parent.layer.msg("删除失败！！！",{icon:3});--%>
                    <%--parent.layer.close(loadingMessage);--%>
                <%--}--%>
            <%--});--%>
        <%--}--%>
		<%--function addRow(list, idx, tpl, row){--%>
			<%--$(list).append(Mustache.render(tpl, {--%>
				<%--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).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");--%>
			<%--}--%>
		<%--}--%>
	</script>
	<style>
		.form-top{
			padding-top: 40px;
			margin-left: 15px;
			margin-right: 15px;
		}
	</style>
</head>
<body>
	<form:form id="inputForm" modelAttribute="layGroup" enctype="multipart/form-data" action="${ctx}/iim/layGroup/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<div class="container1">
			<div class="form-top">
				<div class="layui-item layui-col-sm12">
					<label class="layui-form-label">群组名：</label>
					<div class="layui-input-block">
						<form:input path="groupname" htmlEscape="false" maxlength="64" class="form-control layui-input"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm12" style="height:180px;">
					<label class="layui-form-label">群头像：</label>
					<div class="layui-input-block">
						<div class="pic_box_wrapper">
							<div class="pic_box">
								<div id="this_upload_image_div">
									<div id="this_upload_div_1" style="position:relative;">
										<img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png"  onclick="this_upload_image_button(1)"/>
										<input id="this_upload_file_1" type="file" style="display:none"  name="this_upload_files"  onchange="this_upload_show_image(1)"  class="form-control required"/>
									</div>
								</div>
							</div>
						</div>
						<span id="this_upload_msg">请上传*.png,*.bmp,*.jpg/jpeg格式的图片</span>
					</div>
				</div>
				<div class="layui-item layui-col-sm12 with-textarea">
					<label class="layui-form-label">备注信息：</label>
					<div class="layui-input-block">
						<form:textarea path="remarks" htmlEscape="false" rows="4" style="resize:none;" maxlength="255" class="form-control "/>
					</div>
				</div>

			</div>
		</div>
	</form:form>
</body>
</html>