goodscategory.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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: 'stock/goodscategory/index',
  8. add_url: 'stock/goodscategory/add',
  9. edit_url: 'stock/goodscategory/edit',
  10. del_url: 'stock/goodscategory/del',
  11. multi_url: 'stock/goodscategory/multi',
  12. table: 'stock_goodscategory',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. height: $(window).height() - 97,
  20. pk: 'id',
  21. sortName: 'id',
  22. escape: false,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {
  27. field: 'id',
  28. title: __('Id'),
  29. },
  30. {field: 'name', title: __('商品分类名称'), align: 'left'},
  31. {
  32. field: 'id',
  33. title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle"><i class="fa fa-chevron-up"></i></a>',
  34. operate: false,
  35. formatter: Controller.api.formatter.subnode
  36. },
  37. {field: 'value', title: '分类代码'},
  38. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  39. ]
  40. ],
  41. pagination: false,
  42. search: false,
  43. commonSearch: false,
  44. });
  45. // 为表格绑定事件
  46. Table.api.bindevent(table);
  47. //当内容渲染完成后
  48. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  49. //默认隐藏所有子节点
  50. //$("a.btn[data-id][data-pid][data-pid!=0]").closest("tr").hide();
  51. // $(".btn-node-sub.disabled").closest("tr").hide();
  52. //显示隐藏子节点
  53. $(".btn-node-sub").off("click").on("click", function (e) {
  54. var status = $(this).data("shown") ? true : false;
  55. $("a.btn[data-pid='" + $(this).data("id") + "']").each(function () {
  56. $(this).closest("tr").toggle(!status);
  57. });
  58. $(this).data("shown", !status);
  59. return false;
  60. });
  61. });
  62. //展开隐藏一级
  63. $(document.body).on("click", ".btn-toggle", function (e) {
  64. $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
  65. var that = this;
  66. var show = $("i", that).hasClass("fa-chevron-down");
  67. $("i", that).toggleClass("fa-chevron-down", !show);
  68. $("i", that).toggleClass("fa-chevron-up", show);
  69. $("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
  70. $(".btn-node-sub[data-pid=0]").data("shown", show);
  71. });
  72. //展开隐藏全部
  73. $(document.body).on("click", ".btn-toggle-all", function (e) {
  74. var that = this;
  75. var show = $("i", that).hasClass("fa-plus");
  76. $("i", that).toggleClass("fa-plus", !show);
  77. $("i", that).toggleClass("fa-minus", show);
  78. $(".btn-node-sub.disabled").closest("tr").toggle(show);
  79. $(".btn-node-sub").data("shown", show);
  80. });
  81. },
  82. add: function () {
  83. Controller.api.bindevent();
  84. },
  85. edit: function () {
  86. Controller.api.bindevent();
  87. },
  88. api: {
  89. formatter: {
  90. subnode: function (value, row, index) {
  91. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
  92. + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  93. }
  94. },
  95. bindevent: function () {
  96. Form.api.bindevent($("form[role=form]"));
  97. //ajax请求根据商品类别产生商品代码
  98. function getvolnum() {
  99. Fast.api.ajax({
  100. url: 'stock/goodscategory/madevalue',
  101. type: 'POST', //GET
  102. async: true, //或false,是否异步
  103. timeout: 5000, //超时时间
  104. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  105. data: {id: $('#c-goodscategory option:selected').val()}},
  106. function (data) {
  107. $('#c-value').val(data.code);
  108. }
  109. );
  110. }
  111. $('#c-goodscategory').change(getvolnum);
  112. }
  113. }
  114. };
  115. return Controller;
  116. });