<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
  <meta name="decorator" content="base" />
  <meta charset="utf-8">
  <title>新增</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <style>
    .addForm .mark {
      color: #ff5151;
    }
    .edui-default .edui-editor {
      width: 100% !important;
    }
  </style>
</head>
<body>

<div class="layui-card mb-10" style="padding: 10px;">
  <div class="layui-form addForm layui-card-body over" lay-filter="add-form" id="addForm">
    <div class="layui-row">
      <div class="layui-form-item layui-col-sm11">
        <label class="layui-form-label"><span class="mark">*</span>公告名称：</label>
        <div class="layui-input-block">
          <input hidden value="${type}" name="objType" id="objType">
          <input type="text" id="title" name="title" lay-verify="required" class="layui-input" maxlength="30">
        </div>
      </div>
    </div>
    <div class="layui-form-item layui-col-sm11" style="margin-bottom: 15px;">
      <label class="layui-form-label"><span class="mark">*</span>通知内容：</label>
      <div class="layui-input-block" style="margin-bottom: 30px;">
        <textarea placeholder="请输入内容" class="layui-textarea" id="html" name="html" lay-verify="required" ></textarea>
      </div>
    </div>

    <div class="layui-form-item " style="text-align: center;">
      <input type="button" class="layui-btn submitBut" lay-submit lay-filter="component-form-element" value="确认" >
    </div>
  </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    var $;



    layui.use(['form'], function(){
        var form = layui.form;
        $ = layui.$;


        form.verify({
            htmlRule: function(val) {
                if (!ue.hasContents()) {
                    return "通知内容不能为空";
                }
            },
        });


      var valid = false;
      form.on('submit(component-form-element)', function(data){
        if(valid){
          return
        }
       $(".submitBut").attr("disabled",true);
        valid = true;
        var postData = data.field;
        $.ajax({
          url: '${ctx}/notification/create',
          data: postData,
          type: 'post',
          async: false,
          success: function(result){
              console.log(result)
            if (result.code === "200") {
              parent.layer.msg("保存成功！", {icon: 1});
              parent.layer.closeAll();
              parent.table.reload('dataList');
            } else if (result.code === '402') {
              layer.msg("请选择通知群体！", {icon: 2});
            } else {
              layer.msg("保存失败！", {icon: 2});
            }
          },
          complete: function () {
            valid = false;
            $(".submitBut").attr("disabled",false);
          }
        });

      });


    });

    function isBlank(val) {
      if (val == null || $.trim(val) == '' || val == undefined) {
        return true;
      }
      return false;
    }

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