category.js 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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: 'cid', title: __('来源')},
  39. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  40. ]
  41. ]
  42. };
  43. // 初始化表格
  44. table.bootstrapTable(tableOptions);
  45. // 为表格绑定事件
  46. Table.api.bindevent(table);
  47. //绑定TAB事件
  48. $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
  49. // var options = table.bootstrapTable(tableOptions);
  50. var typeStr = $(this).attr("href").replace('#', '');
  51. var options = table.bootstrapTable('getOptions');
  52. options.pageNumber = 1;
  53. options.queryParams = function (params) {
  54. // params.filter = JSON.stringify({type: typeStr});
  55. params.type = typeStr;
  56. return params;
  57. };
  58. table.bootstrapTable('refresh', {});
  59. return false;
  60. });
  61. //必须默认触发shown.bs.tab事件
  62. // $('ul.nav-tabs li.active a[data-toggle="tab"]').trigger("shown.bs.tab");
  63. },
  64. add: function () {
  65. Controller.api.bindevent();
  66. setTimeout(function () {
  67. $("#c-type").trigger("change");
  68. }, 100);
  69. },
  70. edit: function () {
  71. Controller.api.bindevent();
  72. },
  73. api: {
  74. bindevent: function () {
  75. $(document).on("change", "#c-type", function () {
  76. $("#c-pid option[data-type='all']").prop("selected", true);
  77. $("#c-pid option").removeClass("hide");
  78. $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
  79. $("#c-pid").data("selectpicker") && $("#c-pid").selectpicker("refresh");
  80. });
  81. Form.api.bindevent($("form[role=form]"));
  82. }
  83. }
  84. };
  85. return Controller;
  86. });