practice.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. columns: [
  28. [
  29. {checkbox: true},
  30. {field: 'exam_collection_id', title: __('编号'),operate: false},
  31. {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  32. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  33. {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教师自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  34. // {field: 'exam_collection_type', title: __('Exam_collection_type'),operate: false,formatter: function (value, row, index) {
  35. // return '练习';
  36. // }
  37. // },
  38. {
  39. field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  40. title: __('是否开启练习'),
  41. align: 'center',
  42. table: table,
  43. formatter: Table.api.formatter.collectonstate
  44. },
  45. // {field: 'task_id', title: __('Task_id')},
  46. {field: 'limit_duration', title: __('Limit_duration')},
  47. // {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  48. // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  49. // {field: 'create_user_id', title: __('Create_user_id')},
  50. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  51. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  52. // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
  53. // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  54. // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  55. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  56. // formatter: Table.api.formatter.operate
  57. formatter: Table.api.formatter.buttons,
  58. buttons: [
  59. {
  60. name: 'dispatch',
  61. text: '',
  62. icon: 'fa fa-pencil',
  63. title: '编辑',
  64. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  65. extend: 'data-area=\'["85%","85%"]\'',
  66. url: 'teacher/practice/edit',
  67. },
  68. {
  69. name: 'dispatch',
  70. text: '',
  71. icon: 'fa fa-hand-pointer-o',
  72. title: '进入练习',
  73. visible: function (rr) {
  74. if(rr.exam_collection_state == 2){
  75. return true;
  76. }
  77. return false;
  78. },
  79. classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
  80. url: 'teacher/practice/persent',
  81. },
  82. // {
  83. // name: 'dispatch',
  84. // text: '',
  85. // icon: 'fa fa-trash',
  86. // title: '删除',
  87. // classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  88. // url: 'teacher/practice/del',
  89. // confirm: '确定要删除吗?',
  90. // success: function (data, ret) {
  91. // $(".btn-refresh").trigger("click");
  92. // },
  93. // error: function (data, ret) {
  94. // Layer.alert(ret.msg);
  95. // return false;
  96. // }
  97. // }
  98. ],
  99. }
  100. ]
  101. ]
  102. });
  103. // 为表格绑定事件
  104. Table.api.bindevent(table);
  105. $(document).on('click', '.btn-start', function () {
  106. var ids = Table.api.selectedids(table);
  107. Fast.api.ajax({
  108. url: "teacher/practice/start/ids/"+ids,
  109. type: "post",
  110. }, function () {
  111. table.bootstrapTable('refresh');
  112. Layer.close(index);
  113. });
  114. });
  115. },
  116. persent: function () {
  117. Table.api.init({
  118. extend: {
  119. index_url: 'teacher/practice/persent' + location.search,
  120. indexed_url: 'teacher/practice/examing' + location.search,
  121. table: 'teacher_exams',
  122. }
  123. });
  124. var table = $("#table");
  125. // 初始化表格
  126. table.bootstrapTable({
  127. url: $.fn.bootstrapTable.defaults.extend.index_url,
  128. pk: 'exam_id',
  129. sortName: 'exam_id',
  130. toolbar: '#toolbar',
  131. fixedColumns: true,
  132. fixedRightNumber: 1,
  133. searchFormVisible:false,
  134. showExport:false,
  135. search:false,
  136. columns: [
  137. [
  138. // {checkbox: true},
  139. {field: 'fault_name', title: __('更换件')},
  140. {field: 'create_by', title: __('学员姓名')},
  141. {field: 'request_status', title: __('状态'),
  142. formatter: function(value, row,index) {
  143. if(value==1){
  144. return '<span class="text-warning">待处理</span>';
  145. }else if(value==2){
  146. return '<span class="text-success">已送</span>';
  147. }else if(value==3){
  148. return '<span class="text-danger">已驳回</span>';
  149. }
  150. }
  151. },
  152. {field: 'createtime', title: __('申请时间'), formatter: Table.api.formatter.datetime, operate: false, addclass: 'datetimerange', sortable: true},
  153. {field: 'operate', title: __('Operate'), table: table,
  154. events: Table.api.events.operate,
  155. // formatter: Table.api.formatter.operate
  156. formatter: Table.api.formatter.buttons,
  157. buttons: [
  158. {
  159. name: 'dispatch',
  160. text: '',
  161. icon: 'fa fa-check',
  162. title: '已送',
  163. classname: 'btn btn-success btn-xs btn-magic btn-ajax',
  164. url: 'teacher/exams/handle/type/1',
  165. visible: function (rr) {
  166. if(rr.request_status == 1 || rr.request_status == 0){
  167. return true;
  168. }
  169. return false;
  170. },
  171. success: function (data, ret) {
  172. table.bootstrapTable("refresh");
  173. },
  174. },{
  175. name: 'dispatch',
  176. text: '',
  177. icon: 'fa fa-reply-all',
  178. title: '驳回',
  179. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  180. url: 'teacher/exams/handle/type/2',
  181. visible: function (rr) {
  182. if(rr.request_status == 1 || rr.request_status == 0){
  183. return true;
  184. }
  185. return false;
  186. },
  187. success: function (data, ret) {
  188. table.bootstrapTable("refresh");
  189. },
  190. }
  191. ],
  192. }
  193. ]
  194. ]
  195. });
  196. // 为表格绑定事件
  197. Table.api.bindevent(table);
  198. var table1 = $("#table1");
  199. // 初始化表格
  200. table1.bootstrapTable({
  201. url: $.fn.bootstrapTable.defaults.extend.indexed_url,
  202. pk: 'exam_collection_id',
  203. sortName: 'exam_collection_id',
  204. toolbar: '#toolbar1',
  205. fixedColumns: true,
  206. fixedRightNumber: 1,
  207. searchFormVisible:false,
  208. columns: [
  209. [
  210. // {checkbox: true},
  211. {field: 'seat_id', title: __('座号')},
  212. {field: '', title: __('模拟器状态'),
  213. formatter: function(value, row,index) {
  214. return '<span class="text-success">就绪</span>';
  215. }
  216. },
  217. {field: 'user_username', title: __('学员学号')},
  218. {field: 'user_nickname', title: __('学员姓名')},
  219. {field: '', title: __('状态'),
  220. formatter: function(value, row,index) {
  221. return '<span class="text-success">已交卷</span>';
  222. }
  223. },
  224. {field: 'total_score', title: __('模拟成绩')},
  225. ]
  226. ]
  227. });
  228. // 为表格绑定事件
  229. Table.api.bindevent(table1);
  230. },
  231. add: function () {
  232. Controller.api.bindevent();
  233. },
  234. edit: function () {
  235. Controller.api.bindevent();
  236. },
  237. api: {
  238. bindevent: function () {
  239. var rel_Ids = [];
  240. Table.api.init({
  241. extend: {
  242. index_url: 'department/admin/departadmintotal' + location.search,
  243. }
  244. });
  245. var table = $("#table1");
  246. // 初始化表格
  247. table.bootstrapTable({
  248. url: $.fn.bootstrapTable.defaults.extend.index_url,
  249. pk: 'id',
  250. sortName: 'id',
  251. fixedColumns: true,
  252. fixedRightNumber: 1,
  253. searchFormVisible:false,
  254. Search:false,
  255. columns: [
  256. [
  257. {checkbox: true,
  258. formatter: function(value,row,index){
  259. // console.log(row.id+'####'+Config.row_info.depart_ids)
  260. if(Config.row_info != undefined && Config.row_info.depart_ids.indexOf(row.id)>-1){
  261. rel_Ids.push(row.id);
  262. return true;
  263. }
  264. return false;
  265. }
  266. },
  267. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  268. {field: 'department_admin_count', title: __('全部人员数量'),operate: false},
  269. ]
  270. ]
  271. });
  272. // 为表格绑定事件
  273. Table.api.bindevent(table);
  274. table.on('click-row.bs.table', function (e, row, element) {
  275. console.log(rel_Ids)
  276. // console.log('row')
  277. if(!$.inArray(row.id,rel_Ids)){
  278. arr = $.grep(rel_Ids, function(value) {
  279. return value != row["id"];
  280. });
  281. rel_Ids = arr;
  282. }else if(rel_Ids.indexOf(row.id)>-1){
  283. var index = rel_Ids.indexOf(row.id);
  284. if (index > -1) {
  285. rel_Ids.splice(index, 1);
  286. }
  287. }else{
  288. rel_Ids.push(row.id);
  289. }
  290. $(".depart_ids").val(rel_Ids.join());
  291. });
  292. $(document).on('change', '#c-question_setting_method', function () {
  293. if($(this).val()==1){
  294. $(".btn-sm,.btn-task").css('display','none');
  295. }else if($(this).val()==2){
  296. $(".btn-sm").css('display','block');
  297. $(".btn-task").css('display','none');
  298. }else if($(this).val()==3){
  299. $(".btn-sm").css('display','none');
  300. $(".btn-task").css('display','block');
  301. }
  302. $(".question_ids").val(0);
  303. });
  304. //考题
  305. $(document).on('click', '.btn-sm', function () {
  306. var simtype = $("#c-sim_type").val();
  307. if(!simtype){
  308. Layer.alert('请选择模拟器类型');
  309. return false
  310. }
  311. var title = '选择考题';
  312. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype), title, {
  313. area: ["85%", "85%"],
  314. maxmin: true,
  315. moveOut: false,
  316. offset: ['40px'],
  317. callback: function(value) {
  318. console.log(value)
  319. if (value.task_id) {
  320. $(".question_ids").val(value.task_id);
  321. }
  322. }
  323. });
  324. });
  325. //任务
  326. $(document).on('click', '.btn-task', function () {
  327. var simtype = $("#c-sim_type").val();
  328. if(!simtype){
  329. Layer.alert('请选择模拟器类型');
  330. return false;
  331. }
  332. var title = '选择任务';
  333. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype), title, {
  334. area: ["85%", "85%"],
  335. maxmin: true,
  336. moveOut: false,
  337. offset: ['40px'],
  338. callback: function(value) {
  339. if (value.task_id) {
  340. $(".question_ids").val(value.task_id);
  341. }
  342. }
  343. });
  344. });
  345. // $("input[name='btSelectAll']").click(function () {
  346. // var ids = Table.api.selectedids(table);
  347. // console.log(ids);
  348. // $(".depart_ids").val(ids);
  349. // });
  350. $("input[name='btSelectAll']").css('display','none');
  351. Form.api.bindevent($("form[role=form]"));
  352. }
  353. }
  354. };
  355. return Controller;
  356. });