privatetmp.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. let table1_extend = {
  3. index_url: 'template/privatetmp/parentIndex/' + location.search,
  4. table: 'templates',
  5. };
  6. let table2_extend = {
  7. index_url: 'template/privatetmp/childIndex/' + location.search,
  8. table: 'templates',
  9. };
  10. let Controller = {
  11. index: function () {
  12. // 初始化表格参数配置
  13. Table.api.init();
  14. this.table.first();
  15. this.table.second();
  16. },
  17. table: {
  18. first: function () {
  19. // 初始化表格参数配置
  20. Table.api.init({
  21. extend: table1_extend
  22. });
  23. let table1 = $("#table1");
  24. // 初始化表格
  25. table1.bootstrapTable({
  26. url: $.fn.bootstrapTable.defaults.extend.index_url,
  27. pk: 'id',
  28. pageSize: 10,
  29. toolbar: '#toolbar1',
  30. showToggle: false,
  31. showExport: false,
  32. showColumns: false,
  33. commonSearch: false,
  34. singleSelect: true, //是否启用单选
  35. clickToSelect: true,
  36. onCheck: function (rows) { // 选中事件
  37. // 刷新子级列表
  38. $('#child_name').text(rows.title);
  39. $('#selected_parent').data('pid',rows.id);
  40. $('#toolbar2 .btn-refresh').trigger('click');
  41. },
  42. columns: [
  43. [
  44. {checkbox: true,},
  45. {field: 'title', title: __('Title')},
  46. {field: 'exam_class_id', title: __('Exam_class_id')},
  47. {
  48. field: 'operate',
  49. title: __('Operate'),
  50. table: table1,
  51. events: Controller.api.events.table1_operate,
  52. formatter: Table.api.formatter.operate
  53. }
  54. ]
  55. ]
  56. });
  57. // 默认选中第一条
  58. table1.on('post-body.bs.table', function () {
  59. $('#table1 tr[data-index="0"] td input[data-index="0"]').trigger('click');
  60. });
  61. // 为表格绑定事件
  62. Table.api.bindevent(table1);
  63. // 自定义添加按钮事件
  64. $('#toolbar1 .btn-add-1').on('click', function () {
  65. let ids = Table.api.selectedids(table1);
  66. let url = table1_extend.add_url;
  67. if (url.indexOf("{ids}") !== -1) {
  68. url = Table.api.replaceurl(url, {ids: ids.length > 0 ? ids.join(",") : 0}, table1);
  69. }
  70. Fast.api.open(url, __('Add'), $(this).data() || {});
  71. });
  72. },
  73. second: function () {
  74. // 初始化表格参数配置
  75. Table.api.init({
  76. extend: table2_extend
  77. });
  78. let table2 = $("#table2");
  79. // 初始化表格
  80. table2.bootstrapTable({
  81. url: $.fn.bootstrapTable.defaults.extend.index_url,
  82. pk: 'id',
  83. toolbar: '#toolbar2',
  84. sortName: 'createdAt',
  85. showToggle: false,
  86. showColumns: false,
  87. queryParams: function queryParams(params) {
  88. params.pid = $('#selected_parent').data('pid');
  89. return params;
  90. },
  91. columns: [
  92. [
  93. {field: 'title', title: __('Title'), align: "left"},
  94. {field: 'exam_class_id', title: __('Exam_class_id'),searchable:false},
  95. {field: 'description', title: __('Description'), searchable:false, formatter:Table.api.formatter.content, width: '200'},
  96. {field: 'impression', title: __('Impression'), searchable:false, formatter:Table.api.formatter.content, width: '200'},
  97. {field: 'createdAt', title: __('Createdat'), operate: 'RANGE', addclass: 'datetimerange'},
  98. {
  99. field: 'operate',
  100. title: __('Operate'),
  101. table: table2,
  102. events: Table.api.events.operate,
  103. formatter: Table.api.formatter.operate
  104. }
  105. ]
  106. ]
  107. });
  108. // 为表格绑定事件
  109. Table.api.bindevent(table2);
  110. $('#toolbar2 .btn-add-2').on('click', function () {
  111. let pid = $('#selected_parent').data('pid');
  112. let url = table2_extend.add_url;
  113. url = Table.api.replaceurl(url, {ids: pid}, table2);
  114. Fast.api.open(url, __('Add'), $(this).data() || {});
  115. });
  116. return table2;
  117. },
  118. },
  119. api: {
  120. formatter: {
  121. name: function (value) {
  122. return "<strong>" + value + "</strong>";
  123. }
  124. },
  125. events: {
  126. table1_operate: {
  127. 'click .btn-editone': function (e, value, row, index) {
  128. e.stopPropagation();
  129. e.preventDefault();
  130. let table = $(this).closest('table');
  131. let options = table.bootstrapTable('getOptions');
  132. let ids = row[options.pk];
  133. row = $.extend({}, row ? row : {}, {ids: ids});
  134. let url = table1_extend.edit_url;
  135. Fast.api.open(Table.api.replaceurl(url, row, table), __('Edit'), $(this).data() || {});
  136. },
  137. 'click .btn-delone': function (e, value, row, index) {
  138. e.stopPropagation();
  139. e.preventDefault();
  140. let that = this;
  141. $(that).data('url',table1_extend.del_url);
  142. let top = $(that).offset().top - $(window).scrollTop();
  143. let left = $(that).offset().left - $(window).scrollLeft() - 260;
  144. if (top + 154 > $(window).height()) {
  145. top = top - 154;
  146. }
  147. if ($(window).width() < 480) {
  148. top = left = undefined;
  149. }
  150. Layer.confirm(
  151. __('Are you sure you want to delete this item?'),
  152. {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true},
  153. function (index) {
  154. let table = $(that).closest('table');
  155. let options = table.bootstrapTable('getOptions');
  156. Table.api.multi("del", row[options.pk], table, that);
  157. Layer.close(index);
  158. }
  159. );
  160. }
  161. }
  162. }
  163. },
  164. };
  165. return Controller;
  166. });