category.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. table: 'category',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. escape: false,
  20. pk: 'id',
  21. sortName: 'weigh',
  22. pagination: false,
  23. commonSearch: false,
  24. columns: [
  25. [
  26. {checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'type', title: __('Type')},
  29. {field: 'name', title: __('Name'), align: 'left'},
  30. {field: 'nickname', title: __('Nickname')},
  31. {field: 'flag', title: __('Flag'), operate: false, formatter: Table.api.formatter.flag},
  32. {field: 'image', title: __('Image'), operate: false, formatter: Table.api.formatter.image},
  33. {field: 'weigh', title: __('Weigh'), operate: false},
  34. {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status},
  35. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  36. ]
  37. ]
  38. });
  39. // 为表格绑定事件
  40. Table.api.bindevent(table);
  41. },
  42. add: function () {
  43. Controller.api.bindevent();
  44. },
  45. edit: function () {
  46. Controller.api.bindevent();
  47. },
  48. api: {
  49. bindevent: function () {
  50. $(document).on("change", "#c-type", function () {
  51. $("#c-pid option[data-type='all']").prop("selected", true);
  52. $("#c-pid option").removeClass("hide");
  53. $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
  54. $("#c-pid").selectpicker("refresh");
  55. });
  56. Form.api.bindevent($("form[role=form]"));
  57. }
  58. }
  59. };
  60. return Controller;
  61. });