<!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">
        .seach_items {float:right;margin-left: 10px;}
    </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-md5">
            <div class="LAY-btns" style="margin-bottom: 10px;">
                <div class="layui-col-xs2">
                    <button class="layui-btn" id="finance_category_add" data-permission="finance.add_finance_category"><i class="layui-icon layui-icon-add-circle"></i>添加类别</button>
                </div>
                    <form class="layui-form" lay-filter="query-form-element1">
                        <div class="seach_items">
                            <button class="layui-btn" lay-submit lay-filter="query-form-element1"><i class="layui-icon layui-icon-search"></i>查询</button>
                        </div>
                        <div class="seach_items">
                            <input type="text"  name="name" autocomplete="off" class="layui-input" placeholder="名称"/>
                        </div>
                    </form>
                <div style="clear: both;"></div>
            </div>
            <table class="layui-hide" id="finance_category_datagrid" lay-filter="finance_category-operate"></table>

            <script type="text/html" id="finance_category-operate-bar">
                <div class="layui-btn-group">
              <a class="layui-btn layui-btn-xs" lay-event="finance_category_edit" data-permission="finance.add_finance_category">修改</a>
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="finance_category_del" data-permission="finance.delete_finance_category">删除</a>
                </div>
            </script>
          </div>

          <div class="layui-col-md7">
            <div class="LAY-btns" style="margin-bottom: 10px;">
              <div class="layui-col-xs2">
                    <button class="layui-btn" id="finance_purpose_add" data-permission="finance.add_finance_category"><i class="layui-icon layui-icon-add-circle"></i>添加用途</button>
                </div>

                    <form class="layui-form" lay-filter="query-form-element2">
                        <div class="seach_items">
                            <button class="layui-btn" lay-submit lay-filter="query-form-element2"><i class="layui-icon layui-icon-search"></i>查询</button>
                        </div>
                        <div class="seach_items">
                            <input type="text"  name="name" autocomplete="off" class="layui-input" placeholder="名称"/>
                        </div>
                        <div class="seach_items">
                            <input type="text"  name="category_name" autocomplete="off" class="layui-input" placeholder="类别名称"/>
                        </div>
                    </form>
                <div style="clear: both;"></div>
                </div>

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

            <script type="text/html" id="series-operate-bar">
                <div class="layui-btn-group">
              <a class="layui-btn layui-btn-xs" lay-event="finance_purpose_edit" data-permission="finance.add_finance_category">修改</a>
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="finance_purpose_del" data-permission="finance.delete_finance_category">删除</a>
                </div>
            </script>
          </div>
        </div>
        </div>
    </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
        ,form = layui.form
        ,admin = layui.admin;
      //品牌
    table.render({
      elem: '#finance_category_datagrid'
      ,url: '/finance/finance_category/data/'
      ,cols: [[
        {field:'name', title:'名称', width:200}
        ,{field:'enabled_text', title:'在用', minWidth: 80}
        ,{width:110, align:'center', fixed: 'right', toolbar: '#finance_category-operate-bar'}
      ]]
      ,page: true
      ,height: 'full-108'
      , done: function () {
        layui.index.removeNoPermButtons()
      }
    });
    //车系
    table.render({
      elem: '#finance_purpose_datagrid'
      ,url: '/finance/finance_purpose/data/'
      ,cols: [[
        {field:'category_text', title:'类别', width:200}
        ,{field:'name', title:'名称', width:200}
        ,{field:'type_text', title:'类型', width:80}
        ,{field:'enabled_text', title:'在用', width: 100}
        ,{width:110, align:'center', fixed: 'right', toolbar: '#series-operate-bar'}
      ]]
      ,page: true
      ,height: 'full-108'
      , done: function () {
        layui.index.removeNoPermButtons()
      }
    });

    //监听品牌工具条
    table.on('tool(finance_category-operate)', function(obj) {
        var data = obj.data;
        if (obj.event === 'finance_category_del') {
            layer.confirm('确定要删除吗？', function (index) {
                layer.close(index);
                layui.admin.req({
                    url: '/finance/finance_category/delete/?id=' + data.id
                    ,type: 'get'
                    , done: function (res) {
                        table.reload('finance_category_datagrid', {});
                    }
                });
            });
        } else if (obj.event === 'finance_category_edit') {
            table.editdata = data;
            layer.open({
                type: 2,
                title: '修改',
                shadeClose: false,
                area: ['450px', '350px'],
                btn:['保存','取消'],
                yes: function (index, dom) {
                    layui.onSubmitChild = function (data) {
                        layer.close(index);
                        table.reload('finance_category_datagrid', {});
                        table.reload('finance_purpose_datagrid', {});
                      };
                      layui.submitChild();
                  },
                  btn2: function(index, layero){
                    layer.close(index);//关闭当前按钮
                  },
                content: 'finance_category_edit.html?id=' + data.id
            });
        }
    });
    //监听车系工具条
    table.on('tool(series-operate)', function(obj){
      var data = obj.data;
        if(obj.event === 'finance_purpose_del'){
        layer.confirm('确定要删除吗？', function(index){
          layui.admin.req({
            url: '/finance/finance_purpose/delete/?id='+data.id
            ,type: 'get'
            ,done: function(res){
              table.reload('finance_purpose_datagrid',{});
              layer.close(index);
            }
          });
        });
      } else if(obj.event === 'finance_purpose_edit'){
        table.editdata = data;
        layer.open({
          type: 2,
          title: '修改',
         area: ['500px', '500px'],
          btn:['保存','取消'],
          yes: function (index, dom) {
            layui.onSubmitChild = function (data) {
                layer.close(index);
                table.reload('finance_category_datagrid', {});
                table.reload('finance_purpose_datagrid', {});
              };
              layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'finance_purpose_edit.html?id='+data.id
        });
      }
    });
    form.on('submit(query-form-element1)', function(data){
      table.reload('finance_category_datagrid', {
          where: data.field
          ,page:{curr:1}
      });
      layer.closeAll();
      return false
    });
    form.on('submit(query-form-element2)', function(data){
      table.reload('finance_purpose_datagrid', {
          where: data.field
          ,page:{curr:1}
      });
      layer.closeAll();
      return false
    });
    $('#finance_category_add').on('click', function(){
        layer.open({
          type: 2,
          title: '添加',
          area: ['450px', '280px'],
          btn:['保存','取消'],
          yes: function (index, dom) {
            layui.onSubmitChild = function (data) {
                layer.close(index);
                table.reload('finance_category_datagrid', {});
                table.reload('finance_purpose_datagrid', {});
              };
              layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'finance_category_edit.html'
        });
    });
    $('#finance_purpose_add').on('click', function(){
        layer.open({
          type: 2,
          title: '添加',
          area: ['500px', '500px'],
          btn:['保存','取消'],
          yes: function (index, dom) {
            layui.onSubmitChild = function (data) {
                layer.close(index);
                table.reload('finance_category_datagrid', {});
                table.reload('finance_purpose_datagrid', {});
              };
              layui.submitChild();
          },
          btn2: function(index, layero){
            layer.close(index);//关闭当前按钮
          },
          content: 'finance_purpose_edit.html'
        });
    });
});



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