define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'wwh/casescategory/index', add_url: 'wwh/casescategory/add', edit_url: 'wwh/casescategory/edit', del_url: 'wwh/casescategory/del', multi_url: 'wwh/casescategory/multi', table: 'wwh_casescategory', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', escape: false, columns: [ [ { checkbox: true }, { field: 'id', title: __('Id'), }, { field: 'name', title: __('Name'), align: 'left' }, { field: 'id', title: '', operate: false, formatter: Controller.api.formatter.subnode }, { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate } ] ], pagination: false, search: false, commonSearch: false, }); //当内容渲染完成后 table.on('post-body.bs.table', function (e, settings, json, xhr) { //默认隐藏所有子节点 //$("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide(); //$(".btn-node-sub.disabled[data-pid!=0]").closest("tr").hide(); //显示隐藏子节点 $(".btn-node-sub").off("click").on("click", function (e) { var status = $(this).data("shown") || $("a.btn[data-pid='" + $(this).data("id") + "']:visible").size() > 0 ? true : false; $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () { $(this).closest("tr").toggle(!status); if (!$(this).hasClass("disabled")) { $(this).trigger("click"); } }); $(this).data("shown", !status); return false; }); }); //展开隐藏一级 $(document.body).on("click", ".btn-toggle", function (e) { $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide(); var that = this; var show = $("i", that).hasClass("fa-chevron-down"); $("i", that).toggleClass("fa-chevron-down", !show); $("i", that).toggleClass("fa-chevron-up", show); $("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").toggle(show); $(".btn-node-sub[data-pid=0]").data("shown", show); }); //展开隐藏全部 $(document.body).on("click", ".btn-toggle-all", function (e) { var that = this; var show = $("i", that).hasClass("fa-plus"); $("i", that).toggleClass("fa-plus", !show); $("i", that).toggleClass("fa-minus", show); $(".btn-node-sub.disabled[data-pid!=0]").closest("tr").toggle(show); $(".btn-node-sub[data-pid!=0]").data("shown", show); }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { formatter: { subnode: function (value, row, index) { return ''; } }, bindevent: function () { Form.api.bindevent($("form[role=form]")); }, } }; return Controller; });