<!--{include file="<!--{$oetplpath}-->block_head.tpl"}-->
<div class="layui-fluid">

  <div class="oe_breadcrumb_box clearfix" style="display:none;">
    <div class="layui-breadcrumb fl" lay-filter="breadcrumb" style="visibility: visible;">
      <a href="javascript:;">情感测试</a><span lay-separator="">/</span>
      <a><cite>添加测试</cite></a>
    </div>
    <div class="oe_tool_bar ft">
      <button class="layui-btn layui-btn-sm layui-btn-radius" id="but_submit_post2" lay-submit lay-filter="addform">
        添加保存
        <span class="oe_btn_loading layui-anim layui-icon layui-anim-rotate layui-anim-loop" style="display:none;">&#xe63d;</span>
      </button>
      <span class="layui-btn layui-btn-sm layui-btn-primary layui-btn-radius"><a href="<!--{$oefile}-->&c=<!--{$c}-->">返回列表</a></span>
    </div> 
  </div>
  
  <form class="layui-form" id="myform" action="<!--{$oefile}-->&c=<!--{$c}-->" method="post">
  <input type="hidden" name="a" id="a" value="saveadd" />
  <div class="layui-card">
    <div class="layui-card-header" style="display:none;">添加答案/结果</div>
    <div class="layui-card-body">
      <table class="oe_tbl_form layui-form">
        <tr>
          <th width="20%"><font color="red">*</font> 所属测试：</th>
          <td width="80%">
            <input type="text" name="testid" id="testid" class="layui-input input-120" value="<!--{if $testid > 0}--><!--{$testid}--><!--{/if}-->" />
            &nbsp;&nbsp;&nbsp;
            <!--{$test_title}-->
          </td>
        </tr>
        <tr>
          <th><font color="red">*</font> 得分范围：</th>
          <td>
            <input type="text" name="minscore" id="minscore" class="layui-input input-100" /> 
            至 
            <input type="text" name="maxscore" id="maxscore" class="layui-input input-100" /> 分
            
            <br />
            <span style="color:gray;">(如果只有一个分值，请填写相同分数即可)</span>
          </td>
        </tr>
        <tr>
          <th><font color="red">*</font> 结果描述：</th>
          <td>
            <textarea name="result" id="result" class="layui-textarea" style="width:90%;height:150px;"></textarea>
          </td>
        </tr>
        <tr>
          <th>排序：</th>
          <td>
            <input type="text" name="orders" id="orders" class="layui-input input-120" value="<!--{$orders}-->" />
          </td>
        </tr>
      </table>
    </div>
  </div>
  </form>
  
  <div class="oe_tbl_form_btn">
    <button class="layui-btn" id="but_submit_post" lay-submit lay-filter="addform">
      添加保存
      <span class="oe_btn_loading layui-anim layui-icon layui-anim-rotate layui-anim-loop" style="display:none;">&#xe63d;</span>
    </button>
  </div>
  
</div>

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

    layui.use('form', function(){
        var form = layui.form;
        //保存
        form.on('submit(addform)', function(data){
            var obj_id = data.elem.getAttribute("id");
            if (!$("#"+obj_id).hasClass("forbid_submit")) {
            
                var testid = $("#testid").val();
                if (testid == '' || testid == '0') {
                    layer.msg("请填写所属测试ID");
                    return false;
                }
                var minscore = $("#minscore").val();
                var maxscore = $('#maxscore').val();
                if (minscore == '' || maxscore == '') {
                    layer.msg("请填写得分范围");
                    return false;
                }
                var result = $("#result").val();
                if (result == '') {
                    layer.msg("请填写结果描述");
                    return false;
                }
                var orders = $("#orders").val();
                
                $("#"+obj_id).addClass("forbid_submit");
                $("#"+obj_id).find("span").show();
                $.ajax({
                  type: "POST",
                  url: "<!--{$oefile}-->&c=<!--{$c}-->",
                  cache: false,
                  data: {
                      a:'saveadd', testid:testid, minscore:minscore, maxscore:maxscore, 
                      result:result, orders:orders
                  },
                  dataType: "json",
                  success: function(data) {
                    var response = data.response;
                    var result = data.result;
                    if (response == '1') {
                      layer.msg("添加成功");
                      setTimeout(function(){
                        window.parent.location.reload();
                      }, 600);
                    }
                    else {
                      if (result == '' || result == null) {
                        result = '添加失败，请检查';
                      }
                      layer.msg(result);
                      $("#"+obj_id).removeClass("forbid_submit");
                      $("#"+obj_id).find("span").hide();
                    }
                  },
                  error: function() {
                    layer.msg("系统繁忙，请稍后再试！");
                    $("#"+obj_id).removeClass("forbid_submit");
                    $("#"+obj_id).find("span").hide();
                  }
                });

                
                //$("#myform").submit();
            }
        });   
    });
    
});
</script>
</body>
</html>