department.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. let table1_extend = {
  3. index_url: 'institution/department/institutionIndex/' + location.search,
  4. table: 'templates',
  5. };
  6. let table2_extend = {
  7. index_url: 'institution/department/departmentIndex/' + location.search,
  8. add_url: 'institution/department/add',
  9. edit_url: 'institution/department/edit',
  10. del_url: 'institution/department/del',
  11. table: 'templates',
  12. };
  13. let Controller = {
  14. index: function () {
  15. // 初始化表格参数配置
  16. Table.api.init();
  17. this.table.first();
  18. this.table.second();
  19. },
  20. table: {
  21. first: function () {
  22. // 初始化表格参数配置
  23. Table.api.init({
  24. extend: table1_extend
  25. });
  26. let table1 = $("#table1");
  27. // 初始化表格
  28. table1.bootstrapTable({
  29. url: $.fn.bootstrapTable.defaults.extend.index_url,
  30. pk: 'id',
  31. pageSize: 10,
  32. toolbar: '#toolbar1',
  33. showToggle: false,
  34. showExport: false,
  35. showColumns: false,
  36. commonSearch: false,
  37. singleSelect: true, //是否启用单选
  38. clickToSelect: true,
  39. onCheck: function (rows) { // 选中事件
  40. // 刷新子级列表
  41. $('#selected_institution').data('id',rows.id);
  42. $('#toolbar2 .btn-refresh').trigger('click');
  43. },
  44. columns: [
  45. [
  46. {checkbox: true,},
  47. {field: 'name', title: __('Title')},
  48. {field: 'createdAt', title: __('CreatedAt')},
  49. ]
  50. ]
  51. });
  52. // 默认选中第一条
  53. table1.on('post-body.bs.table', function () {
  54. $('#table1 tr[data-index="0"] td input[data-index="0"]').trigger('click');
  55. });
  56. // 为表格绑定事件
  57. Table.api.bindevent(table1);
  58. },
  59. second: function () {
  60. // 初始化表格参数配置
  61. Table.api.init({
  62. extend: table2_extend
  63. });
  64. let table2 = $("#table2");
  65. // 初始化表格
  66. table2.bootstrapTable({
  67. url: $.fn.bootstrapTable.defaults.extend.index_url,
  68. pk: 'id',
  69. toolbar: '#toolbar2',
  70. showToggle: false,
  71. showColumns: false,
  72. showExport: false,
  73. commonSearch: false,
  74. queryParams: function queryParams(params) {
  75. params.ins_id = $('#selected_institution').data('id');
  76. return params;
  77. },
  78. columns: [
  79. [
  80. {field: 'department_name', title: __('Department_name')},
  81. {field: 'is_report', title: __('Is_report'),formatter: Controller.api.formatter.is_report},
  82. {
  83. field: 'operate',
  84. export:false,
  85. title: __('Operate'),
  86. table: table2,
  87. events: Table.api.events.operate,
  88. formatter: Table.api.formatter.operate
  89. }
  90. ]
  91. ]
  92. });
  93. // 为表格绑定事件
  94. Table.api.bindevent(table2);
  95. $('#toolbar2 .btn-add-2').on('click', function () {
  96. let ins_id = $('#selected_institution').data('id');
  97. let url = table2_extend.add_url;
  98. url = Table.api.replaceurl(url, {ids: ins_id}, table2);
  99. Fast.api.open(url, __('Add'), $(this).data() || {});
  100. });
  101. return table2;
  102. },
  103. },
  104. add: function () {
  105. Controller.api.bindevent();
  106. },
  107. edit: function () {
  108. Controller.api.bindevent();
  109. },
  110. api: {
  111. bindevent: function () {
  112. Form.api.bindevent($("form[role=form]"));
  113. },
  114. formatter: {
  115. is_report: function (value) {
  116. return value == '1' ? '是' : '否';
  117. }
  118. },
  119. },
  120. };
  121. return Controller;
  122. });