practice.js 29 KB

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