<!--{include file="<!--{$oapath}-->public/ins_page.tpl"}-->
     <link rel='stylesheet' type='text/css' href="<!--{$oapath}-->Ins/js/layui/css/layui.css">
 <script type='text/javascript' src='<!--{$urlpath}-->data/oaeditor/kindeditor.js'></script><block name="content">
	<div class="popup-box">
		
		<form class="well form-horizontal" method='post' id="form_data" name="form_data" enctype="multipart/form-data">
			<input type="hidden" id="ajax" name="ajax" value="1">
			<input type="hidden" id="to" name="to"/>
			<input type="hidden" id="opmode" name="opmode" value="add"/>
			<input type="text" style="display:none">

			<div class="form-group">
				<label class="col-sm-2 control-label" for="recever">收信人*：</label>
				<div class="col-sm-10">
					<div id="recever" class="inputbox">
						<a class="pull-right btn btn-link text-center" onclick="popup_contact();"> <i class="fa fa-user"></i> </a>
						<div class="wrap" >
							<span class="address_list"></span>
							<span class="text" >
								<input class="letter" type="text"  >
							</span>
						</div>
						<div class="search dropdown ">
							<ul class="dropdown-menu"></ul>
						</div>
					</div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-xs-12">
					<textarea  class="editor" id="content" msg="请输入内容" name="content" style="width:100%;height:300px;"></textarea>
                                                                                          <script>var editor;KindEditor.ready(function(K) {editor = K.create('#content',{afterCreate : function() {
    this.sync();
},
afterBlur:function(){
    this.sync();
} }); });</script>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label" for="name">附件：</label>
				<div class="col-sm-10">
					<div class="uploader" id="uploader_add_file" add_file_id="add_file">
                                    <a class="btn btn-sm btn-primary" id="testList">添加附件</a>
                                    
                                    <ul class="file_list" new_upload="" id="file_list"></ul>
                            </div>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-10 col-sm-offset-2">
					<a onclick="save();"  class="btn btn-sm btn-primary">发送</a>
					<a onclick="go_return_url();" class="btn btn-sm btn-default">取消</a>
				</div>
			</div>
		</form>
	</div>
</block>

                                		</div>
		<!-- Mainly scripts -->
		<script src="<!--{$oapath}-->Ins/js/jquery-2.1.1.js"></script>
		<script src="<!--{$oapath}-->Ins/js/bootstrap.min.js"></script>
		<script src="<!--{$oapath}-->Ins/js/plugins/metisMenu/jquery.metisMenu.js"></script>
		<script src="<!--{$oapath}-->Ins/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
		<!-- Custom and plugin javascript -->
		<script src="<!--{$oapath}-->Ins/js/inspinia.js"></script>
		<script src="<!--{$oapath}-->Ins/js/common.js"></script>
		<script src="<!--{$oapath}-->Ins/js/plugins/pace/pace.min.js"></script>
                
		<script src="<!--{$oapath}-->Ins/js/plugins/toastr/toastr.min.js"></script>
                <script src="<!--{$oapath}-->Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
                <script src="<!--{$oapath}-->Ins/js/plugins/bootbox/bootbox.min.js"></script>
		
        <script src="<!--{$oapath}-->Ins/js/plugins/jquery-ui/jquery-ui.min.js"></script>
	<script src="<!--{$oapath}-->Ins/js/plugins/nouslider/jquery.nouislider.min.js"></script>
        <script src="<!--{$oapath}-->Ins/js/plugins/date-time/moment-with-locales.js"></script>
	<script src="<!--{$oapath}-->Ins/js/plugins/date-time/bootstrap-datetimepicker.js"></script>

       <script type="text/javascript" src="<!--{$oapath}-->Ins/js/layui/layui.js"></script>

<block name="js">

<block name="js">
	<script type="text/javascript">
		$(document).ready(function() {

			/*单击删除已选联系人*/
			$(document).on("click", ".inputbox .address_list a.del", function() {
				$(this).parent().parent().remove();
			});

			/* 查找联系人input 功能*/
			$(document).on("click", ".inputbox .search li", function() {
				name = $(this).text().replace(/<.*>/, '');
				data = $(this).find("a").attr("data");
				html = conv_inputbox_item(name, data);

				inputbox = $(this).parents(".inputbox");
				inputbox.find("span.address_list").append(html);
				inputbox.find("input.letter").val("");
				inputbox.find(".search ul").html("");
				inputbox.find(".search ul").hide();
				inputbox.find(".search").hide();
			});
			/* 查找联系人input 功能*/
			$(".inputbox .letter").keyup(function(e) {
				switch(e.keyCode) {
				case 40:
					var $curr = $(this).parents(".inputbox").find(".search li.active").next();
					if ($curr.html() != null) {
						$(this).parents(".inputbox").find(".search li").removeClass("active");
						$curr.addClass("active");
					}
					break;

				case 38:
					var $curr = $(this).parents(".inputbox").find(".search li.active").prev();
					if ($curr.html() != null) {
						$(this).parents(".inputbox").find(".search li").removeClass("active");
						$curr.addClass("active");
					}
					break;

				case 13:
					if ($(this).parents(".inputbox").find(".search ul").html() != "") {
						name = $(".search li.active").text().replace(/<.*>/, '');
						data = $(".search li.active a").attr("data");
						html = conv_inputbox_item(name, data);
						$(this).parents(".inputbox").find("span.address_list").append(html);
						$(this).parents(".inputbox").find(".search ul").html("");

						$(this).val("");
						$(this).parents(".inputbox").find(".search ul").hide();
					} else {
						email = $(this).val();
						if (validate(email, 'email')) {
							name = email;
							html = conv_inputbox_item(name, email);
							$(this).parents(".inputbox").find("span.address_list").append(html);
							$(this).val("");
						} else {
							ui_error("邮件格式错误");
							return false;
						}
					}
					break;

				default:
					var search = $(this).parents(".inputbox").find("div.search ul");
					if ($(this).val().length > 1) {
						$.getJSON("oa.php?c=popup&a=json", {
							key : $(this).val()
						}, function(json) {
							if (json != "") {
								if (json.length > 0) {
									search.html("");
									$.each(json, function(i) {
										search.append('<li><a data="' + json[i].id + '" title="' + json[i].email + '">' + json[i].name + '&lt;' + json[i].email + '&gt;</a></li>');
									});
									search.children("li:first").addClass("active");
									search.show();
								}
							} else {
								search.html("");
								search.hide();
							}
						});
					} else {
						search.hide();
					}
				}
			});
		});
		function save() {
			$("#to").val("");
			$("#recever .address_list span").each(function() {
				$("#to").val($("#to").val() + $(this).find("b").text() + '|' + $(this).attr("data") + ";");
			});
			if ($("#to").val() == "") {
				ui_error("请选择收信人");
				$("#recever .letter").focus();
				return false;
			}
			sendForm("form_data", "oa.php?c=Message&a=save", "oa.php?c=Message");
		}

		function popup_contact() {
			winopen("oa.php?c=popup&a=message", 560, 470);
		}
                    $(document).on("click", "#del_li", function() {
                                                $(this).parent().parent().parent().remove();		
                                });
	</script>

</block>
          <script>
layui.use('upload', function(){
  var $ = layui.jquery
  ,upload = layui.upload;
  
  //普通图片上传
  var uploadInst = upload.render({
    elem: '#testList'
    ,url: 'oa.php?c=Popup&a=upload'
    ,accept: 'file'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo1').attr('src', result); //图片链接（base64）
      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }else{
          var html="<li class='tbody'><input type='hidden' name='upload_file[]' value='"+res.name1+"'/><div class='loading' style='width: 100%;'></div><div class='data'><span class='del text-center'><a class='link del' id='del_li' style='display: inline;'>删除</a></span>";
          html+="<span class='size text-right'>"+res.size+"</span>";
          html+="<span class='auto autocut'>"+res.name2+"</span></div></li>";
          var demoText = $('#file_list');
          demoText.append(html);
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });
  

  
  //绑定原始文件域
  upload.render({
    elem: '#test20'
    ,url: '/upload/'
    ,done: function(res){
      console.log(res)
    }
  });
  
});
</script>
</block>
	</body>
</html>