practice.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'student/practice/index' + location.search,
  8. table: 'teacher_collection',
  9. }
  10. });
  11. var table = $("#table");
  12. // 初始化表格
  13. table.bootstrapTable({
  14. url: $.fn.bootstrapTable.defaults.extend.index_url,
  15. pk: 'exam_collection_id',
  16. sortName: 'exam_collection_id',
  17. fixedColumns: true,
  18. fixedRightNumber: 1,
  19. searchFormVisible:true,
  20. columns: [
  21. [
  22. {checkbox: true},
  23. {field: 'exam_collection_id', title: __('编号')},
  24. {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  25. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  26. {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教员自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  27. // {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
  28. // return '考试';
  29. // }
  30. // },
  31. // {
  32. // field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  33. // title: __('Exam_collection_state'),
  34. // align: 'center',
  35. // table: table,disable:true,
  36. // formatter: Table.api.formatter.collectonstate
  37. // },
  38. {field: 'limit_duration', title: __('Limit_duration')},
  39. {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  40. {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  41. // {field: 'create_user_id', title: __('Create_user_id')},
  42. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  43. // {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  44. // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
  45. // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  46. // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  47. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  48. {field: 'operate', title: __('Operate'), table: table,
  49. events: Table.api.events.operate,
  50. // formatter: Table.api.formatter.operate,
  51. formatter: Table.api.formatter.buttons,
  52. buttons: [
  53. {
  54. name: 'dispatch',
  55. text: '进入',
  56. icon: 'fa fa-hand-pointer-o',
  57. title: '进入',
  58. // visible: function (row){
  59. // if(row.is_user_examed==0){
  60. // return true;
  61. // }
  62. // return false;
  63. // },
  64. classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
  65. extend: 'data-area=\'["85%","85%"]\'',
  66. url: 'student/practice/into',
  67. }
  68. ],
  69. }
  70. ]
  71. ]
  72. });
  73. // 为表格绑定事件
  74. Table.api.bindevent(table);
  75. },
  76. add: function () {
  77. Controller.api.bindevent();
  78. },
  79. into: function () {
  80. // Controller.api.bindevent();
  81. // Form.api.bindevent($("form[role=form]"), function(data, ret) {
  82. // if(ret.code==1){
  83. // Backend.api.addtabs( ret.url,'正在练习');
  84. // }
  85. // });
  86. $(document).on('click', '.btn-startexam', function () {
  87. var index = Layer.load(2, {
  88. shade: [0.5,'#393D49'],
  89. content: '正在检查模拟器并下发故障,请稍后...', // 这里是加载的文字
  90. });
  91. $(this).removeClass('btn-info');
  92. $(this).addClass('btn-primary');
  93. if(Config.is_fault){
  94. $.ajax({
  95. url: Config.url_type+"/sim/real-exam/student/exercise/start/"+Config.exam_id+"?ip="+Config.server_ip,
  96. type: 'get',
  97. success: function (data) {
  98. console.log(data);
  99. if(data.code==200){
  100. window.location.href = '/admin/student/practice/examing/ids/'+Config.exam_id;
  101. }else{
  102. Layer.alert(data.msg);
  103. Layer.close(index);
  104. return;
  105. }
  106. }
  107. });
  108. }else{
  109. window.location.href = '/admin/student/practice/examing/ids/'+Config.exam_id;
  110. }
  111. });
  112. //刷新模拟器
  113. $(document).on('click', '.btn-refreshs', function () {
  114. var index = Layer.load(2, {
  115. shade: [0.5,'#393D49'],
  116. content: '正在刷新检查模拟器,请稍后...', // 这里是加载的文字
  117. });
  118. $(this).removeClass('btn-info');
  119. $(this).addClass('btn-primary');
  120. if(Config.is_fault){
  121. $.ajax({
  122. url: Config.url_type+"/sim/real-exam/student/refresh-sim-state?userId="+Config.user_id+"&ip="+Config.server_ip,
  123. type: 'get',
  124. success: function (data) {
  125. console.log(data);
  126. if(data.code==200 && data.data.simState==2){
  127. $(".kaiguan").css('display','block');
  128. }else{
  129. $(".kaiguan").css('display','none');
  130. }
  131. $(".mnq_zt").val(data.msg)
  132. Layer.close(index);
  133. }
  134. });
  135. }else{
  136. window.location.href='';
  137. }
  138. });
  139. //载入页面单独调用一次
  140. if(Config.is_fault){
  141. var index = Layer.load(2, {
  142. shade: [0.5,'#393D49'],
  143. content: '正在刷新检查模拟器,请稍后...', // 这里是加载的文字pro
  144. });
  145. $.ajax({
  146. url: Config.url_type+"/sim/real-exam/student/refresh-sim-state?userId="+Config.user_id+"&ip="+Config.server_ip,
  147. type: 'get',
  148. success: function (data) {
  149. console.log(data);
  150. if(data.code==200 && data.data.simState==2){
  151. $(".kaiguan").css('display','block');
  152. }else{
  153. $(".kaiguan").css('display','none');
  154. }
  155. Layer.close(index);
  156. $(".mnq_zt").val(data.msg)
  157. }
  158. });
  159. }
  160. },
  161. examing: function () {
  162. var dingshi = '';
  163. $(document).ready(function() {
  164. var countdownTime = Config.timer; // 倒计时时间,单位为秒
  165. var countdownTime1 = 600; // 10分钟倒计时时间,单位为秒
  166. var display = $('#timer');
  167. var fenzhong = 0;
  168. var timer = setInterval(function() {
  169. var minutes = parseInt(countdownTime / 60, 10);
  170. var seconds = parseInt(countdownTime % 60, 10);
  171. // minutes = minutes < 10 ? "0" + minutes : minutes;
  172. // seconds = seconds < 10 ? "0" + seconds : seconds;
  173. display.text(minutes + "分" + seconds+'秒');
  174. // console.log(parseInt(minutes.replace("0-",'')));
  175. if (--countdownTime < 0) {
  176. $.ajax({
  177. url: "student/collection/countdown/ids/"+Config.ids,
  178. type: 'post',
  179. data: {},
  180. success: function (data) {
  181. if(data.code==1){
  182. console.log(data.msg);
  183. $(".djs").html(data.msg);
  184. if(data.msg==0){
  185. $('#update-form').submit();
  186. clearInterval(timer);
  187. }
  188. }
  189. if(data.code==0){
  190. Layer.alert(data.msg);
  191. }
  192. }
  193. });
  194. }
  195. }, 1000);
  196. //五秒刷新,同步更换件列表数据
  197. if(Config.isloading==1 && countdownTime>0){
  198. dingshi = setInterval(function() {
  199. window.location.reload();
  200. }, 30000);
  201. }
  202. });
  203. $(document).on('click', '.btn-replace', function () {
  204. console.log($(".other_replace").val());
  205. if($(".other_replace").val()=='[{"fault_id":"","request_status":"0"}]'){
  206. Layer.alert('请先填写更换件');
  207. return false;
  208. }
  209. $.ajax({
  210. url: "student/collection/replace/ids/"+Config.ids,
  211. type: 'post',
  212. data: {
  213. other_replace: $(".other_replace").val(),
  214. other_report: $(".other_report").val(),
  215. },
  216. success: function (data) {
  217. if(data.code==1){
  218. Layer.alert(data.msg, {
  219. btn: ['确定'], // 或者直接使用默认的确定按钮
  220. yes: function(index, layero){
  221. // 刷新页面
  222. window.location.reload();
  223. }
  224. });
  225. }
  226. if(data.code==0){
  227. Layer.alert(data.msg);
  228. }
  229. }
  230. });
  231. });
  232. //追加记录
  233. $(document).on('click', '.btn-addlog', function () {
  234. clearTimeout(dingshi);
  235. console.log(dingshi+'@@@@');
  236. var ids = Config.ids;
  237. var other_report_count = Config.other_report_count;
  238. if(other_report_count==3){
  239. Layer.alert('维修报告最多允许增加三条');
  240. return false;
  241. }
  242. Fast.api.open('student/collection/addreport/ids/'+ids, __("维修报告"), {area: ["95%", "85%"],
  243. callback:function(value){
  244. console.log(value+'@@@@');
  245. }
  246. });
  247. });
  248. //编辑记录
  249. $(document).on('click', '.btnedit', function () {
  250. clearTimeout(dingshi);
  251. var ids = Config.ids;
  252. var xh_id = $(this).attr('xh_id');
  253. Fast.api.open('student/collection/editreport/ids/'+ids+'/xh_id/'+xh_id, __("维修报告"), {area: ["95%", "85%"],
  254. callback:function(value){
  255. console.log(value+'@@@@');
  256. }
  257. });
  258. });
  259. //移除记录
  260. $(document).on('click', '.btnmove', function () {
  261. var ids = Config.ids;
  262. var xh_id = $(this).attr('xh_id');
  263. Layer.confirm(
  264. __('确定要移除此条记录吗?', ids.length),
  265. {icon:3, title: __('Warning'), shadeClose: true, btn: [__('OK'), __('Cancel')]},
  266. function (index) {
  267. var url = 'student/collection/delreport/ids/'+ids;
  268. options = {url: url, data: {xh_id: xh_id}};
  269. Fast.api.ajax(options, function (data, ret) {
  270. window.location.reload();
  271. }, function (data, ret) {
  272. var error = $(that).data("error") || $.noop;
  273. if (typeof error === 'function') {
  274. if (false === error.call(that, data, ret)) {
  275. return false;
  276. }
  277. }
  278. });
  279. Layer.close(index);
  280. }
  281. );
  282. });
  283. $(document).on('click', '.layui-layer-close1', function () {
  284. window.location.reload();
  285. });
  286. $(document).on('click', '.btn-jiaojuan', function () {
  287. // Layer.confirm(__('确定交卷?<br/>交卷后无法再修改维修报告和进行维修。'), {
  288. // icon: 3,
  289. // title: '提示'
  290. // }, function (index) {
  291. // $("#update-form").submit();
  292. // });
  293. Layer.confirm(__('确定交卷?<br/>交卷后无法再修改维修报告和进行维修。'), {
  294. icon: 3,
  295. title: '提示'
  296. }, function (index) {
  297. if(Config.is_fault){
  298. Fast.api.ajax({
  299. url: Config.url_type+"/sim/real-exam/student/exam/submit/"+Config.exam_id+"?ip="+Config.server_ip,
  300. type: 'get',
  301. }, function (data) {
  302. console.log(data);
  303. if(data.code==200){
  304. $("#update-form").submit();
  305. }else{
  306. Layer.closeAll();
  307. Layer.alert(data.msg);
  308. }
  309. });
  310. }else{
  311. $("#update-form").submit();
  312. }
  313. });
  314. });
  315. $(document).on("fa.event.appendfieldlist", "#second-fieldlist .btn-append", function (e, obj) {
  316. //绑定动态下拉组件
  317. Form.events.selectpage(obj);
  318. });
  319. Form.api.bindevent($("form[role=form]"), function(data, ret) {
  320. if(ret.code==1){
  321. Backend.api.addtabs( ret.url,'答题分析');
  322. Backend.api.closetabs('/admin/student/practice/index');
  323. }
  324. });
  325. },
  326. analysis: function () {
  327. Form.api.bindevent($("form[role=form]"), function(data, ret) {
  328. if(ret.code==1){
  329. Backend.api.addtabs( ret.url);
  330. parent.window.reload();
  331. }
  332. });
  333. },
  334. edit: function () {
  335. Controller.api.bindevent();
  336. },
  337. api: {
  338. bindevent: function () {
  339. Form.api.bindevent($("form[role=form]"));
  340. }
  341. }
  342. };
  343. return Controller;
  344. });