customer.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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/customer/index',
  8. add_url: 'stock/customer/add',
  9. edit_url: 'stock/customer/edit',
  10. del_url: 'stock/customer/del',
  11. multi_url: 'stock/customer/multi',
  12. table: 'stock_customer',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'weigh',
  21. escape: false,
  22. columns: [
  23. [
  24. { checkbox: true },
  25. { field: 'id', title: __('Id'),width:50 },
  26. { field: 'encode', title: __('Encode'),align:'left' },
  27. { field: 'name', title: __('Name'),width:150,align:'left' },
  28. {
  29. field: 'id',
  30. title: '<a href="javascript:;" class="btn btn-success btn-xs btn-toggle"><i class="fa fa-chevron-up"></i></a>',
  31. operate: false,
  32. formatter: Controller.api.formatter.subnode
  33. },
  34. { field: 'shortname', title: __('Shortname') },
  35. { field: 'innerphone', title: __('Innerphone') },
  36. { field: 'weigh', title: __('Weigh') },
  37. { field: 'enabledmark', title: __('Enabledmark'), visible: false, searchList: { "1": __('Enabledmark 1'), "0": __('Enabledmark 0') } },
  38. { field: 'enabledmark_text', title: __('Enabledmark'), operate: false },
  39. { field: 'remark', title: __('Remark') },
  40. { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
  41. ]
  42. ],
  43. pagination: false,
  44. search: false,
  45. commonSearch: false,
  46. });
  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. $(".btn-change[data-id],.btn-delone,.btn-dragsort").data("success", function (data, ret) {
  62. Fast.api.refreshmenu();
  63. });
  64. });
  65. //批量删除后的回调
  66. $(".toolbar > .btn-del,.toolbar .btn-more~ul>li>a").data("success", function (e) {
  67. Fast.api.refreshmenu();
  68. });
  69. //展开隐藏一级
  70. $(document.body).on("click", ".btn-toggle", function (e) {
  71. $("a.btn[data-id][data-pid][data-pid!=0].disabled").closest("tr").hide();
  72. var that = this;
  73. var show = $("i", that).hasClass("fa-chevron-down");
  74. $("i", that).toggleClass("fa-chevron-down", !show);
  75. $("i", that).toggleClass("fa-chevron-up", show);
  76. $("a.btn[data-id][data-pid][data-pid!=0]").not('.disabled').closest("tr").toggle(show);
  77. $(".btn-node-sub[data-pid=0]").data("shown", show);
  78. });
  79. //展开隐藏全部
  80. $(document.body).on("click", ".btn-toggle-all", function (e) {
  81. var that = this;
  82. var show = $("i", that).hasClass("fa-plus");
  83. $("i", that).toggleClass("fa-plus", !show);
  84. $("i", that).toggleClass("fa-minus", show);
  85. $(".btn-node-sub.disabled").closest("tr").toggle(show);
  86. $(".btn-node-sub").data("shown", show);
  87. });
  88. // 为表格绑定事件
  89. Table.api.bindevent(table);
  90. },
  91. add: function () {
  92. Controller.api.bindevent();
  93. },
  94. edit: function () {
  95. Controller.api.bindevent();
  96. },
  97. api: {
  98. formatter: {
  99. subnode: function (value, row, index) {
  100. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Toggle sub menu') + '" data-id="' + row.id + '" data-pid="' + row.pid + '" class="btn btn-xs '
  101. + (row.haschild == 1 || row.ismenu == 1 ? 'btn-success' : 'btn-default disabled') + ' btn-node-sub"><i class="fa fa-sitemap"></i></a>';
  102. }
  103. },
  104. bindevent: function () {
  105. //ajax请求根据父级客户产生客户代码
  106. function madeEncode() {
  107. $.ajax({
  108. url: 'stock/customer/madeencode',
  109. type: 'POST', //GET
  110. async: true, //或false,是否异步
  111. timeout: 5000, //超时时间
  112. dataType: 'json', //返回的数据格式:json/xml/html/script/jsonp/text
  113. data: { id: $('#c-pid option:selected').val() },
  114. success: function (data) {
  115. $('#c-encode').val(data);
  116. }
  117. });
  118. }
  119. $('#c-pid').change(madeEncode);
  120. Form.api.bindevent($("form[role=form]"));
  121. }
  122. }
  123. };
  124. return Controller;
  125. });