collection.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. singleSelect : true, //
  27. searchFormVisible:true,
  28. search:false,
  29. columns: [
  30. [
  31. {checkbox: true},
  32. {field: 'exam_collection_id', title: __('编号')},
  33. {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  34. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  35. {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  36. {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
  37. return '考试';
  38. }
  39. },
  40. {
  41. field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  42. title: __('Exam_collection_state'),
  43. align: 'center',
  44. table: table,
  45. formatter: Table.api.formatter.collectonstate
  46. },
  47. // {field: 'task_id', title: __('Task_id')},
  48. {field: 'limit_duration', title: __('Limit_duration')},
  49. {field: 'start_time', title: __('Start_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  50. {field: 'end_time', title: __('End_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  51. // {field: 'create_user_id', title: __('Create_user_id')},
  52. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  53. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  54. // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
  55. // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  56. // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  57. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  58. // formatter: Table.api.formatter.operate
  59. formatter: Table.api.formatter.buttons,
  60. buttons: [
  61. {
  62. name: 'dispatch',
  63. text: '',
  64. icon: 'fa fa-pencil',
  65. title: '编辑',
  66. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  67. extend: 'data-area=\'["85%","85%"]\'',
  68. url: 'teacher/collection/edit',
  69. },
  70. {
  71. name: 'dispatch',
  72. text: '',
  73. icon: 'fa fa-hand-pointer-o',
  74. title: '进入考试',
  75. visible: function (rr) {
  76. if(rr.exam_collection_state == 2){
  77. return true;
  78. }
  79. return false;
  80. },
  81. classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
  82. url: 'teacher/exams/persent',
  83. },
  84. // {
  85. // name: 'dispatch',
  86. // text: '',
  87. // icon: 'fa fa-trash',
  88. // title: '删除',
  89. // classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  90. // url: 'teacher/collection/del',
  91. // confirm: '确定要删除吗?',
  92. // success: function (data, ret) {
  93. // $(".btn-refresh").trigger("click");
  94. // },
  95. // error: function (data, ret) {
  96. // Layer.alert(ret.msg);
  97. // return false;
  98. // }
  99. // }
  100. ],
  101. }
  102. ]
  103. ]
  104. });
  105. // 为表格绑定事件
  106. Table.api.bindevent(table);
  107. $(document).on('click', '.btn-start', function () {
  108. var ids = Table.api.selectedids(table);
  109. Fast.api.ajax({
  110. url: "teacher/collection/start/ids/"+ids,
  111. type: "post",
  112. }, function () {
  113. table.bootstrapTable('refresh', {});
  114. Layer.close(index);
  115. });
  116. });
  117. },
  118. task: function () {
  119. // 初始化表格参数配置
  120. Table.api.init({
  121. extend: {
  122. index_url: 'teacher/collection/task/type/' +Config.sim_type+ location.search,
  123. }
  124. });
  125. var table = $("#table");
  126. var multiple = true;
  127. // 初始化表格
  128. table.bootstrapTable({
  129. url: $.fn.bootstrapTable.defaults.extend.index_url,
  130. pk: 'task_id',
  131. sortName: 'task_id',
  132. fixedColumns: true,
  133. fixedRightNumber: 1,
  134. singleSelect : true,
  135. searchFormVisible:true,
  136. columns: [
  137. [
  138. {checkbox: true},
  139. {field: 'task_id', title: __('Task_id')},
  140. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  141. // {field: 'task_type', title: __('Task_type'),operate: false,formatter: function (value, row, index) {
  142. // return '教师创建';
  143. // }
  144. // },
  145. {field: 'name', title: __('任务名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  146. {field: 'xianxiang_count', title: __('故障现象数量'),operate: false},
  147. {field: 'buwei_count', title: __('故障部位数量'),operate: false},
  148. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  149. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  150. {
  151. field: 'operate', title: __('Operate'), width: 85, events: {
  152. 'click .btn-chooseone': function (e, value, row, index) {
  153. Fast.api.close({url: row.url, multiple: multiple,task_id:row.task_id});
  154. },
  155. }, formatter: function () {
  156. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  157. }
  158. }
  159. ]
  160. ]
  161. });
  162. // 为表格绑定事件
  163. Table.api.bindevent(table);
  164. },
  165. faults: function () {
  166. // 初始化表格参数配置
  167. Table.api.init({
  168. extend: {
  169. index_url: 'teacher/collection/faults/type/'+Config.sim_type + location.search,
  170. }
  171. });
  172. var table = $("#table");
  173. var multiple = true;
  174. // 初始化表格
  175. table.bootstrapTable({
  176. url: $.fn.bootstrapTable.defaults.extend.index_url,
  177. pk: 'fault_id',
  178. sortName: 'fault_id',
  179. fixedColumns: true,
  180. fixedRightNumber: 1,
  181. searchFormVisible:true,
  182. columns: [
  183. [
  184. {checkbox: true},
  185. {field: 'sim_type', title: __('模拟器类型'),operate:false,searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  186. {field: 'parent_name', title: __('故障现象'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  187. {field: 'name', title: __('故障部位'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  188. {
  189. field: 'operate', title: __('Operate'), width: 85, events: {
  190. 'click .btn-chooseone': function (e, value, row, index) {
  191. Fast.api.close({url: row.url, multiple: multiple,task_id:row.fault_id});
  192. },
  193. }, formatter: function () {
  194. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  195. }
  196. }
  197. ]
  198. ]
  199. });
  200. // 为表格绑定事件
  201. Table.api.bindevent(table);
  202. // 选中多个
  203. $(document).on("click", ".btn-choose-multi", function () {
  204. var ids = Table.api.selectedids(table);
  205. Fast.api.close({url: '', multiple: multiple, task_id:ids});
  206. });
  207. },
  208. add: function () {
  209. Controller.api.bindevent();
  210. },
  211. edit: function () {
  212. Controller.api.bindevent();
  213. },
  214. api: {
  215. bindevent: function () {
  216. var rel_Ids = [];
  217. Table.api.init({
  218. extend: {
  219. index_url: 'department/admin/departadmintotal' + location.search,
  220. }
  221. });
  222. var table = $("#table1");
  223. // 初始化表格
  224. table.bootstrapTable({
  225. url: $.fn.bootstrapTable.defaults.extend.index_url,
  226. pk: 'id',
  227. sortName: 'id',
  228. fixedColumns: true,
  229. fixedRightNumber: 1,
  230. searchFormVisible:false,
  231. Search:false,
  232. columns: [
  233. [
  234. {checkbox: true,
  235. formatter: function(value,row,index){
  236. // console.log(row.id+'####'+Config.row_info.depart_ids)
  237. if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
  238. rel_Ids.push(row.id);
  239. return true;
  240. }
  241. return false;
  242. }
  243. },
  244. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  245. {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
  246. ]
  247. ]
  248. });
  249. // 为表格绑定事件
  250. Table.api.bindevent(table);
  251. table.on('click-row.bs.table', function (e, row, element) {
  252. console.log(rel_Ids)
  253. // console.log('row')
  254. if(!$.inArray(row.id,rel_Ids)){
  255. arr = $.grep(rel_Ids, function(value) {
  256. return value != row["id"];
  257. });
  258. rel_Ids = arr;
  259. }else if(rel_Ids.indexOf(row.id)>-1){
  260. var index = rel_Ids.indexOf(row.id);
  261. if (index > -1) {
  262. rel_Ids.splice(index, 1);
  263. }
  264. }else{
  265. rel_Ids.push(row.id);
  266. }
  267. $(".depart_ids").val(rel_Ids.join());
  268. });
  269. $(document).on('change', '#c-question_setting_method', function () {
  270. if($(this).val()==1){
  271. $(".btn-sm,.btn-task").css('display','none');
  272. }else if($(this).val()==2){
  273. $(".btn-sm").css('display','block');
  274. $(".btn-task").css('display','none');
  275. }else if($(this).val()==3){
  276. $(".btn-sm").css('display','none');
  277. $(".btn-task").css('display','block');
  278. }
  279. $(".question_ids").val(0);
  280. });
  281. //考题
  282. $(document).on('click', '.btn-sm', function () {
  283. var simtype = $("#c-sim_type").val();
  284. if(!simtype){
  285. Layer.alert('请选择模拟器类型');
  286. return false
  287. }
  288. var title = '选择考题';
  289. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype), title, {
  290. area: ["85%", "85%"],
  291. maxmin: true,
  292. moveOut: false,
  293. offset: ['40px'],
  294. callback: function(value) {
  295. console.log(value)
  296. if (value.task_id) {
  297. $(".question_ids").val(value.task_id);
  298. }
  299. }
  300. });
  301. });
  302. //任务
  303. $(document).on('click', '.btn-task', function () {
  304. var simtype = $("#c-sim_type").val();
  305. if(!simtype){
  306. Layer.alert('请选择模拟器类型');
  307. return false;
  308. }
  309. var title = '选择任务';
  310. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype), title, {
  311. area: ["85%", "85%"],
  312. maxmin: true,
  313. moveOut: false,
  314. offset: ['40px'],
  315. callback: function(value) {
  316. if (value.task_id) {
  317. $(".question_ids").val(value.task_id);
  318. }
  319. }
  320. });
  321. });
  322. // $("input[name='btSelectAll']").click(function () {
  323. // var ids = Table.api.selectedids(table);
  324. // console.log(ids);
  325. // $(".depart_ids").val(ids);
  326. // });
  327. $("input[name='btSelectAll']").css('display','none');
  328. Form.api.bindevent($("form[role=form]"));
  329. }
  330. }
  331. };
  332. return Controller;
  333. });