category.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'category/index',
  8. add_url: 'category/add',
  9. edit_url: 'category/edit',
  10. del_url: 'category/del',
  11. multi_url: 'category/multi',
  12. dragsort_url: 'ajax/weigh',
  13. table: 'category',
  14. }
  15. });
  16. var table = $("#table");
  17. var tableOptions = {
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. escape: false,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. pagination: false,
  23. commonSearch: false,
  24. search: false,
  25. columns: [
  26. [
  27. {checkbox: true},
  28. {field: 'id', title: __('Id')},
  29. {field: 'type', title: __('Type'), operate: false, searchList: Config.searchList, formatter: Table.api.formatter.label},
  30. {field: 'name', title: __('Name'), align: 'left'},
  31. {field: 'nickname', title: __('Nickname')},
  32. {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag},
  33. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  34. {field: 'weigh', title: __('Weigh')},
  35. {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
  36. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  37. ]
  38. ]
  39. };
  40. // 初始化表格
  41. table.bootstrapTable(tableOptions);
  42. // 为表格绑定事件
  43. Table.api.bindevent(table);
  44. //绑定TAB事件
  45. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  46. // var options = table.bootstrapTable(tableOptions);
  47. var typeStr = $(this).attr("href").replace('#', '');
  48. var options = table.bootstrapTable('getOptions');
  49. options.pageNumber = 1;
  50. options.queryParams = function (params) {
  51. // params.filter = JSON.stringify({type: typeStr});
  52. params.type = typeStr;
  53. return params;
  54. };
  55. table.bootstrapTable('refresh', {});
  56. return false;
  57. });
  58. //必须默认触发shown.bs.tab事件
  59. // $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  60. },
  61. add: function () {
  62. Controller.api.bindevent();
  63. setTimeout(function () {
  64. $("#c-type").trigger("change");
  65. }, 100);
  66. },
  67. edit: function () {
  68. Controller.api.bindevent();
  69. },
  70. api: {
  71. bindevent: function () {
  72. $(document).on("change", "#c-type", function () {
  73. $("#c-pid option[data-type='all']").prop("selected", true);
  74. $("#c-pid option").removeClass("hide");
  75. $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
  76. $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
  77. });
  78. Form.api.bindevent($("form[role=form]"));
  79. }
  80. }
  81. };
  82. return Controller;
  83. });