<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/H-ui.login.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/css/style.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/admin/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath }/common/other/kingedit/themes/default/default.css" rel="stylesheet" type="text/css" />
<title>添加商品</title>
</head>
<body>
<div class="pd-20">
	<form action="${pageContext.request.contextPath }/secure/message/insert" class="form form-horizontal" id="form-addGoods" method="POST" >
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>消息标题：</label>
			<div class="formControls col-5">
				<input id="title" name="title" type="text" class="input-text" value="" placeholder="" >
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>消息内容：</label>
			<div class="formControls col-10">
				<textarea id="content" name="content" class="textarea-text" placeholder="" style="width:600px;height:120px;"></textarea>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>消息url：</label>
			<div class="formControls col-5">
				<input id="url" type="text" name="url" id="" placeholder="格式:http://www.baidu.com" value="" class="input-text" ></div>
		</div>
		
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2"><span class="c-red">*</span>是否远程推送：</label>
			<div id="integralDiv" class="formControls col-2">
				<select id="is_needsend" name="is_needsend" class="select">
						<option  value="1">是</option>
						<option selected="selected" value="2">否</option>
				</select>
			</div>
		</div>
		
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2"><span class="c-red">*</span>是否内部打开：</label>
			<div id="integralDiv" class="formControls col-2">
				<span class="select-box">
				<select id="forword" name="forword" class="select">
						<option selected="selected" value="1">内部</option>
						<option value="2">外部</option>
				</select>
				</span>
			</div>
		</div>
		
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2"><span class="c-red">*</span>推送类型：</label>
			<div id="integralDiv" class="formControls col-2">
				<select id="send_type" name="send_type" class="select">
						<option selected="selected" value="1">文本</option>
						<option value="2">url</option>
						<option value="3">内部页面</option>
				</select>
			</div>
		</div>
		
		
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>目标用户：</label>
			<div class="formControls col-4">
			<input id="user"  name="user" 
				  type="hidden"   value="" class="input-text" style="width:50%">
				<input id="username"  name="username"  readonly="readonly" 
				  type="text"  placeholder="" value="" class="input-text" style="width:50%">
					 <span   onclick="  goods_edit('选择用户','${pageContext.request.contextPath }/secure/message/listuser','','400');"> 
					 	选择接受用户
					 </span>  
				</div>
		</div>
		
		<div class="row cl">
			<label id="integralLabel" class="form-label col-2"><span class="c-red">*</span>备注：</label>
			<div id="integralDiv" class="formControls col-2">
				<textarea id="remark" name="remark" class="textarea-text" placeholder="" style="width:600px;height:60px;"></textarea>
			</div>
		</div>
		
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<!-- <button onClick="return admin_addGoods();" class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button> -->
				<button onClick="return checkMessage();" class="btn btn-primary radius" type="submit">
					<i class="Hui-iconfont">&#xe632;</i>保存
				</button>
			</div>
		</div>
		<!-- 已售数量 -->
		<input type="hidden" name="productSalesnum" value="0">
		<!-- 浏览量 -->
		<input type="hidden" name="productAccessnum" value="0">
		
		</form>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/lib/layer/1.9.3/layer.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/H-ui.admin.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/tips.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/ueditor.all.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath }/common/admin/js/ueditor.config.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/other/kingedit/kindeditor.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/common/other/kingedit/lang/zh_CN.js"></script> 	
<script type="text/javascript" language="javascript">



/**
 * 打开界面
 */
function goods_edit(title,url,id,w,h){
	/*layer_show(title,url,w,h);*/
	var iWidth = 1000;
var iHeight = 700;
var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
 window.open(url, title, "width=" + iWidth + ", height=" + iHeight + ",top=" + iTop + ",left=" + iLeft + ",toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no,alwaysRaised=yes,depended=yes");
	 

}


//上传产品参数图
KindEditor.ready(function(K) {
	var editor = K.editor({
    	fileManagerJson : '${pageContext.request.contextPath }/common/other/kingedit/jsp/file_manager_json.jsp',
        uploadJson : '${pageContext.request.contextPath }/common/other/kingedit/jsp/upload_json.jsp',
		allowFileManager : true
	});
	K('#insertfileParameter').click(function() {
	     var imgid = $(this).attr("id");//获取当前ID
		editor.loadPlugin('image', function() {
			editor.plugin.imageDialog({
				showRemote : false,
				imageUrl : K('#productParameterImg').val(),
				clickFn : function(url, title, width, height, border, align) {
					K('#parameterImg').attr("src",url);
					K('#productParameterImg').val(url);
					editor.hideDialog();
					return false; 
				}
			});
		});
	}); 
	
});

//上传介绍图
KindEditor.ready(function(K) {
	var editor = K.editor({
    	fileManagerJson : '${pageContext.request.contextPath }/common/other/kingedit/jsp/file_manager_json.jsp',
        uploadJson : '${pageContext.request.contextPath }/common/other/kingedit/jsp/upload_json.jsp',
		allowFileManager : true
	});
	K('#insertfileIntroduce').click(function() {
	     var imgid = $(this).attr("id");//获取当前ID
		editor.loadPlugin('image', function() {
			editor.plugin.imageDialog({
				showRemote : false,
				imageUrl : K('#productIntroduceImg').val(),
				clickFn : function(url, title, width, height, border, align) {
					K('#introduceImg').attr("src",url);
					K('#productIntroduceImg').val(url);
					editor.hideDialog();
					return false; 
				}
			});
		});
	}); 
	
});


$(document).ready(function(){
	//showHidden();
	addBtnEvent(1);
	var spotMax = 10;
	var ids = document.getElementsByName('productIntroduceImg').length;
	if(ids >= spotMax) {
		("#addimages").hide();
	}
	$("input#addimages").click(function(){     
		  addSpot(this, spotMax);
	});
});
function addSpot(obj, sm) {
	var goodsimagess = document.getElementsByName('productIntroduceImg').length;
	var ids = "imageFile"+(goodsimagess+1);
	var urls = "url"+(goodsimagess+1);
	var imagesClass = "urlClass"+(goodsimagess+1);
	var introduceImgs = "introduceImg"+(goodsimagess+1);
	
	$('div#spots').before(
		'<div class="row cl">'+
		'<label class="form-label col-2"></label>'+
		'<img alt="介绍图" src="" id="'+introduceImgs+'" width="90" height="80">'+
	    '<input name="productIntroduceImg" class='+imagesClass+' type="hidden" id='+urls+'/>'+
	    '&nbsp;<i class="Hui-iconfont">&#xe642;</i>&nbsp;'+
	    '<input type="button" class="addImagesClass btn btn-primary radius upload-btn" id='+ids+' value="选择图片" />' +
	    '&nbsp;<input type="button" class="remove btn btn-primary radius upload-btn" onclick="removes(this)" value="删除" /></div>')
	if((goodsimagess-1) >= sm) {
		$("#productIntroduceImg").hide();
	}
	//给新增的按钮绑定事件
	addBtnEvent((goodsimagess+1));
};
//删除新增的上传组件
function removes(obj){
	$(obj).parent().remove();
    $("#productIntroduceImg").show();
    preview();
}
//
function addBtnEvent(goodsimagess){
	KindEditor.ready(function(K) {
		var editor = K.editor({
        	fileManagerJson : '${pageContext.request.contextPath }/common/other/kingedit/jsp/file_manager_json.jsp',
            uploadJson : '${pageContext.request.contextPath }/common/other/kingedit/jsp/upload_json.jsp',
			allowFileManager : true
		});
		K('#imageFile'+goodsimagess).click(function() {
			var imgid = $(this).attr("id");//获取当前ID
			var imagesClass =  "urlClass"+imgid.substr(imgid.length-1,1);
			var introduceImg = "introduceImg"+imgid.substr(imgid.length-1,1);
		     
			editor.loadPlugin('image', function() {
				editor.plugin.imageDialog({
					showRemote : false,
					imageUrl : K('.'+imagesClass).val(),
					clickFn : function(url, title, width, height, border, align) {
						K('#'+introduceImg).attr("src",url);
						K('.'+imagesClass).val(url);
						editor.hideDialog();
						return false; 
					}
				});
			});
		}); 
		
	});
}
		

	function checkMessage(){
			//消息标题
			if(!commonLengthJdg('title',1,60,null,true)){
				layer.msg("消息标题不能为空!且长度为1-30位",{icon: 2,time:2000});
				return false;
			}
			//消息内容
			if(!commonLengthJdg('content',1,200,null,true)){
				layer.msg("消息内容不能为空!",{icon: 2,time:2000});
				return false;
			}
			//是否在内部打开
			if(!commonLengthJdg('forword',digital,null,true)){
				layer.msg("是否在内部打开不能为空",{icon: 2,time:2000});
				return false;
			}
			//是否需要远程推送
			if(!commonTypeJdg('is_needsend',digital,null,true)){
				layer.msg("是否需要远程推送不能为空",{icon: 2,time:2000});
				return false;
			}
			//推送的类型
			if(!commonLengthJdg('send_type',digital,null,true)){
				layer.msg("推送的类型不能为空",{icon: 2,time:2000});
				return false;
			}
			//目标用户
			if(!commonLengthJdg('username',digital,null,true)){
				layer.msg("目标用户不能为空",{icon: 2,time:2000});
				return false;
			}
			
			return true;
	}

</script>
</body>
</html>