<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
  <meta name="decorator" content="base"/>
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
  <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.css" media="all">
  <style>
    html {
      background-color: #fff;
      padding-bottom: 50px;
    }
  </style>
</head>

<body>
<div class="layui-form">
  <div class="layui-card">
    <input type="hidden" id="parentId" name="parentId" class="layui-input" value="${parentId}">
    <input type="hidden" id="capitalId" name="capitalId" class="layui-input" value="${capitalId}">
    <input type="hidden" id="id" name="id" value="${capitalDict.id}">
    <div class="layui-col-xs12 mb-10 pr-30">
      <div class="layui-inline layui-col-xs6">
        <label class="layui-form-label w-130"><i class="red">*</i>资方名称：</label>
        <div class="layui-input-block ">
          <select name="capitalId" lay-verify="required" lay-filter="materialTypeId" disabled>
            <option value="-1">通用</option>
            <c:forEach items="${paterns}" var="data">
              <option value="${data.columns.id}" <c:if test="${capitalDict.capitalId eq data.columns.id}"> selected</c:if>  data-value="${data.columns.name}" >${data.columns.name}</option>
            </c:forEach>
          </select>
        </div>
      </div>
      <div class="layui-inline layui-col-xs6">
        <label class="layui-form-label w-130"><i class="red">*</i>字典码：</label>
        <div class="layui-input-block  w-200">
          <input type="text" id="code" name="code" lay-verify="required" autocomplete="off" placeholder="请输入"
                 class="layui-input" value="${capitalDict.code}">
        </div>
      </div>
    </div>
    <div class="layui-col-xs12 mb-10 pr-30">
      <div class="layui-inline layui-col-xs6">
        <label class="layui-form-label w-130"><i class="red">*</i>字典值：</label>
        <div class="layui-input-block  w-200">
          <input type="text" name="dictKey" id="dictKey" lay-verify="required" autocomplete="off" placeholder="请输入"
                 class="layui-input" value="${capitalDict.dictKey}">
        </div>
      </div>

      <div class="layui-inline layui-col-xs6">
        <label class="layui-form-label w-130"><i class="red">*</i>字典类型：</label>
        <div class="layui-input-block  w-200">
          <input type="text" name="dictValue" id="dictValue" lay-verify="required" autocomplete="off" placeholder="请输入"
                 class="layui-input" value="${capitalDict.dictValue}">
        </div>
      </div>

    </div>
    <div class="layui-col-xs12 mb-10 pr-30">
      <div class="layui-inline layui-col-xs6">
        <label class="layui-form-label w-130"><i class="red">*</i>排序：</label>
        <div class="layui-input-block  w-200">
          <input type="text" id="sort" name="sort" lay-verify="required" autocomplete="off" placeholder="请输入"
                 class="layui-input" value="${capitalDict.sort}">
        </div>
      </div>
      <div class="layui-inline layui-col-xs6">
        <label class="layui-form-label w-130"><i class="red">*</i>备注：</label>
        <div class="layui-input-block w-200">
          <input id="remark" type="text" id="remark" name="sort" lay-verify="required" autocomplete="off" placeholder="请输入"
                 class="layui-input" value="${capitalDict.remark}">
        </div>
      </div>
    </div>
  </div>
  <div class="operate-footer">
    <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="确认">
    <input type="button" value="取消" class="layui-btn layui-btn-primary " onclick="closeDiv();">
  </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript">
  //初始数据
  var $form;
  var form;
  var $;
  var imgs = '';
  var myreg = /^[0-9]*$/;
  var reg = /\./;
  layui.config({
    base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['form', 'layedit', 'laydate', 'jquery', 'layer'], function () {
    $ = layui.jquery;
    form = layui.form;
    $form = $('form');

    var saveFlag = false;
    form.on('submit(confirm)', function (data) {
      if(saveFlag){
        return false;
      }
      var id = $("#id").val();
      data.field.id = id;

      var capitalId = $("#capitalId").val();
      data.field.capitalId = capitalId;

      var code = $("#code").val();
      data.field.code = code;

      var dictKey = $("#dictKey").val();
      data.field.dictKey = dictKey;

      var dictValue = $("#dictValue").val();
      data.field.dictValue = dictValue;

      var sort = $("#sort").val();
      data.field.sort = sort;

      var remark = $("#remark").val();
      data.field.remark = remark;


      saveFlag=true;
      var index= layer.load(2, {shade: [0.5,'#fff'], content:''});
      console.log(data)
      $.ajax({
        url: '${ctx}/capitalDict/saveOreditCapitalDict',
        method: 'post',
        data: data.field,
        dataType: 'JSON',
        success: function (res) {
          if (res.code == "200") {
            parent.layer.msg("保存成功", {time: 1000});
            closeDiv();
            parent.table.reload('test');
          }else {
            layer.msg(res.msg, {icon: 2},{time: 1000});
            saveFlag = false;
          }
        },complete: function () {
          layer.close(index);
        },
        error: function (data) {
          layer.msg("请刷新！", {icon: 2});
          return;
        }
      });
    });


  })

  function closeDiv() {
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
  }

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


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