category.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. $(document).on('change', '#c-channel_id', function () {
  45. Fast.api.ajax({url: 'goods/get_channel_fields', data: {channel_id: $(this).val()}}, function (data) {
  46. $("#extend").html(data.html);
  47. Form.api.bindevent($("#extend"));
  48. return false;
  49. });
  50. });
  51. $("#c-channel_id").trigger("change");
  52. Controller.api.bindevent();
  53. },
  54. edit: function () {
  55. Controller.api.bindevent();
  56. },
  57. api: {
  58. bindevent: function () {
  59. $(document).on("change", "#c-type", function () {
  60. $("#c-pid option[data-type='all']").prop("selected", true);
  61. $("#c-pid option").removeClass("hide");
  62. $("#c-pid option[data-type!='" + $(this).val() + "'][data-type!='all']").addClass("hide");
  63. $("#c-pid").selectpicker("refresh");
  64. });
  65. Form.api.bindevent($("form[role=form]"));
  66. }
  67. }
  68. };
  69. return Controller;
  70. });