goods_category.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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: 'goods_category/index' + location.search,
  8. add_url: 'goods_category/add',
  9. edit_url: 'goods_category/edit',
  10. del_url: 'goods_category/del',
  11. multi_url: 'goods_category/multi',
  12. import_url: 'goods_category/import',
  13. table: 'goods_category',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. // {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  27. // {field: 'title', title: __('Title'), align: 'left', formatter:function (value, row, index) { return value.toString().replace(/(&|&)nbsp;/g, ' '); } },
  28. {field: 'title', title: __('Title'), align: 'left', formatter:function (value, row, index) {return value.toString().replace(/(&|&)nbsp;/g, ' ');}},
  29. {field: 'pid', title: __('Pid')},
  30. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  31. {field: 'weigh', title: __('Weigh'), operate: false},
  32. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  33. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  34. {field: 'status_switch', title: __('Status_switch'), table: table, formatter: Table.api.formatter.toggle},
  35. {field: 'id', title: '展开', operate: false, formatter: Controller.api.formatter.subnode},
  36. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  37. ]
  38. ],
  39. pagination: false,//隐藏分页
  40. search: false,//隐藏搜索框
  41. commonSearch: false,//隐藏搜索按钮
  42. showToggle: false,//表格视图两种模式
  43. showColumns: false,//隐藏列
  44. showExport: false,//隐藏导出
  45. });
  46. // 为表格绑定事件
  47. // Table.api.bindevent(table);
  48. Table.api.bindevent(table);
  49. //当内容渲染完成后
  50. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  51. //默认隐藏所有子节点
  52. $("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide();
  53. // $(".btn-node-sub.disabled").closest("tr").hide();
  54. //显示隐藏子节点
  55. $(".btn-node-sub").off("click").on("click", function (e) {
  56. var status = $(this).data("shown") ? true : false;
  57. $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
  58. $(this).closest("tr").toggle(!status);
  59. });
  60. $(this).data("shown", !status);
  61. return false;
  62. });
  63. //点击切换/排序/删除操作后刷新左侧菜单
  64. $(".btn-change[data-id],.btn-delone,.btn-dragsort").data("success", function (data, ret) {
  65. Fast.api.refreshmenu();
  66. return false;
  67. });
  68. });
  69. //批量删除后的回调
  70. $(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) {
  71. Fast.api.refreshmenu();
  72. });
  73. //展开隐藏一级
  74. $(document.body).on("click", ".btn-toggle", function (e) {
  75. $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
  76. var that = this;
  77. var show = $("i", that).hasClass("fa-chevron-down");
  78. $("i", that).toggleClass("fa-chevron-down", !show);
  79. $("i", that).toggleClass("fa-chevron-up", show);
  80. $("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
  81. $(".btn-node-sub[data-pid=0]").data("shown", show);
  82. });
  83. //展开隐藏全部
  84. $(document.body).on("click", ".btn-toggle-all", function (e) {
  85. var that = this;
  86. var show = $("i", that).hasClass("fa-plus");
  87. $("i", that).toggleClass("fa-plus", !show);
  88. $("i", that).toggleClass("fa-minus", show);
  89. $(".btn-node-sub.disabled").closest("tr").toggle(show);
  90. $(".btn-node-sub").data("shown", show);
  91. });
  92. },
  93. add: function () {
  94. Controller.api.bindevent();
  95. },
  96. edit: function () {
  97. Controller.api.bindevent();
  98. },
  99. api: {
  100. formatter: {
  101. subnode: function (value, row, index) {
  102. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
  103. + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  104. }
  105. },
  106. bindevent: function () {
  107. Form.api.bindevent($("form[role=form]"));
  108. }
  109. }
  110. };
  111. return Controller;
  112. });