category.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. pk: 'id',
  20. sortName: 'weigh',
  21. pagination: false,
  22. commonSearch: false,
  23. search: false,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'type', title: __('Type'), operate: false, searchList: Config.searchList, formatter: Table.api.formatter.label},
  29. {field: 'name', title: __('Name'), align: 'left', formatter:function (value, row, index) {
  30. return value.toString().replace(/(&|&)nbsp;/g, ' ');
  31. }
  32. },
  33. {field: 'nickname', title: __('Nickname')},
  34. {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag},
  35. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  36. {field: 'weigh', title: __('Weigh')},
  37. {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
  38. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  39. ]
  40. ]
  41. };
  42. // 初始化表格
  43. table.bootstrapTable(tableOptions);
  44. // 为表格绑定事件
  45. Table.api.bindevent(table);
  46. //绑定TAB事件
  47. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  48. // var options = table.bootstrapTable(tableOptions);
  49. var typeStr = $(this).attr("href").replace('#', '');
  50. var options = table.bootstrapTable('getOptions');
  51. options.pageNumber = 1;
  52. options.queryParams = function (params) {
  53. // params.filter = JSON.stringify({type: typeStr});
  54. params.type = typeStr;
  55. return params;
  56. };
  57. table.bootstrapTable('refresh', {});
  58. return false;
  59. });
  60. //必须默认触发shown.bs.tab事件
  61. // $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  62. },
  63. add: function () {
  64. Controller.api.bindevent();
  65. setTimeout(function () {
  66. $("#c-type").trigger("change");
  67. }, 100);
  68. },
  69. edit: function () {
  70. Controller.api.bindevent();
  71. },
  72. api: {
  73. bindevent: function () {
  74. $(document).on("change", "#c-type", function () {
  75. $("#c-pid option[data-type='all']").prop("selected", true);
  76. $("#c-pid option").removeClass("hide");
  77. $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
  78. $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
  79. });
  80. Form.api.bindevent($("form[role=form]"));
  81. }
  82. }
  83. };
  84. return Controller;
  85. });