practice.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  178. {field: 'fault_name', title: __('更换件')},
  179. {field: 'create_by', title: __('学员姓名')},
  180. {field: 'request_status', title: __('状态'),
  181. formatter: function(value, row,index) {
  182. if(value==1){
  183. return '<span class="text-warning">待处理</span>';
  184. }else if(value==2){
  185. return '<span class="text-success">已送</span>';
  186. }else if(value==3){
  187. return '<span class="text-danger">已驳回</span>';
  188. }
  189. }
  190. },
  191. {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
  192. {field: 'operate', title: __('Operate'), table: table,
  193. events: Table.api.events.operate,
  194. // formatter: Table.api.formatter.operate
  195. formatter: Table.api.formatter.buttons,
  196. buttons: [
  197. {
  198. name: 'dispatch',
  199. text: '已送',
  200. icon: 'fa fa-check',
  201. title: '已送',
  202. classname: 'btn btn-success btn-xs btn-magic btn-ajax',
  203. url: 'teacher/exams/handle/type/1',
  204. visible: function (rr) {
  205. if(rr.request_status == 1 || rr.request_status == 0){
  206. return true;
  207. }
  208. return false;
  209. },
  210. success: function (data, ret) {
  211. table.bootstrapTable("refresh");
  212. },
  213. },{
  214. name: 'dispatch',
  215. text: '驳回',
  216. icon: 'fa fa-reply-all',
  217. title: '驳回',
  218. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  219. url: 'teacher/exams/handle/type/2',
  220. visible: function (rr) {
  221. if(rr.request_status == 1 || rr.request_status == 0){
  222. return true;
  223. }
  224. return false;
  225. },
  226. success: function (data, ret) {
  227. table.bootstrapTable("refresh");
  228. },
  229. }
  230. ],
  231. }
  232. ]
  233. ]
  234. });
  235. // 为表格绑定事件
  236. Table.api.bindevent(table);
  237. var table1 = $("#table1");
  238. // 初始化表格
  239. table1.bootstrapTable({
  240. url: $.fn.bootstrapTable.defaults.extend.indexed_url,
  241. pk: 'exam_id',
  242. sortName: 'exam_id',
  243. toolbar: '#toolbar1',
  244. fixedColumns: true,
  245. fixedRightNumber: 1,
  246. searchFormVisible:false,
  247. showExport:false,
  248. search:false,
  249. pagination:false,
  250. columns: [
  251. [
  252. // {checkbox: true},
  253. {field: 'seat_id', title: __('座号')},
  254. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  255. {field: 'sim_state', title: __('模拟器状态'),
  256. formatter: function(value, row,index) {
  257. if(value=='在线'){
  258. return '<span class="text-success">'+value+'</span>';
  259. }
  260. if(value=='离线'){
  261. return '<span class="text-danger">'+value+'</span>';
  262. }
  263. }
  264. },
  265. {field: 'user_username', title: __('学员学号')},
  266. {field: 'user_nickname', title: __('学员姓名')},
  267. {field: 'exam_status', title: __('考试状态'),
  268. formatter: function(value, row,index) {
  269. if(value=='未登录'){
  270. return '<span class="text-danger">'+value+'</span>';
  271. }else if(value=='已登录未开始考试'){
  272. return '<span class="text-warning">'+value+'</span>';
  273. }else if(value=='已开始考试'){
  274. return '<span class="text-info">'+value+'</span>';
  275. }else if(value=='已交卷'){
  276. return '<span class="text-success">'+value+'</span>';
  277. }
  278. }
  279. },
  280. {field: 'total_score', title: __('考试成绩')},
  281. {field: 'fault_names', title: __('出题题目'),formatter: Table.api.formatter.faultname},
  282. {field: 'operate', title: __('Operate'), table: table1,
  283. events: Table.api.events.operate,
  284. // formatter: Table.api.formatter.operate
  285. formatter: Table.api.formatter.buttons,
  286. buttons: [
  287. {
  288. name: 'dispatch',
  289. text: '成绩详情',
  290. icon: 'fa fa-eye',
  291. title: '成绩详情',
  292. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  293. extend: 'data-area=\'["75%","95%"]\'',
  294. visible: function (row) {
  295. if(row.total_score>0){
  296. return true;
  297. }
  298. return false;
  299. },
  300. url: 'teacher/exams/view',
  301. }
  302. ],
  303. }
  304. ]
  305. ]
  306. });
  307. // 为表格绑定事件
  308. Table.api.bindevent(table1);
  309. var table2 = $("#table2");
  310. // 初始化表格
  311. table2.bootstrapTable({
  312. url: $.fn.bootstrapTable.defaults.extend.score_url,
  313. pk: 'exam_id',
  314. sortName: 'exam_id',
  315. toolbar: '#toolbar2',
  316. fixedColumns: true,
  317. pageSize: 10,
  318. pagination:false,
  319. fixedLeftNumber: 4,
  320. searchFormVisible:false,
  321. showExport:false,
  322. search:false,
  323. columns: [
  324. [
  325. // {checkbox: true},
  326. {field: 'seat_id', title: __('座号')},
  327. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  328. {field: 'user_username', title: __('学员学号')},
  329. {field: 'user_nickname', title: __('学员姓名')},
  330. {field: 'total', title: __('考试成绩')},
  331. {field: 'fault_one_score', title: __('故障一扣分'),editable:true},
  332. {field: 'fault_two_score', title: __('故障二扣分'),editable:true},
  333. {field: 'fault_three_score', title: __('故障三扣分'),editable:true},
  334. {field: 'xianxian_score', title: __('故障现象扣分'),editable:true},
  335. {field: 'yuanyin_socre', title: __('可能原因扣分'),editable:true},
  336. {field: 'buwei_score', title: __('故障部位扣分'),editable:true},
  337. {field: 'fangfa_score', title: __('排除方法扣分'),editable:true},
  338. {field: 'overtime_score', title: __('超时扣分'),editable:true},
  339. {field: 'operate', title: __('Operate'), table: table1,
  340. events: Table.api.events.operate,
  341. // formatter: Table.api.formatter.operate
  342. formatter: Table.api.formatter.buttons,
  343. buttons: [
  344. {
  345. name: 'dispatch',
  346. text: '成绩详情',
  347. icon: 'fa fa-eye',
  348. title: '成绩详情',
  349. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  350. extend: 'data-area=\'["75%","95%"]\'',
  351. url: 'teacher/exams/view',
  352. }
  353. ],
  354. }
  355. ]
  356. ]
  357. });
  358. // 为表格绑定事件
  359. Table.api.bindevent(table2);
  360. //关闭考试 并且
  361. $(document).on('click', '.btn-closes', function () {
  362. var ids = Config.ids;
  363. Backend.api.closetabs('/admin/teacher/practice/persent/ids/'+Config.ids)
  364. // Backend.api.addtabs('teacher/practice','练习列表');
  365. // $.ajax({
  366. // type:'post',
  367. // url:'teacher/collection/multi',
  368. // data:{ids:ids,params:'exam_collection_state=3'}, //重点必须为一个变量如:data
  369. // success:function(data){
  370. // if(data.code==1){
  371. // Backend.api.closetabs('/admin/teacher/exams/persent/ids/'+Config.ids)
  372. // Backend.api.addtabs('teacher/collection','考试列表');
  373. // }
  374. // },
  375. // error:function(){
  376. // layer.alert("操作失败");
  377. // return;
  378. // }
  379. // })
  380. });
  381. $("button[name=commonSearch]").css('display','none');
  382. //定时刷新
  383. setInterval(function() {
  384. table.bootstrapTable('refresh');
  385. table1.bootstrapTable('refresh');
  386. table2.bootstrapTable('refresh');
  387. }, 30000);
  388. },
  389. add: function () {
  390. Controller.api.bindevent1();
  391. },
  392. edit: function () {
  393. Controller.api.bindevent1();
  394. },
  395. adduser: function () {
  396. Controller.api.bindevent2();
  397. },
  398. edituser: function () {
  399. Controller.api.bindevent2();
  400. },
  401. api: {
  402. bindevent1: function () {
  403. Form.api.bindevent($("form[role=form]"));
  404. },
  405. initSubTable: function (index, row, $detail,parent_table) {
  406. var admin_id = row.id;
  407. var cur_table = $detail.html('<table id="sub_'+ admin_id +'" style="background-color:#d7d1d147"></table>').find('table');
  408. var sub_table = $(cur_table);
  409. sub_table.bootstrapTable({
  410. // url: 'area/index',
  411. toolbar: false,
  412. showColumns: false,
  413. showToggle: false,
  414. showExport: false,
  415. search: false,
  416. pagination:false,
  417. commonSearch: false,
  418. sortOrder: 'ASC',
  419. checkboxHeader: false,
  420. columns: [
  421. {checkbox: true,
  422. formatter: function(value,rows,index){
  423. console.log('Config.user_ids');
  424. console.log(Config.user_ids);
  425. if(Config.user_ids.length==0){
  426. return false;
  427. }else if(Config.user_ids.indexOf(rows.id)>-1){
  428. return true;
  429. }else{
  430. return {disabled : true}
  431. }
  432. }
  433. },
  434. // {field: 'id', title: 'ID'},
  435. {field: 'username', title: __('学号')},
  436. {field: 'nickname', title: __('姓名')},
  437. ],
  438. data: row.alluser
  439. });
  440. Table.api.bindevent(sub_table);
  441. sub_table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table", function (e) {
  442. var selectedIds = Table.api.selectedids(sub_table);
  443. console.log(selectedIds);
  444. $(".xueyuan_input").val(selectedIds.length);
  445. $(".xueyuan_total").html(selectedIds.length);
  446. $(".depart_ids").val(selectedIds.join());
  447. })
  448. },
  449. bindevent2: function () {
  450. var rel_Ids = [];
  451. var qudui_total = 0;
  452. var xueyuan_total = 0;
  453. Table.api.init({
  454. extend: {
  455. index_url: 'department/admin/departadmintotal' + location.search,
  456. }
  457. });
  458. var table = $("#table1");
  459. // 初始化表格
  460. table.bootstrapTable({
  461. url: $.fn.bootstrapTable.defaults.extend.index_url,
  462. pk: 'id',
  463. sortName: 'id',
  464. fixedColumns: true,
  465. fixedRightNumber: 1,
  466. searchFormVisible:false,
  467. // pagination:false,
  468. detailView: true,//父子表
  469. Search:false,
  470. columns: [
  471. [
  472. {checkbox: true,},
  473. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  474. {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
  475. ]
  476. ],
  477. onExpandRow: function (index, row, $detail) {
  478. Controller.api.initSubTable(index, row, $detail);
  479. },
  480. onCheck: function (row, $element) {
  481. $('.btn-disabled').addClass('disabled');
  482. var id = row.id;
  483. $("#sub_" + id).bootstrapTable("checkAll");
  484. },
  485. onUncheck: function (row) {
  486. var id = row.id;
  487. $("#sub_" + id).bootstrapTable("uncheckAll");
  488. },
  489. });
  490. // 为表格绑定事件
  491. Table.api.bindevent(table);
  492. $(document).on('change', '#c-question_setting_method', function () {
  493. if($(this).val()==1){
  494. $(".btn-sm,.btn-task").css('display','none');
  495. }else if($(this).val()==2){
  496. $(".btn-sm").show();
  497. $(".btn-task").css('display','none');
  498. }else if($(this).val()==3){
  499. $(".btn-sm").css('display','none');
  500. $(".btn-task").show();
  501. }
  502. $(".question_ids").val(0);
  503. $(".task_id").val(0);
  504. $("#c-task_name").val('');
  505. $("#c-fault_name").val('');
  506. $("#c-question_name").val('');
  507. $(".tasks,.questions").css('display','none')
  508. });
  509. //考题
  510. $(document).on('click', '.btn-sm', function () {
  511. var simtype = $("#c-sim_type").val();
  512. if(!simtype){
  513. Layer.alert('请选择模拟器类型');
  514. return false
  515. }
  516. var title = '选择考题';
  517. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype), title, {
  518. area: ["85%", "85%"],
  519. maxmin: true,
  520. moveOut: false,
  521. offset: ['40px'],
  522. callback: function(value) {
  523. if (value.task_id) {
  524. $(".questions").css('display','block')
  525. $(".question_ids").val(value.task_id);
  526. $("#c-question_name").val(value.task_name);
  527. $(".tasks").css('display','none')
  528. $(".task_id").val(0);
  529. $("#c-task_name").val('');
  530. $("#c-fault_name").val('');
  531. }
  532. }
  533. });
  534. });
  535. //任务
  536. $(document).on('click', '.btn-task', function () {
  537. var simtype = $("#c-sim_type").val();
  538. if(!simtype){
  539. Layer.alert('请选择模拟器类型');
  540. return false;
  541. }
  542. var title = '选择任务';
  543. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype), title, {
  544. area: ["65%", "70%"],
  545. maxmin: true,
  546. moveOut: false,
  547. offset: ['40px'],
  548. callback: function(value) {
  549. console.log(value);
  550. if (value.task_id) {
  551. $(".tasks").css('display','block')
  552. $(".task_id").val(value.task_id);
  553. $("#c-task_name").val(value.task_name);
  554. $("#c-fault_name").val(value.fault_name);
  555. $(".questions").css('display','none')
  556. $(".question_ids").val(0);
  557. $("#c-question_name").val('');
  558. }
  559. }
  560. });
  561. });
  562. $("button[name=commonSearch]").css('display','none');
  563. $("input[name='btSelectAll']").css('display','none');
  564. Form.api.bindevent($("form[role=form]"));
  565. }
  566. }
  567. };
  568. return Controller;
  569. });