category.js 2.7 KB

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