<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>

<div class="layui-form" style="margin-top: 15px; padding-right: 15px;">
<form class="layui-form" id="detail_form" method="post">
  <div class="layui-form-item">
    <label class="layui-form-label">公告标题</label>
    <div class="layui-input-block">
      <input type="text" name="title" lay-verify="required" placeholder="请输入" class="layui-input" value="<?php echo $notice->title; ?>">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">标题颜色</label>
    <div class="layui-input-block" id="colorbox">
    <?php foreach(Yii::$app->params["title_color"] as $onecolor){ ?>
      <a class="layui-btn" style="width: 70px; background-color: <?php echo $onecolor; ?>;" color="<?php echo $onecolor; ?>"><?php if($notice->color==$onecolor){echo '<i class="layui-icon">&#xe618;</i>';} ?></a>
    <?php } ?>
    <a class="layui-btn layui-btn-primary" style="width: 70px;">清除</a>
    </div>
    <input type="hidden" name="color" value="<?php echo $notice->color; ?>">
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">有效期</label>
    <div class="layui-input-inline">
      <input type="text" name="starttime" placeholder="请选择" class="layui-input" value="<?php echo $notice->starttime; ?>" readonly onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD hh:mm:ss'})">
    </div>
    <div class="layui-form-mid">至</div>
    <div class="layui-input-inline">
      <input type="text" name="stoptime" placeholder="请选择" class="layui-input" value="<?php echo $notice->stoptime; ?>" readonly onclick="layui.laydate({elem: this, istime: false, format: 'YYYY-MM-DD hh:mm:ss'})">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">公告内容</label>
    <div class="layui-input-block">
      <textarea name="content" id="editor" class="layui-textarea" style="border: none;"><?php echo $notice->content; ?></textarea>
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="button" class="layui-btn" id="finished_button">提交</button>
      <button type="button" class="layui-btn layui-btn-primary" onclick="javascript:window.history.back();">取消</button>
    </div>
  </div>

  <input type="hidden" name="noticeid" value="<?php echo $notice->id; ?>">

</form>
</div>

<script type="text/javascript">
var ue = UE.getEditor('editor',{
  initialFrameHeight: '450',
  scaleEnabled: true
});

//标题颜色
$("#colorbox").find("a").on("click", function(){
  var color = $(this).attr("color");
  $(this).siblings().html('');
  $(this).html('<i class="layui-icon">&#xe618;</i>');
  $("#colorbox").find("a:last").html('清除');
  $("#detail_form").find("input[name='color']").val(color);
});

//提交表单
$("#finished_button").on("click", function(){
  var title = $("#detail_form").find("input[name='title']");
  var starttime = $("#detail_form").find("input[name='starttime']");
  var stoptime = $("#detail_form").find("input[name='stoptime']");
  var hascontent = UE.getEditor('editor').hasContents();
  if($(title).val()==""){
    layer.msg("请填写标题", {icon:2});
    return false;
  }
  if($(starttime).val()=="" || $(stoptime).val()==""){
    layer.msg("请选择有效期", {icon:2});
    return false;
  }
  if(hascontent==false){
    layer.msg("请填写内容", {icon:2});
    return false;
  }
  $("#detail_form").attr("action", "/glnotice/basic/basicok.html");
  $("#detail_form").submit();
});
</script>