practice.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  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. table: 'teacher_exams',
  126. }
  127. });
  128. var table = $("#table");
  129. // 初始化表格
  130. table.bootstrapTable({
  131. url: $.fn.bootstrapTable.defaults.extend.index_url,
  132. pk: 'rel_id',
  133. sortName: 'rel_id',
  134. toolbar: '#toolbar',
  135. fixedColumns: true,
  136. fixedRightNumber: 1,
  137. searchFormVisible:false,
  138. showExport:false,
  139. search:false,
  140. columns: [
  141. [
  142. // {checkbox: true},
  143. {field: 'fault_name', title: __('更换件')},
  144. {field: 'create_by', title: __('学员姓名')},
  145. {field: 'request_status', title: __('状态'),
  146. formatter: function(value, row,index) {
  147. if(value==1){
  148. return '<span class="text-warning">待处理</span>';
  149. }else if(value==2){
  150. return '<span class="text-success">已送</span>';
  151. }else if(value==3){
  152. return '<span class="text-danger">已驳回</span>';
  153. }
  154. }
  155. },
  156. {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
  157. {field: 'operate', title: __('Operate'), table: table,
  158. events: Table.api.events.operate,
  159. // formatter: Table.api.formatter.operate
  160. formatter: Table.api.formatter.buttons,
  161. buttons: [
  162. {
  163. name: 'dispatch',
  164. text: '已送',
  165. icon: 'fa fa-check',
  166. title: '已送',
  167. classname: 'btn btn-success btn-xs btn-magic btn-ajax',
  168. url: 'teacher/exams/handle/type/1',
  169. visible: function (rr) {
  170. if(rr.request_status == 1 || rr.request_status == 0){
  171. return true;
  172. }
  173. return false;
  174. },
  175. success: function (data, ret) {
  176. table.bootstrapTable("refresh");
  177. },
  178. },{
  179. name: 'dispatch',
  180. text: '驳回',
  181. icon: 'fa fa-reply-all',
  182. title: '驳回',
  183. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  184. url: 'teacher/exams/handle/type/2',
  185. visible: function (rr) {
  186. if(rr.request_status == 1 || rr.request_status == 0){
  187. return true;
  188. }
  189. return false;
  190. },
  191. success: function (data, ret) {
  192. table.bootstrapTable("refresh");
  193. },
  194. }
  195. ],
  196. }
  197. ]
  198. ]
  199. });
  200. // 为表格绑定事件
  201. Table.api.bindevent(table);
  202. var table1 = $("#table1");
  203. // 初始化表格
  204. table1.bootstrapTable({
  205. url: $.fn.bootstrapTable.defaults.extend.indexed_url,
  206. pk: 'exam_collection_id',
  207. sortName: 'exam_collection_id',
  208. toolbar: '#toolbar1',
  209. fixedColumns: true,
  210. fixedRightNumber: 1,
  211. searchFormVisible:false,
  212. columns: [
  213. [
  214. // {checkbox: true},
  215. {field: 'seat_id', title: __('座号')},
  216. {field: '', title: __('模拟器状态'),
  217. formatter: function(value, row,index) {
  218. return '<span class="text-success">就绪</span>';
  219. }
  220. },
  221. {field: 'user_username', title: __('学员学号')},
  222. {field: 'user_nickname', title: __('学员姓名')},
  223. {field: '', title: __('考试状态'),
  224. formatter: function(value, row,index) {
  225. return '<span class="text-success">已交卷</span>';
  226. }
  227. },
  228. {field: 'total_score', title: __('考试成绩')},
  229. // {field: 'fault_names', title: __('出题题目'),formatter: Table.api.formatter.faultname},
  230. // {field: 'xianxiang_names', title: __('故障现象'),formatter: Table.api.formatter.faultname},
  231. // {field: 'yuanyin_names', title: __('可能原因'),formatter: Table.api.formatter.faultname},
  232. // {field: 'buwei_names', title: __('故障部位'),formatter: Table.api.formatter.faultname},
  233. // {field: 'fangfa_names', title: __('排除方法'),formatter: Table.api.formatter.faultname},
  234. ]
  235. ]
  236. });
  237. // 为表格绑定事件
  238. Table.api.bindevent(table1);
  239. //关闭考试 并且
  240. $(document).on('click', '.btn-closes', function () {
  241. var ids = Config.ids;
  242. Backend.api.closetabs('/admin/teacher/practice/persent/ids/'+Config.ids)
  243. // Backend.api.addtabs('teacher/practice','练习列表');
  244. // $.ajax({
  245. // type:'post',
  246. // url:'teacher/collection/multi',
  247. // data:{ids:ids,params:'exam_collection_state=3'}, //重点必须为一个变量如:data
  248. // success:function(data){
  249. // if(data.code==1){
  250. // Backend.api.closetabs('/admin/teacher/exams/persent/ids/'+Config.ids)
  251. // Backend.api.addtabs('teacher/collection','考试列表');
  252. // }
  253. // },
  254. // error:function(){
  255. // layer.alert("操作失败");
  256. // return;
  257. // }
  258. // })
  259. });
  260. },
  261. add: function () {
  262. Controller.api.bindevent();
  263. },
  264. edit: function () {
  265. Controller.api.bindevent();
  266. },
  267. api: {
  268. bindevent: function () {
  269. var rel_Ids = [];
  270. var qudui_total = 0;
  271. var xueyuan_total = 0;
  272. Table.api.init({
  273. extend: {
  274. index_url: 'department/admin/departadmintotal' + location.search,
  275. }
  276. });
  277. var table = $("#table1");
  278. // 初始化表格
  279. table.bootstrapTable({
  280. url: $.fn.bootstrapTable.defaults.extend.index_url,
  281. pk: 'id',
  282. sortName: 'id',
  283. fixedColumns: true,
  284. fixedRightNumber: 1,
  285. searchFormVisible:false,
  286. pagination:false,
  287. Search:false,
  288. columns: [
  289. [
  290. {checkbox: true,
  291. formatter: function(value,row,index){
  292. // console.log(row.id+'####'+Config.row_info.depart_ids)
  293. if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
  294. rel_Ids.push(row.id);
  295. return true;
  296. }
  297. return false;
  298. }
  299. },
  300. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  301. {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
  302. ]
  303. ],
  304. onLoadSuccess: function(data) {
  305. $.each(data.rows, function(index, row) {
  306. if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
  307. qudui_total = qudui_total+1;
  308. xueyuan_total = xueyuan_total+row.department_admin_count;
  309. }
  310. });
  311. $(".qudui_total").html(qudui_total);
  312. $(".xueyuan_total").html(xueyuan_total);
  313. $(".qudui_input").val(qudui_total);
  314. $(".xueyuan_input").val(xueyuan_total);
  315. },
  316. // 点击每一个单选框时触发的操作
  317. onCheck:function(row){
  318. rel_Ids.push(row.id);
  319. qudui_total = qudui_total+1;
  320. xueyuan_total = xueyuan_total+row.department_admin_count;
  321. $(".depart_ids").val(rel_Ids.join());
  322. $(".qudui_total").html(qudui_total);
  323. $(".xueyuan_total").html(xueyuan_total);
  324. $(".qudui_input").val(qudui_total);
  325. $(".xueyuan_input").val(xueyuan_total);
  326. },
  327. // 取消每一个单选框时对应的操作;
  328. onUncheck:function(row){
  329. var index = rel_Ids.indexOf(row.id);
  330. if(index > -1) {
  331. rel_Ids.splice(index, 1);
  332. }
  333. qudui_total = qudui_total-1;
  334. xueyuan_total = xueyuan_total-row.department_admin_count;
  335. $(".depart_ids").val(rel_Ids.join());
  336. $(".qudui_total").html(qudui_total);
  337. $(".xueyuan_total").html(xueyuan_total);
  338. $(".qudui_input").val(qudui_total);
  339. $(".xueyuan_input").val(xueyuan_total);
  340. }
  341. });
  342. // 为表格绑定事件
  343. Table.api.bindevent(table);
  344. // table.on('click-row.bs.table', function (e, row, element) {
  345. // console.log(rel_Ids)
  346. // // console.log('row')
  347. // if(!$.inArray(row.id,rel_Ids)){
  348. // if(Config.row_info.starttime>0){
  349. // Layer.alert('考试正在进行中,只可增加区队不可取消区队');
  350. // return false;
  351. // }
  352. // arr = $.grep(rel_Ids, function(value) {
  353. // return value != row["id"];
  354. // });
  355. // rel_Ids = arr;
  356. // qudui_total = qudui_total-1;
  357. // xueyuan_total = xueyuan_total-row.department_admin_count;
  358. // }else if(rel_Ids.indexOf(row.id)>-1){
  359. // if(Config.row_info.starttime>0){
  360. // Layer.alert('考试正在进行中,只可增加区队不可取消区队');
  361. // return false;
  362. // }
  363. // var index = rel_Ids.indexOf(row.id);
  364. // if(index > -1) {
  365. // rel_Ids.splice(index, 1);
  366. // }
  367. // qudui_total = qudui_total-1;
  368. // xueyuan_total = xueyuan_total-row.department_admin_count;
  369. // }else{
  370. // qudui_total = qudui_total+1;
  371. // xueyuan_total = xueyuan_total+row.department_admin_count;
  372. // rel_Ids.push(row.id);
  373. // }
  374. // console.log(qudui_total);
  375. // console.log(xueyuan_total);
  376. // $(".depart_ids").val(rel_Ids.join());
  377. // $(".qudui_total").html(qudui_total);
  378. // $(".xueyuan_total").html(xueyuan_total);
  379. // $(".qudui_input").val(qudui_total);
  380. // $(".xueyuan_input").val(xueyuan_total);
  381. // });
  382. $(document).on('change', '#c-question_setting_method', function () {
  383. if($(this).val()==1){
  384. $(".btn-sm,.btn-task").css('display','none');
  385. }else if($(this).val()==2){
  386. $(".btn-sm").show();
  387. $(".btn-task").css('display','none');
  388. }else if($(this).val()==3){
  389. $(".btn-sm").css('display','none');
  390. $(".btn-task").show();
  391. }
  392. $(".question_ids").val(0);
  393. $(".task_id").val(0);
  394. $("#c-task_name").val('');
  395. $("#c-fault_name").val('');
  396. $("#c-question_name").val('');
  397. $(".tasks,.questions").css('display','none')
  398. });
  399. //考题
  400. $(document).on('click', '.btn-sm', function () {
  401. var simtype = $("#c-sim_type").val();
  402. if(!simtype){
  403. Layer.alert('请选择模拟器类型');
  404. return false
  405. }
  406. var title = '选择考题';
  407. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype), title, {
  408. area: ["85%", "85%"],
  409. maxmin: true,
  410. moveOut: false,
  411. offset: ['40px'],
  412. callback: function(value) {
  413. if (value.task_id) {
  414. $(".questions").css('display','block')
  415. $(".question_ids").val(value.task_id);
  416. $("#c-question_name").val(value.task_name);
  417. $(".tasks").css('display','none')
  418. $(".task_id").val(0);
  419. $("#c-task_name").val('');
  420. $("#c-fault_name").val('');
  421. }
  422. }
  423. });
  424. });
  425. //任务
  426. $(document).on('click', '.btn-task', function () {
  427. var simtype = $("#c-sim_type").val();
  428. if(!simtype){
  429. Layer.alert('请选择模拟器类型');
  430. return false;
  431. }
  432. var title = '选择任务';
  433. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype), title, {
  434. area: ["65%", "70%"],
  435. maxmin: true,
  436. moveOut: false,
  437. offset: ['40px'],
  438. callback: function(value) {
  439. console.log(value);
  440. if (value.task_id) {
  441. $(".tasks").css('display','block')
  442. $(".task_id").val(value.task_id);
  443. $("#c-task_name").val(value.task_name);
  444. $("#c-fault_name").val(value.fault_name);
  445. $(".questions").css('display','none')
  446. $(".question_ids").val(0);
  447. $("#c-question_name").val('');
  448. }
  449. }
  450. });
  451. });
  452. // $("input[name='btSelectAll']").click(function () {
  453. // var ids = Table.api.selectedids(table);
  454. // console.log(ids);
  455. // $(".depart_ids").val(ids);
  456. // });
  457. $("button[name=commonSearch]").css('display','none');
  458. $("input[name='btSelectAll']").css('display','none');
  459. Form.api.bindevent($("form[role=form]"));
  460. }
  461. }
  462. };
  463. return Controller;
  464. });