<!DOCTYPE html>
<html>
<head>
  <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">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
  <style type="text/css">
      .layui-form-select dl{max-height: 150px;}
  </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body" pad15>
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">

                    <div class="LAY-btns" style="margin-bottom: 10px;">
                        <button class="layui-btn layui-btn-sm" data-permission="foundation.add_option" id="btn_add"><i class="layui-icon layui-icon-add-circle"></i>添加</button>
                        <button class="layui-btn layui-btn-sm" data-permission="foundation.view_option" id="btn_select"><i class="layui-icon layui-icon-search"></i>查询</button>
                    </div>

                    <table class="layui-hide" id="datagrid" lay-filter="datagrid-operate"></table>

                    <script type="text/html" id="datagrid-operate-bar">
                        <div class="layui-btn-group">
                            <a class="layui-btn layui-btn-xs" data-permission="foundation.add_option" lay-event="edit">修改</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" data-permission="foundation.delete_option" lay-event="del">删除</a>
                        </div>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
    <div id="dlg_query" style="display: none">
    <div class="layui-card-body" pad15>
        <form class="layui-form" lay-filter="query-form-element">
          <div class="layui-row layui-col-space10 layui-form-item">
              <div class="layui-col-xs12 layui-col-sm12">
                <label class="layui-form-label">类别：</label>
                <div class="layui-input-block">
                    <select name="type">
                        <option value=""></option>
                        <option value="1">原料类别</option>
                        <option value="2">耗材类别</option>
                        <option value="3">成品类别</option>
                        <option value="4">质量要求</option>
                    </select>
                </div>
              </div>
            </div>
          <div class="layui-form-item" style="display: none">
                <button class="layui-btn" lay-submit lay-filter="query-form-element" id="query_btn">查询</button>
          </div>
        </form>
    </div>
  </div>
  <script src="../../layuiadmin/layui/layui.js?t=1"></script>
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table', 'form'], function(){
    var $ = layui.$;
    var table = layui.table;
    var form = layui.form;

    table.render({
      elem: '#datagrid'
      ,url: '/foundation/option/data/'
      ,cols: [[
        {field:'name', title:'名称', width:200}
        ,{field:'type_text', title:'类别', width:100}
        ,{field:'enabled_text', title:'在用', width:80}
        ,{field:'notes', title:'备注', minWidth: 150}
        ,{width:100, align:'left', fixed: 'right', toolbar: '#datagrid-operate-bar'}
      ]]
      ,page: true
      ,height: 'full-104'
      ,done:function () {
        layui.index.removeNoPermButtons();
      }
    });

    //监听工具条
    table.on('tool(datagrid-operate)', function(obj) {
        var data = obj.data;
        if (obj.event === 'detail') {
            layer.msg('ID：' + data.id + ' 的查看操作');
        } else if (obj.event === 'del') {
            layer.confirm('确定要删除吗？', function (index) {
                layer.close(index);
                layui.admin.req({
                    url: '/foundation/option/delete/?id=' + data.id
                    , done: function (res) {
                        table.reload('datagrid', {});
                    }
                });
            });
        } else if (obj.event === 'edit') {
            table.editdata = data;
            layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                area: ['450px', '400px'],
                btn: ['保存', '取消'],
                content: 'option_edit.html?id=' + data.id,
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('datagrid', {});
                    };
                    layui.submitChild();
                },
                btn2: function (index, layero) {
                    layer.close(index);//关闭当前按钮
                }
            });
        }
    });
    $('#btn_select').on('click', function(){
        layer.open({
          type: 1,
          shadeClose: true,
          area: ['500px', '400px'],
          title: '查询',
          btn: ['查询'],
          content: $('#dlg_query'),
          yes:function(index, dom){
              $('#query_btn').click();
          },
        });
    });
      $('#btn_add').on('click', function () {
          layer.open({
              type: 2,
              title: '添加',
              shadeClose: false,
              area: ['450px', '400px'],
              btn: ['保存', '取消'],
              content: 'option_edit.html',
              yes: function (index, dom) {
                  layui.onSubmitChild = function (data) {
                      layer.close(index);
                      table.reload('datagrid', {});
                  };
                  layui.submitChild();
              },
              btn2: function (index, layero) {
                  layer.close(index);//关闭当前按钮
              }
          });
      });
    form.on('submit(query-form-element)', function(data){
      _params = data.field;
      table.reload('datagrid', {
          where: data.field,
          page:{curr:1}

      });
      layer.closeAll();
      return false
    });
  });
  </script>
</body>
</html>

