practice.js 29 KB

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