collection.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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: 'teacher/collection/index' + location.search,
  8. add_url: 'teacher/collection/add',
  9. edit_url: 'teacher/collection/edit',
  10. del_url: 'teacher/collection/del',
  11. multi_url: 'teacher/collection/multi',
  12. import_url: 'teacher/collection/import',
  13. table: 'teacher_collection',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'exam_collection_id',
  21. sortName: 'exam_collection_id',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. singleSelect : true, //
  25. searchFormVisible:true,
  26. search:false,
  27. columns: [
  28. [
  29. {checkbox: true},
  30. {field: 'exam_collection_id', title: __('编号'),operate: false},
  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. {
  35. field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  36. title: __('Exam_collection_state'),
  37. align: 'center',
  38. table: table,
  39. formatter: Table.api.formatter.collectonstate
  40. },
  41. // {field: 'task_id', title: __('Task_id')},
  42. {field: 'limit_duration', title: __('Limit_duration')},
  43. // {field: 'start_time', title: __('Start_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  44. // {field: 'end_time', title: __('End_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  45. // {field: 'create_user_id', title: __('Create_user_id')},
  46. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  47. // {field: 'qudui_count', title: __('区队数量'), operate: false},
  48. {field: 'xueyuan_count', title: __('应考人数'), operate: false},
  49. {field: 'yikao_count', title: __('已考人数'), operate: false},
  50. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  51. // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
  52. // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  53. // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  54. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  55. // formatter: Table.api.formatter.operate
  56. formatter: Table.api.formatter.buttons,
  57. buttons: [
  58. {
  59. name: 'dispatch',
  60. text: '编辑',
  61. icon: 'fa fa-pencil',
  62. title: '编辑',
  63. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  64. // extend: 'data-area=\'["85%","85%"]\'',
  65. url: 'teacher/collection/edit',
  66. },
  67. {
  68. name: 'dispatch',
  69. text: '进入考试',
  70. icon: 'fa fa-hand-pointer-o',
  71. title: '进入考试',
  72. visible: function (rr) {
  73. if(rr.exam_collection_state == 2){
  74. return true;
  75. }
  76. return false;
  77. },
  78. classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
  79. url: 'teacher/exams/persent',
  80. },
  81. {
  82. name: 'dispatch',
  83. text: '查看学员',
  84. icon: 'fa fa-eye',
  85. title: '查看学员',
  86. visible: function (rr) {
  87. if(rr.user_count > 0){
  88. return true;
  89. }
  90. return false;
  91. },
  92. classname: 'btn btn-warning btn-xs btn-magic btn-dialog',
  93. extend: 'data-area=\'["85%","85%"]\'',
  94. url: 'teacher/collection/viewuser',
  95. },
  96. {
  97. name: 'dispatch',
  98. text: '添加学员',
  99. icon: 'fa fa-plus',
  100. title: '添加学员',
  101. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  102. extend: 'data-area=\'["85%","85%"]\'',
  103. url: 'teacher/collection/adduser',
  104. },
  105. {
  106. name: 'dispatch',
  107. text: '删除学员',
  108. icon: 'fa fa-pencil',
  109. title: '删除学员',
  110. visible: function (rr) {
  111. if(rr.user_count > 0){
  112. return true;
  113. }
  114. return false;
  115. },
  116. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  117. extend: 'data-area=\'["75%","75%"]\'',
  118. url: 'teacher/collection/edituser',
  119. },
  120. {
  121. name: 'dispatch',
  122. text: '删除',
  123. icon: 'fa fa-trash',
  124. title: '删除',
  125. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  126. url: 'teacher/collection/del',
  127. confirm: '确定要删除吗?',
  128. success: function (data, ret) {
  129. $(".btn-refresh").trigger("click");
  130. },
  131. error: function (data, ret) {
  132. Layer.alert(ret.msg);
  133. return false;
  134. }
  135. }
  136. ],
  137. }
  138. ]
  139. ]
  140. });
  141. // 为表格绑定事件
  142. Table.api.bindevent(table);
  143. $(document).on('click', '.btn-start', function () {
  144. var ids = Table.api.selectedids(table);
  145. Fast.api.ajax({
  146. url: "teacher/collection/start/ids/"+ids,
  147. type: "post",
  148. }, function () {
  149. Layer.alert('开始成功');
  150. table.bootstrapTable('refresh');
  151. Layer.close(index);
  152. });
  153. });
  154. },
  155. viewuser: function () {
  156. // 初始化表格参数配置
  157. Table.api.init({
  158. extend: {
  159. index_url: 'teacher/collection/viewuser/ids/' +Config.ids+ location.search,
  160. }
  161. });
  162. var table = $("#table");
  163. var multiple = true;
  164. // 初始化表格
  165. table.bootstrapTable({
  166. url: $.fn.bootstrapTable.defaults.extend.index_url,
  167. pk: 'task_id',
  168. sortName: 'task_id',
  169. fixedColumns: true,
  170. fixedRightNumber: 1,
  171. singleSelect : true,
  172. searchFormVisible:true,
  173. search: false,
  174. columns: [
  175. [
  176. // {checkbox: true},
  177. // {field: 'task_id', title: __('Task_id'),operate: false},
  178. {field: 'user_nickname', title: __('学员'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  179. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  180. {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  181. {field: 'fault_names', title: __('故障内容'),formatter: Table.api.formatter.faultname,operate: false},
  182. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  183. // {
  184. // field: 'operate', title: __('Operate'), width: 85, events: {
  185. // 'click .btn-chooseone': function (e, value, row, index) {
  186. // Fast.api.close({url: row.url, multiple: multiple,task_id:row.task_id,task_name:row.name,fault_name:row.fault_name});
  187. // },
  188. // }, formatter: function () {
  189. // return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  190. // }
  191. // }
  192. ]
  193. ]
  194. });
  195. // 为表格绑定事件
  196. Table.api.bindevent(table);
  197. },
  198. task: function () {
  199. // 初始化表格参数配置
  200. Table.api.init({
  201. extend: {
  202. index_url: 'teacher/collection/task/type/' +Config.sim_type+ location.search,
  203. }
  204. });
  205. var table = $("#table");
  206. var multiple = true;
  207. // 初始化表格
  208. table.bootstrapTable({
  209. url: $.fn.bootstrapTable.defaults.extend.index_url,
  210. pk: 'task_id',
  211. sortName: 'task_id',
  212. fixedColumns: true,
  213. fixedRightNumber: 1,
  214. singleSelect : true,
  215. searchFormVisible:true,
  216. search: false,
  217. columns: [
  218. [
  219. {checkbox: true},
  220. {field: 'task_id', title: __('Task_id'),operate: false},
  221. {field: 'name', title: __('任务名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  222. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  223. {field: 'fault_name', title: __('故障内容'),formatter: Table.api.formatter.faultname},
  224. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  225. {
  226. field: 'operate', title: __('Operate'), width: 85, events: {
  227. 'click .btn-chooseone': function (e, value, row, index) {
  228. Fast.api.close({url: row.url, multiple: multiple,task_id:row.task_id,task_name:row.name,fault_name:row.fault_name});
  229. },
  230. }, formatter: function () {
  231. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  232. }
  233. }
  234. ]
  235. ]
  236. });
  237. // 为表格绑定事件
  238. Table.api.bindevent(table);
  239. },
  240. faults: function () {
  241. // 初始化表格参数配置
  242. Table.api.init({
  243. extend: {
  244. index_url: 'teacher/collection/faults/type/'+Config.sim_type + location.search,
  245. }
  246. });
  247. var table = $("#table");
  248. var multiple = true;
  249. // 初始化表格
  250. table.bootstrapTable({
  251. url: $.fn.bootstrapTable.defaults.extend.index_url,
  252. pk: 'fault_id',
  253. sortName: 'fault_id',
  254. sortOrder:'asc',
  255. fixedColumns: true,
  256. fixedRightNumber: 1,
  257. searchFormVisible:false,
  258. showExport:false,
  259. pagination:false,
  260. search:false,
  261. columns: [
  262. [
  263. {checkbox: true},
  264. {field: 'sim_type', title: __('模拟器类型'),operate:false,searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  265. {field: 'parent_name', title: __('故障现象'), operate: false, table: table, class: 'autocontent',},
  266. {field: 'name', title: __('故障内容'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  267. // {
  268. // field: 'operate', title: __('Operate'), width: 85, events: {
  269. // 'click .btn-chooseone': function (e, value, row, index) {
  270. // Fast.api.close({url: row.url, multiple: multiple,task_id:row.fault_id});
  271. // },
  272. // }, formatter: function () {
  273. // return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  274. // }
  275. // }
  276. ]
  277. ]
  278. });
  279. // 为表格绑定事件
  280. Table.api.bindevent(table);
  281. // 选中多个
  282. $(document).on("click", ".btn-choose-multi", function () {
  283. var ids = Table.api.selectedids(table);
  284. if(ids.length!=3){
  285. Layer.alert('故障内容只允许选择3个');
  286. return false
  287. }
  288. console.log(ids)
  289. var taskname = [];
  290. var ptaskids = [];
  291. var datas = $("#table").bootstrapTable('getSelections');
  292. $.each(datas,function (index,val) {
  293. taskname.push(val.name)
  294. // var index = ptaskids.indexOf(val.parent_fault_id);
  295. // if (index > -1) {
  296. // Layer.alert('一个故障现象下只允许申请一个故障部位');
  297. // return false
  298. // }
  299. ptaskids.push(val.parent_fault_id)
  300. })
  301. console.log(taskname)
  302. console.log('taskname')
  303. console.log(ptaskids);
  304. var obj = {};
  305. for (var i = 0; i < ptaskids.length; i++) {
  306. var str = ptaskids[i];
  307. if (obj[str]) {
  308. Layer.alert('一个故障现象下只允许申请一个故障部位');
  309. return;
  310. } else {
  311. obj[str] = str; // 存入对象中做标记
  312. }
  313. }
  314. Fast.api.close({url: '', multiple: multiple, task_id:ids,task_name:taskname});
  315. });
  316. $("button[name=commonSearch]").css('display','none');
  317. },
  318. add: function () {
  319. Controller.api.bindevent1();
  320. },
  321. adduser: function () {
  322. Controller.api.bindevent2();
  323. },
  324. edituser: function () {
  325. Controller.api.bindevent2();
  326. },
  327. edit: function () {
  328. Controller.api.bindevent1();
  329. },
  330. api: {
  331. bindevent1: function () {
  332. Form.api.bindevent($("form[role=form]"));
  333. },
  334. initSubTable: function (index, row, $detail,parent_table) {
  335. var admin_id = row.id;
  336. var cur_table = $detail.html('<table id="sub_'+ admin_id +'" style="background-color:#d7d1d147"></table>').find('table');
  337. var sub_table = $(cur_table);
  338. sub_table.bootstrapTable({
  339. // url: 'area/index',
  340. toolbar: false,
  341. showColumns: false,
  342. showToggle: false,
  343. showExport: false,
  344. search: false,
  345. pagination:false,
  346. commonSearch: false,
  347. sortOrder: 'ASC',
  348. checkboxHeader: false,
  349. columns: [
  350. {checkbox: true,
  351. formatter: function(value,rows,index){
  352. console.log('Config.user_ids');
  353. console.log(Config.user_ids);
  354. if(Config.user_ids.length==0){
  355. return false;
  356. }else if(Config.user_ids.indexOf(rows.id)>-1){
  357. return true;
  358. }else{
  359. return {disabled : true}
  360. }
  361. }
  362. },
  363. // {field: 'id', title: 'ID'},
  364. {field: 'username', title: __('学号')},
  365. {field: 'nickname', title: __('姓名')},
  366. ],
  367. data: row.alluser
  368. });
  369. Table.api.bindevent(sub_table);
  370. sub_table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table", function (e) {
  371. var selectedIds = Table.api.selectedids(sub_table);
  372. console.log(selectedIds);
  373. $(".xueyuan_input").val(selectedIds.length);
  374. $(".xueyuan_total").html(selectedIds.length);
  375. $(".depart_ids").val(selectedIds.join());
  376. })
  377. },
  378. bindevent2: function () {
  379. var rel_Ids = [];
  380. var qudui_total = 0;
  381. var xueyuan_total = 0;
  382. Table.api.init({
  383. extend: {
  384. index_url: 'department/admin/departadmintotal' + location.search,
  385. // index_url: 'auth/admin/admintotal' + location.search,
  386. }
  387. });
  388. var table = $("#table1");
  389. // var oInit = new Object();
  390. // 初始化表格
  391. table.bootstrapTable({
  392. url: $.fn.bootstrapTable.defaults.extend.index_url,
  393. pk: 'id',
  394. sortName: 'id',
  395. fixedColumns: true,
  396. fixedRightNumber: 1,
  397. searchFormVisible:false,
  398. // pagination:false,
  399. detailView: true,//父子表
  400. Search:false,
  401. columns: [
  402. [
  403. {checkbox: true},
  404. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  405. {field: 'department_admin_count', title: __('人员数量'),operate: false},
  406. ]
  407. ],
  408. onExpandRow: function (index, row, $detail) {
  409. Controller.api.initSubTable(index, row, $detail);
  410. },
  411. onCheck: function (row, $element) {
  412. $('.btn-disabled').addClass('disabled');
  413. var id = row.id;
  414. $("#sub_" + id).bootstrapTable("checkAll");
  415. },
  416. onUncheck: function (row) {
  417. var id = row.id;
  418. $("#sub_" + id).bootstrapTable("uncheckAll");
  419. },
  420. });
  421. // 为表格绑定事件
  422. Table.api.bindevent(table);
  423. $(document).on('change', '#c-question_setting_method', function () {
  424. if($(this).val()==1){
  425. $(".btn-sm,.btn-task").css('display','none');
  426. }else if($(this).val()==2){
  427. $(".btn-sm").show();
  428. $(".btn-task").css('display','none');
  429. }else if($(this).val()==3){
  430. $(".btn-sm").css('display','none');
  431. $(".btn-task").show();
  432. }
  433. $(".question_ids").val(0);
  434. $(".task_id").val(0);
  435. $("#c-task_name").val('');
  436. $("#c-fault_name").val('');
  437. $("#c-question_name").val('');
  438. $(".tasks,.questions").css('display','none')
  439. });
  440. //考题
  441. $(document).on('click', '.btn-sm', function () {
  442. var simtype = $("#c-sim_type").val();
  443. if(!simtype){
  444. Layer.alert('请选择模拟器类型');
  445. return false
  446. }
  447. var title = '选择考题';
  448. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype), title, {
  449. area: ["85%", "85%"],
  450. maxmin: true,
  451. moveOut: false,
  452. offset: ['40px'],
  453. callback: function(value) {
  454. if (value.task_id) {
  455. $(".questions").css('display','block')
  456. $(".question_ids").val(value.task_id);
  457. $("#c-question_name").val(value.task_name);
  458. $(".tasks").css('display','none')
  459. $(".task_id").val(0);
  460. $("#c-task_name").val('');
  461. $("#c-fault_name").val('');
  462. }
  463. }
  464. });
  465. });
  466. //任务
  467. $(document).on('click', '.btn-task', function () {
  468. var simtype = $("#c-sim_type").val();
  469. if(!simtype){
  470. Layer.alert('请选择模拟器类型');
  471. return false;
  472. }
  473. var title = '选择任务';
  474. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype), title, {
  475. area: ["65%", "70%"],
  476. maxmin: true,
  477. moveOut: false,
  478. offset: ['40px'],
  479. callback: function(value) {
  480. console.log(value);
  481. if (value.task_id) {
  482. $(".tasks").css('display','block')
  483. $(".task_id").val(value.task_id);
  484. $("#c-task_name").val(value.task_name);
  485. $("#c-fault_name").val(value.fault_name);
  486. $(".questions").css('display','none')
  487. $(".question_ids").val(0);
  488. $("#c-question_name").val('');
  489. }
  490. }
  491. });
  492. });
  493. $("button[name=commonSearch]").css('display','none');
  494. $("input[name='btSelectAll']").css('display','none');
  495. Form.api.bindevent($("form[role=form]"));
  496. },
  497. }
  498. };
  499. return Controller;
  500. });