collection.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $('.btn-add').data('area',['85%','85%']);
  5. $('.btn-edit').data('area',['85%','85%']);
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'teacher/collection/index' + location.search,
  10. add_url: 'teacher/collection/add',
  11. edit_url: 'teacher/collection/edit',
  12. del_url: 'teacher/collection/del',
  13. multi_url: 'teacher/collection/multi',
  14. import_url: 'teacher/collection/import',
  15. table: 'teacher_collection',
  16. }
  17. });
  18. var table = $("#table");
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'exam_collection_id',
  23. sortName: 'exam_collection_id',
  24. fixedColumns: true,
  25. fixedRightNumber: 1,
  26. searchFormVisible:true,
  27. columns: [
  28. [
  29. {checkbox: true},
  30. {field: 'exam_collection_id', title: __('编号')},
  31. {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  32. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  33. {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  34. {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
  35. return '考试';
  36. }
  37. },
  38. {
  39. field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  40. title: __('Exam_collection_state'),
  41. align: 'center',
  42. table: table,
  43. formatter: Table.api.formatter.collectonstate
  44. },
  45. // {field: 'task_id', title: __('Task_id')},
  46. {field: 'limit_duration', title: __('Limit_duration')},
  47. {field: 'start_time', title: __('Start_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  48. {field: 'end_time', title: __('End_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  49. // {field: 'create_user_id', title: __('Create_user_id')},
  50. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  51. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  52. // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
  53. // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  54. // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  55. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  56. // formatter: Table.api.formatter.operate
  57. formatter: Table.api.formatter.buttons,
  58. buttons: [
  59. {
  60. name: 'dispatch',
  61. text: '',
  62. icon: 'fa fa-pencil',
  63. title: '编辑',
  64. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  65. extend: 'data-area=\'["85%","85%"]\'',
  66. url: 'teacher/collection/edit',
  67. },
  68. // {
  69. // name: 'dispatch',
  70. // text: '',
  71. // icon: 'fa fa-trash',
  72. // title: '删除',
  73. // classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  74. // url: 'teacher/collection/del',
  75. // confirm: '确定要删除吗?',
  76. // success: function (data, ret) {
  77. // $(".btn-refresh").trigger("click");
  78. // },
  79. // error: function (data, ret) {
  80. // Layer.alert(ret.msg);
  81. // return false;
  82. // }
  83. // }
  84. ],
  85. }
  86. ]
  87. ]
  88. });
  89. // 为表格绑定事件
  90. Table.api.bindevent(table);
  91. },
  92. add: function () {
  93. Controller.api.bindevent();
  94. },
  95. edit: function () {
  96. Controller.api.bindevent();
  97. },
  98. api: {
  99. bindevent: function () {
  100. var rel_Ids = [];
  101. Table.api.init({
  102. extend: {
  103. index_url: 'department/admin/departadmintotal' + location.search,
  104. }
  105. });
  106. var table = $("#table1");
  107. // 初始化表格
  108. table.bootstrapTable({
  109. url: $.fn.bootstrapTable.defaults.extend.index_url,
  110. pk: 'id',
  111. sortName: 'id',
  112. fixedColumns: true,
  113. fixedRightNumber: 1,
  114. searchFormVisible:false,
  115. Search:false,
  116. columns: [
  117. [
  118. {checkbox: true,
  119. formatter: function(value,row,index){
  120. // console.log(row.id+'####'+Config.row_info.depart_ids)
  121. if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
  122. rel_Ids.push(row.id);
  123. return true;
  124. }
  125. return false;
  126. }
  127. },
  128. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  129. {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
  130. ]
  131. ]
  132. });
  133. // 为表格绑定事件
  134. Table.api.bindevent(table);
  135. table.on('click-row.bs.table', function (e, row, element) {
  136. console.log(rel_Ids)
  137. // console.log('row')
  138. if(!$.inArray(row.id,rel_Ids)){
  139. arr = $.grep(rel_Ids, function(value) {
  140. return value != row["id"];
  141. });
  142. rel_Ids = arr;
  143. }else if(rel_Ids.indexOf(row.id)>-1){
  144. var index = rel_Ids.indexOf(row.id);
  145. if (index > -1) {
  146. rel_Ids.splice(index, 1);
  147. }
  148. }else{
  149. rel_Ids.push(row.id);
  150. }
  151. $(".depart_ids").val(rel_Ids.join());
  152. });
  153. // $("input[name='btSelectAll']").click(function () {
  154. // var ids = Table.api.selectedids(table);
  155. // console.log(ids);
  156. // $(".depart_ids").val(ids);
  157. // });
  158. $("input[name='btSelectAll']").css('display','none')
  159. Form.api.bindevent($("form[role=form]"));
  160. }
  161. }
  162. };
  163. return Controller;
  164. });