practice.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function ($, undefined, Backend, Table, Form,editable) {
  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/practice/index' + location.search,
  10. add_url: 'teacher/practice/add',
  11. edit_url: 'teacher/practice/edit',
  12. del_url: 'teacher/practice/del',
  13. multi_url: 'teacher/practice/multi',
  14. import_url: 'teacher/practice/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. search:false,
  28. showExport:false,
  29. showToggle:false,
  30. showColumns: false,
  31. columns: [
  32. [
  33. {checkbox: true},
  34. {field: 'exam_collection_id', title: __('编号'),operate: false},
  35. {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  36. // {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  37. // {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教员自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  38. // {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
  39. // return '训练';
  40. // }
  41. // },
  42. {
  43. field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  44. title: __('是否开启训练'),
  45. align: 'center',
  46. table: table,
  47. formatter: Table.api.formatter.collectonstate
  48. },
  49. // {field: 'task_id', title: __('Task_id')},
  50. {field: 'limit_duration', title: __('Limit_duration')},
  51. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  52. // {field: 'qudui_count', title: __('区队数量'), operate: false},
  53. {field: 'xueyuan_count', title: __('应考人数'), operate: false},
  54. {field: 'yikao_count', title: __('已考人数'), operate: false},
  55. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  56. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  57. // formatter: Table.api.formatter.operate
  58. formatter: Table.api.formatter.buttons,
  59. buttons: [
  60. {
  61. name: 'dispatch',
  62. text: '编辑',
  63. icon: 'fa fa-pencil',
  64. title: '编辑',
  65. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  66. // extend: 'data-area=\'["85%","85%"]\'',
  67. url: 'teacher/practice/edit',
  68. },
  69. {
  70. name: 'dispatch',
  71. text: '进入训练',
  72. icon: 'fa fa-hand-pointer-o',
  73. title: '进入训练',
  74. visible: function (rr) {
  75. if(rr.exam_collection_state == 2){
  76. return true;
  77. }
  78. return false;
  79. },
  80. classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
  81. url: 'teacher/practice/persent',
  82. },
  83. {
  84. name: 'dispatch',
  85. text: '查看学员',
  86. icon: 'fa fa-eye',
  87. title: '查看学员',
  88. visible: function (rr) {
  89. if(rr.user_count > 0){
  90. return true;
  91. }
  92. return false;
  93. },
  94. classname: 'btn btn-warning btn-xs btn-magic btn-dialog',
  95. extend: 'data-area=\'["85%","85%"]\'',
  96. url: 'teacher/collection/viewuser',
  97. },
  98. {
  99. name: 'dispatch',
  100. text: '添加学员',
  101. icon: 'fa fa-plus',
  102. title: '添加学员',
  103. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  104. extend: 'data-area=\'["85%","85%"]\'',
  105. url: 'teacher/practice/adduser',
  106. },
  107. {
  108. name: 'dispatch',
  109. text: '删除学员',
  110. icon: 'fa fa-pencil',
  111. title: '删除学员',
  112. visible: function (rr) {
  113. if(rr.user_count > 0){
  114. return true;
  115. }
  116. return false;
  117. },
  118. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  119. extend: 'data-area=\'["75%","75%"]\'',
  120. url: 'teacher/practice/edituser',
  121. },
  122. {
  123. name: 'dispatch',
  124. text: '删除',
  125. icon: 'fa fa-trash',
  126. title: '删除',
  127. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  128. url: 'teacher/practice/del',
  129. confirm: '确定要删除吗?',
  130. success: function (data, ret) {
  131. $(".btn-refresh").trigger("click");
  132. },
  133. error: function (data, ret) {
  134. Layer.alert(ret.msg);
  135. return false;
  136. }
  137. }
  138. ],
  139. }
  140. ]
  141. ]
  142. });
  143. // 为表格绑定事件
  144. Table.api.bindevent(table);
  145. $(document).on('click', '.btn-start', function () {
  146. var ids = Table.api.selectedids(table);
  147. Fast.api.ajax({
  148. url: "teacher/practice/start/ids/"+ids,
  149. type: "post",
  150. }, function () {
  151. table.bootstrapTable('refresh');
  152. Layer.close(index);
  153. });
  154. });
  155. },
  156. persent: function () {
  157. Table.api.init({
  158. extend: {
  159. index_url: 'teacher/practice/persent/ids/'+Config.ids + location.search,
  160. indexed_url: 'teacher/practice/examing/ids/'+ Config.ids+ location.search,
  161. score_url: 'teacher/practice/score/ids/'+Config.ids + location.search,
  162. table: 'teacher_exams',
  163. }
  164. });
  165. var table = $("#table");
  166. // 初始化表格
  167. table.bootstrapTable({
  168. url: $.fn.bootstrapTable.defaults.extend.index_url,
  169. pk: 'rel_id',
  170. sortName: 'rel_id',
  171. toolbar: '#toolbar',
  172. fixedColumns: true,
  173. fixedRightNumber: 1,
  174. searchFormVisible:false,
  175. showExport:false,
  176. search:false,
  177. showExport:false,
  178. showToggle:false,
  179. showColumns: false,
  180. columns: [
  181. [
  182. // {checkbox: true},
  183. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  184. {field: 'fault_name', title: __('更换件')},
  185. {field: 'create_by', title: __('学员姓名')},
  186. {field: 'request_status', title: __('状态'),
  187. formatter: function(value, row,index) {
  188. if(value==1){
  189. return '<span class="text-warning">待处理</span>';
  190. }else if(value==2){
  191. return '<span class="text-success">已送</span>';
  192. }else if(value==3){
  193. return '<span class="text-danger">已驳回</span>';
  194. }
  195. }
  196. },
  197. {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
  198. {field: 'operate', title: __('Operate'), table: table,
  199. events: Table.api.events.operate,
  200. // formatter: Table.api.formatter.operate
  201. formatter: Table.api.formatter.buttons,
  202. buttons: [
  203. {
  204. name: 'dispatch',
  205. text: '已送',
  206. icon: 'fa fa-check',
  207. title: '已送',
  208. classname: 'btn btn-success btn-xs btn-magic btn-ajax',
  209. url: 'teacher/exams/handle/type/1',
  210. visible: function (rr) {
  211. if(rr.request_status == 1 || rr.request_status == 0){
  212. return true;
  213. }
  214. return false;
  215. },
  216. success: function (data, ret) {
  217. table.bootstrapTable("refresh");
  218. },
  219. },{
  220. name: 'dispatch',
  221. text: '驳回',
  222. icon: 'fa fa-reply-all',
  223. title: '驳回',
  224. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  225. url: 'teacher/exams/handle/type/2',
  226. visible: function (rr) {
  227. if(rr.request_status == 1 || rr.request_status == 0){
  228. return true;
  229. }
  230. return false;
  231. },
  232. success: function (data, ret) {
  233. table.bootstrapTable("refresh");
  234. },
  235. }
  236. ],
  237. }
  238. ]
  239. ]
  240. });
  241. // 为表格绑定事件
  242. Table.api.bindevent(table);
  243. var table1 = $("#table1");
  244. // 初始化表格
  245. table1.bootstrapTable({
  246. url: $.fn.bootstrapTable.defaults.extend.indexed_url,
  247. pk: 'exam_id',
  248. sortName: 'exam_id',
  249. toolbar: '#toolbar1',
  250. fixedColumns: true,
  251. fixedRightNumber: 1,
  252. searchFormVisible:false,
  253. showExport:false,
  254. search:false,
  255. pagination:false,
  256. showExport:false,
  257. showToggle:false,
  258. showColumns: false,
  259. columns: [
  260. [
  261. // {checkbox: true},
  262. {field: 'seat_id', title: __('座号')},
  263. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  264. {field: 'sim_state', title: __('模拟器状态'),
  265. formatter: function(value, row,index) {
  266. // if(value=='在线'){
  267. // return '<span class="text-success">'+value+'</span>';
  268. // }
  269. // if(value=='离线'){
  270. // return '<span class="text-danger">'+value+'</span>';
  271. // }
  272. return '<span class="text-success">'+value+'</span>';
  273. }
  274. },
  275. {field: 'user_username', title: __('学员学号')},
  276. {field: 'user_nickname', title: __('学员姓名')},
  277. {field: 'exam_status', title: __('考试状态'),
  278. formatter: function(value, row,index) {
  279. if(value=='未登录'){
  280. return '<span class="text-danger">'+value+'</span>';
  281. }else if(value=='已登录未开始考试'){
  282. return '<span class="text-warning">'+value+'</span>';
  283. }else if(value=='已开始考试'){
  284. return '<span class="text-info">'+value+'</span>';
  285. }else if(value=='已交卷'){
  286. return '<span class="text-success">'+value+'</span>';
  287. }
  288. }
  289. },
  290. {field: 'total_score', title: __('考试成绩')},
  291. {field: 'fault_names', title: __('出题题目'),formatter: Table.api.formatter.faultname},
  292. {field: 'operate', title: __('Operate'), table: table1,
  293. events: Table.api.events.operate,
  294. // formatter: Table.api.formatter.operate
  295. formatter: Table.api.formatter.buttons,
  296. buttons: [
  297. {
  298. name: 'dispatch',
  299. text: '成绩详情',
  300. icon: 'fa fa-eye',
  301. title: '成绩详情',
  302. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  303. extend: 'data-area=\'["75%","95%"]\'',
  304. visible: function (row) {
  305. if(row.total_score>0){
  306. return true;
  307. }
  308. return false;
  309. },
  310. url: 'teacher/exams/view',
  311. }
  312. ],
  313. }
  314. ]
  315. ]
  316. });
  317. // 为表格绑定事件
  318. Table.api.bindevent(table1);
  319. var table2 = $("#table2");
  320. // 初始化表格
  321. table2.bootstrapTable({
  322. url: $.fn.bootstrapTable.defaults.extend.score_url,
  323. pk: 'exam_id',
  324. sortName: 'exam_id',
  325. toolbar: '#toolbar2',
  326. fixedColumns: true,
  327. pageSize: 10,
  328. pagination:false,
  329. fixedLeftNumber: 4,
  330. searchFormVisible:false,
  331. showExport:false,
  332. search:false,
  333. showExport:false,
  334. showToggle:false,
  335. showColumns: false,
  336. columns: [
  337. [
  338. // {checkbox: true},
  339. {field: 'seat_id', title: __('座号')},
  340. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  341. {field: 'user_username', title: __('学员学号')},
  342. {field: 'user_nickname', title: __('学员姓名')},
  343. {field: 'total', title: __('考试成绩')},
  344. {field: 'fault_one_score', title: __('故障一扣分'),editable:true},
  345. {field: 'fault_two_score', title: __('故障二扣分'),editable:true},
  346. {field: 'fault_three_score', title: __('故障三扣分'),editable:true},
  347. {field: 'xianxian_score', title: __('故障现象扣分'),editable:true},
  348. {field: 'yuanyin_socre', title: __('可能原因扣分'),editable:true},
  349. {field: 'buwei_score', title: __('故障部位扣分'),editable:true},
  350. {field: 'fangfa_score', title: __('排除方法扣分'),editable:true},
  351. {field: 'overtime_score', title: __('超时扣分'),editable:true},
  352. {field: 'operate', title: __('Operate'), table: table1,
  353. events: Table.api.events.operate,
  354. // formatter: Table.api.formatter.operate
  355. formatter: Table.api.formatter.buttons,
  356. buttons: [
  357. {
  358. name: 'dispatch',
  359. text: '成绩详情',
  360. icon: 'fa fa-eye',
  361. title: '成绩详情',
  362. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  363. extend: 'data-area=\'["75%","95%"]\'',
  364. url: 'teacher/exams/view',
  365. }
  366. ],
  367. }
  368. ]
  369. ]
  370. });
  371. // 为表格绑定事件
  372. Table.api.bindevent(table2);
  373. //关闭考试 并且
  374. $(document).on('click', '.btn-closes', function () {
  375. var ids = Config.ids;
  376. Backend.api.closetabs('/admin/teacher/practice/persent/ids/'+Config.ids)
  377. // Backend.api.addtabs('teacher/practice','训练列表');
  378. // $.ajax({
  379. // type:'post',
  380. // url:'teacher/collection/multi',
  381. // data:{ids:ids,params:'exam_collection_state=3'}, //重点必须为一个变量如:data
  382. // success:function(data){
  383. // if(data.code==1){
  384. // Backend.api.closetabs('/admin/teacher/exams/persent/ids/'+Config.ids)
  385. // Backend.api.addtabs('teacher/collection','考试列表');
  386. // }
  387. // },
  388. // error:function(){
  389. // layer.alert("操作失败");
  390. // return;
  391. // }
  392. // })
  393. });
  394. $("button[name=commonSearch]").css('display','none');
  395. //定时刷新
  396. setInterval(function() {
  397. table.bootstrapTable('refresh');
  398. table1.bootstrapTable('refresh');
  399. table2.bootstrapTable('refresh');
  400. }, 30000);
  401. },
  402. add: function () {
  403. Controller.api.bindevent1();
  404. },
  405. edit: function () {
  406. Controller.api.bindevent1();
  407. },
  408. adduser: function () {
  409. Controller.api.bindevent2();
  410. },
  411. edituser: function () {
  412. Controller.api.bindevent2();
  413. },
  414. api: {
  415. bindevent1: function () {
  416. Form.api.bindevent($("form[role=form]"));
  417. },
  418. initSubTable: function (index, row, $detail,parent_table) {
  419. var admin_id = row.id;
  420. var cur_table = $detail.html('<table id="sub_'+ admin_id +'" style="background-color:#d7d1d147"></table>').find('table');
  421. var sub_table = $(cur_table);
  422. sub_table.bootstrapTable({
  423. // url: 'area/index',
  424. toolbar: false,
  425. showColumns: false,
  426. showToggle: false,
  427. showExport: false,
  428. search: false,
  429. pagination:false,
  430. commonSearch: false,
  431. sortOrder: 'ASC',
  432. checkboxHeader: false,
  433. columns: [
  434. {checkbox: true,
  435. formatter: function(value,rows,index){
  436. // console.log('Config.user_ids');
  437. // console.log(Config.user_ids);
  438. if(Config.user_ids.length==0){
  439. return false;
  440. }else if(Config.user_ids.indexOf(rows.id)>-1){
  441. return true;
  442. }else{
  443. return {disabled : true}
  444. }
  445. }
  446. },
  447. // {field: 'id', title: 'ID'},
  448. {field: 'username', title: __('学号')},
  449. {field: 'nickname', title: __('姓名')},
  450. ],
  451. data: row.alluser
  452. });
  453. Table.api.bindevent(sub_table);
  454. sub_table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table", function (e) {
  455. var selectedIds = Table.api.selectedids(sub_table);
  456. console.log(selectedIds+'@@@@');
  457. $(".xueyuan_input").val(selectedIds.length);
  458. $(".xueyuan_total").html(selectedIds.length);
  459. $(".depart_ids").val(selectedIds.join());
  460. })
  461. },
  462. bindevent2: function () {
  463. var rel_Ids = [];
  464. var qudui_total = 0;
  465. var xueyuan_total = 0;
  466. Table.api.init({
  467. extend: {
  468. index_url: 'department/admin/departadmintotal' + location.search,
  469. }
  470. });
  471. var table = $("#table1");//当内容渲染完成后展开详细
  472. table.on('post-body.bs.table', function (e, data) {
  473. $('#table1').bootstrapTable('expandAllRows');
  474. });
  475. // 初始化表格
  476. table.bootstrapTable({
  477. url: $.fn.bootstrapTable.defaults.extend.index_url,
  478. pk: 'id',
  479. sortName: 'id',
  480. fixedColumns: true,
  481. fixedRightNumber: 1,
  482. searchFormVisible:false,
  483. // pagination:false,
  484. detailView: true,//父子表
  485. Search:false,
  486. showExport:false,
  487. showToggle:false,
  488. showColumns: false,
  489. columns: [
  490. [
  491. {checkbox: true,},
  492. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  493. {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
  494. ]
  495. ],
  496. onExpandRow: function (index, row, $detail) {
  497. Controller.api.initSubTable(index, row, $detail);
  498. },
  499. onCheck: function (row, $element) {
  500. $('.btn-disabled').addClass('disabled');
  501. var id = row.id;
  502. $("#sub_" + id).bootstrapTable("checkAll");
  503. },
  504. onUncheck: function (row) {
  505. var id = row.id;
  506. $("#sub_" + id).bootstrapTable("uncheckAll");
  507. },
  508. });
  509. // 为表格绑定事件
  510. Table.api.bindevent(table);
  511. $(document).on('change', '#c-question_setting_method', function () {
  512. if($(this).val()==1){
  513. $(".btn-sm,.btn-task").css('display','none');
  514. $(".fault_total").css('display','block');
  515. $('form[role=form]').validator("setField", {
  516. "row[fault_total]": "required",
  517. });
  518. }else if($(this).val()==2){
  519. $(".btn-sm").show();
  520. $(".btn-task,.fault_total").css('display','none');
  521. $('form[role=form]').validator("setField", {
  522. "row[fault_total]":null,
  523. });
  524. }else if($(this).val()==3){
  525. $(".btn-sm,.fault_total").css('display','none');
  526. $('form[role=form]').validator("setField", {
  527. "row[fault_total]": null,
  528. });
  529. $(".btn-task").show();
  530. }
  531. $(".question_ids").val(0);
  532. $(".task_id").val(0);
  533. $("#c-task_name").val('');
  534. $("#c-fault_name").val('');
  535. $("#c-question_name").val('');
  536. $(".tasks,.questions").css('display','none');
  537. });
  538. //考题
  539. $(document).on('click', '.btn-sm', function () {
  540. var simtype = $("#c-sim_type").val();
  541. if(!simtype){
  542. Layer.alert('请选择模拟器类型');
  543. return false
  544. }
  545. var examid = $(".examid").val();
  546. var title = '选择考题';
  547. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype+"/ids/"+examid), title, {
  548. area: ["85%", "85%"],
  549. maxmin: true,
  550. moveOut: false,
  551. offset: ['40px'],
  552. callback: function(value) {
  553. if (value.task_id) {
  554. $(".questions").css('display','block')
  555. $(".question_ids").val(value.task_id);
  556. $("#c-question_name").val(value.task_name);
  557. $(".tasks").css('display','none')
  558. $(".task_id").val(0);
  559. $("#c-task_name").val('');
  560. $("#c-fault_name").val('');
  561. }
  562. }
  563. });
  564. });
  565. //任务
  566. $(document).on('click', '.btn-task', function () {
  567. var simtype = $("#c-sim_type").val();
  568. if(!simtype){
  569. Layer.alert('请选择模拟器类型');
  570. return false;
  571. }
  572. var examid = $(".examid").val();
  573. var title = '选择任务';
  574. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype+"/ids/"+examid), title, {
  575. area: ["65%", "70%"],
  576. maxmin: true,
  577. moveOut: false,
  578. offset: ['40px'],
  579. callback: function(value) {
  580. console.log(value);
  581. if (value.task_id) {
  582. $(".tasks").css('display','block')
  583. $(".task_id").val(value.task_id);
  584. $("#c-task_name").val(value.task_name);
  585. $("#c-fault_name").val(value.fault_name);
  586. $(".questions").css('display','none')
  587. $(".question_ids").val(0);
  588. $("#c-question_name").val('');
  589. }
  590. }
  591. });
  592. });
  593. $("button[name=commonSearch]").css('display','none');
  594. $("input[name='btSelectAll']").css('display','none');
  595. Form.api.bindevent($("form[role=form]"));
  596. }
  597. }
  598. };
  599. return Controller;
  600. });