<div style="text-align: center;margin: 10px 10px 10px 10px;">


  <form id="form1" class="layui-form  layui-form-pane" action="/u/SaveForward" method="POST">
    <div class="layui-form-item">
      <label class="layui-form-label">名称</label>
      <div class="layui-input-inline">
        <input type="text" name="name" value="{{.entity.Name}}" lay-verify="required" autocomplete="off" placeholder="取个名称，用以区分" class="layui-input">
        <input type="hidden" name="id" value="{{.entity.Id}}">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">本地监听地址</label>
      <div class="layui-input-inline">
        <input type="text" name="addr" value="{{.entity.Addr}}" placeholder="默认监听所有地址" autocomplete="off" class="layui-input">
        
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">本地监听端口</label>
      <div class="layui-input-inline">
        <input type="text" name="port" value="{{if gt .entity.Port 0}}{{.entity.Port}}{{end}}" lay-verify="required|number" placeholder="端口号，例如8080" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">转发方式</label>
      <div class="layui-input-inline">
        <select name="fType">
          <option value="0" {{if eq .entity.FType 0}}selected="selected"{{end}}>端口到端口映射</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">协议</label>
      <div class="layui-input-inline">
        <select name="protocol">
          <option value="TCP" {{if eq .entity.Protocol "TCP"}}selected="selected"{{end}}>TCP</option>
          <option value="UDP" {{if eq .entity.Protocol "UDP"}}selected="selected"{{end}}>UDP</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">转发到地址</label>
      <div class="layui-input-inline">
        <input type="text" name="targetAddr" value="{{.entity.TargetAddr}}" lay-verify="required" placeholder="目标地址" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">转发到端口</label>
      <div class="layui-input-inline">
        <input type="text" name="targetPort" value="{{if gt .entity.TargetPort 0}}{{.entity.TargetPort}}{{end}}" lay-verify="required|number" placeholder="目标端口号，例如3306" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">多分发</label>
      <div class="layui-input-block">
        <input type="text" name="others" value="{{.entity.Others}}" placeholder="如 192.1.1.100:8081;192.1.1.100:8082" title="多个用 ; 号隔开" autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">一键开启</label>
      <div class="layui-input-block">
        <input type="radio" name="status" value="0" title="不支持" {{if eq .entity.Status 0}} checked {{end}}>
        <input type="radio" name="status" value="1" title="支持" {{if eq .entity.Status 1}} checked {{end}}>
      </div>
    </div>
    <div class="layui-form-item">
        <pre class="layui-code" style="text-align: left;">
*多分发说明：
如果不需要“多分发”，请留空；
如果需要分发到多个端口，填写格式为 “IP:端口”，多个用 ; 号隔开
如 192.1.1.100:8081;192.1.1.100:8082

*一键开启说明，设置为“支持”后：
通过在配置文件中添加  onstart.forward = "true" ，可让程序每次运行后就开始转发该规则，或者在列表页面通过点击“一键开启”。

        </pre> 
    </div>
  </form>

</div>

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

    layui.use(["form", "element"], function () {
      var form = layui.form;

      form.render();
    });


  });

  function submitForm(index) {
    // if ($("#form1").submit() == false) {
    //   return;
    // }
    var postData = $("#form1").serializeArray();
    $.post($("#form1").attr("action"), postData, function (json) {
      //var data = $.parseJSON(json);
      if (json.Code == 0) {
        //成功
        //layer.alert("保存成功");
        //layer.msg("保存成功.");
        refreshGrid();
        layer.close(index);

      } else {
        //
        layer.alert("失败了：" + json.Msg, { icon: 2 });
      }
    }, "json");
  }

</script>