collection.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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: 'teacher/collection/index' + location.search,
  8. add_url: 'teacher/collection/add',
  9. edit_url: 'teacher/collection/edit',
  10. del_url: 'teacher/collection/del',
  11. multi_url: 'teacher/collection/multi',
  12. import_url: 'teacher/collection/import',
  13. table: 'teacher_collection',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'exam_collection_id',
  21. sortName: 'exam_collection_id',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. singleSelect : true, //
  25. searchFormVisible:true,
  26. search:false,
  27. showExport:false,
  28. showToggle:false,
  29. showColumns: false,
  30. columns: [
  31. [
  32. {checkbox: true},
  33. {field: 'exam_collection_id', title: __('编号'),operate: false},
  34. {field: 'exam_collection_name', title: __('Exam_collection_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  35. // {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  36. // {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教员自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  37. {
  38. field: 'exam_collection_state',searchList:{"2":"打开","3":"关闭"},
  39. title: __('Exam_collection_state'),
  40. align: 'center',
  41. table: table,
  42. formatter: Table.api.formatter.collectonstate
  43. },
  44. // {field: 'task_id', title: __('Task_id')},
  45. {field: 'limit_duration', title: __('Limit_duration')},
  46. // {field: 'start_time', title: __('Start_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  47. // {field: 'end_time', title: __('End_time'), operate:false, addclass:'datetimerange', autocomplete:false},
  48. // {field: 'create_user_id', title: __('Create_user_id')},
  49. {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
  50. // {field: 'qudui_count', title: __('区队数量'), operate: false},
  51. {field: 'xueyuan_count', title: __('应考人数'), operate: false},
  52. {field: 'yikao_count', title: __('已考人数'), operate: false},
  53. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  54. // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
  55. // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  56. // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  57. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  58. // formatter: Table.api.formatter.operate
  59. formatter: Table.api.formatter.buttons,
  60. buttons: [
  61. {
  62. name: 'dispatch',
  63. text: '编辑',
  64. icon: 'fa fa-pencil',
  65. title: '编辑',
  66. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  67. // extend: 'data-area=\'["85%","85%"]\'',
  68. url: 'teacher/collection/edit',
  69. },
  70. {
  71. name: 'dispatch',
  72. text: '进入考试',
  73. icon: 'fa fa-hand-pointer-o',
  74. title: '进入考试',
  75. visible: function (rr) {
  76. if(rr.exam_collection_state == 2){
  77. return true;
  78. }
  79. return false;
  80. },
  81. classname: 'btn btn-info btn-xs btn-magic btn-addtabs',
  82. url: 'teacher/exams/persent',
  83. },
  84. {
  85. name: 'dispatch',
  86. text: '查看学员',
  87. icon: 'fa fa-eye',
  88. title: '查看学员',
  89. visible: function (rr) {
  90. if(rr.user_count > 0){
  91. return true;
  92. }
  93. return false;
  94. },
  95. classname: 'btn btn-warning btn-xs btn-magic btn-dialog',
  96. extend: 'data-area=\'["85%","85%"]\'',
  97. url: 'teacher/collection/viewuser',
  98. },
  99. {
  100. name: 'dispatch',
  101. text: '添加学员',
  102. icon: 'fa fa-plus',
  103. title: '添加学员',
  104. classname: 'btn btn-success btn-xs btn-magic btn-dialog',
  105. extend: 'data-area=\'["85%","85%"]\'',
  106. url: 'teacher/collection/adduser',
  107. },
  108. {
  109. name: 'dispatch',
  110. text: '删除学员',
  111. icon: 'fa fa-pencil',
  112. title: '删除学员',
  113. visible: function (rr) {
  114. if(rr.user_count > 0){
  115. return true;
  116. }
  117. return false;
  118. },
  119. classname: 'btn btn-info btn-xs btn-magic btn-dialog',
  120. extend: 'data-area=\'["75%","75%"]\'',
  121. url: 'teacher/collection/edituser',
  122. },
  123. {
  124. name: 'dispatch',
  125. text: '删除',
  126. icon: 'fa fa-trash',
  127. title: '删除',
  128. classname: 'btn btn-danger btn-xs btn-magic btn-ajax',
  129. url: 'teacher/collection/del',
  130. confirm: '确定要删除吗?',
  131. success: function (data, ret) {
  132. $(".btn-refresh").trigger("click");
  133. },
  134. error: function (data, ret) {
  135. Layer.alert(ret.msg);
  136. return false;
  137. }
  138. }
  139. ],
  140. }
  141. ]
  142. ]
  143. });
  144. // 为表格绑定事件
  145. Table.api.bindevent(table);
  146. $(document).on('click', '.btn-start', function () {
  147. var ids = Table.api.selectedids(table);
  148. Fast.api.ajax({
  149. url: "teacher/collection/start/ids/"+ids,
  150. type: "post",
  151. }, function () {
  152. Layer.alert('开始成功');
  153. table.bootstrapTable('refresh');
  154. Layer.close(index);
  155. });
  156. });
  157. },
  158. viewuser: function () {
  159. // 初始化表格参数配置
  160. Table.api.init({
  161. extend: {
  162. index_url: 'teacher/collection/viewuser/ids/' +Config.ids+ location.search,
  163. }
  164. });
  165. var table = $("#table");
  166. var multiple = true;
  167. // 初始化表格
  168. table.bootstrapTable({
  169. url: $.fn.bootstrapTable.defaults.extend.index_url,
  170. pk: 'task_id',
  171. sortName: 'task_id',
  172. fixedColumns: true,
  173. fixedRightNumber: 1,
  174. singleSelect : true,
  175. searchFormVisible:true,
  176. search: false,
  177. showExport:false,
  178. showToggle:false,
  179. showColumns: false,
  180. columns: [
  181. [
  182. // {checkbox: true},
  183. // {field: 'task_id', title: __('Task_id'),operate: false},
  184. {field: 'user_nickname', title: __('学员'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  185. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  186. {field: 'question_setting_method', title: __('Question_setting_method'),searchList:{"1":"系统随机","2":"教员自选","3":"任务自选"},formatter: Table.api.formatter.simmethod},
  187. {field: 'fault_names', title: __('故障内容'),formatter: Table.api.formatter.faultname,operate: false},
  188. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  189. // {
  190. // field: 'operate', title: __('Operate'), width: 85, events: {
  191. // 'click .btn-chooseone': function (e, value, row, index) {
  192. // Fast.api.close({url: row.url, multiple: multiple,task_id:row.task_id,task_name:row.name,fault_name:row.fault_name});
  193. // },
  194. // }, formatter: function () {
  195. // return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  196. // }
  197. // }
  198. ]
  199. ]
  200. });
  201. // 为表格绑定事件
  202. Table.api.bindevent(table);
  203. },
  204. task: function () {
  205. // 初始化表格参数配置
  206. Table.api.init({
  207. extend: {
  208. index_url: 'teacher/collection/task/type/' +Config.sim_type+'/ids/'+Config.ids+ location.search,
  209. }
  210. });
  211. var table = $("#table");
  212. var multiple = true;
  213. // 初始化表格
  214. table.bootstrapTable({
  215. url: $.fn.bootstrapTable.defaults.extend.index_url,
  216. pk: 'task_id',
  217. sortName: 'task_id',
  218. fixedColumns: true,
  219. fixedRightNumber: 1,
  220. singleSelect : true,
  221. searchFormVisible:true,
  222. search: false,
  223. showExport:false,
  224. showToggle:false,
  225. showColumns: false,
  226. columns: [
  227. [
  228. {checkbox: true},
  229. // {field: 'task_id', title: __('Task_id'),operate: false},
  230. {field: 'name', title: __('任务名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  231. {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  232. {field: 'fault_name', title: __('故障内容'),formatter: Table.api.formatter.faultname},
  233. {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  234. {
  235. field: 'operate', title: __('Operate'), width: 85, events: {
  236. 'click .btn-chooseone': function (e, value, row, index) {
  237. Fast.api.close({url: row.url, multiple: multiple,task_id:row.task_id,task_name:row.name,fault_name:row.fault_name});
  238. },
  239. }, formatter: function () {
  240. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  241. }
  242. }
  243. ]
  244. ]
  245. });
  246. // 为表格绑定事件
  247. Table.api.bindevent(table);
  248. },
  249. faults: function () {
  250. // 初始化表格参数配置
  251. Table.api.init({
  252. extend: {
  253. index_url: 'teacher/collection/faults/type/'+Config.sim_type + location.search,
  254. }
  255. });
  256. var table = $("#table");
  257. var multiple = true;
  258. // 初始化表格
  259. table.bootstrapTable({
  260. url: $.fn.bootstrapTable.defaults.extend.index_url,
  261. pk: 'fault_id',
  262. sortName: 'fault_id',
  263. sortOrder:'asc',
  264. fixedColumns: true,
  265. fixedRightNumber: 1,
  266. searchFormVisible:false,
  267. showExport:false,
  268. pagination:false,
  269. search:false,
  270. columns: [
  271. [
  272. {checkbox: true},
  273. {field: 'sim_type', title: __('模拟器类型'),operate:false,searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
  274. {field: 'parent_name', title: __('故障现象'), operate: false, table: table, class: 'autocontent',},
  275. {field: 'name', title: __('故障内容'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  276. // {
  277. // field: 'operate', title: __('Operate'), width: 85, events: {
  278. // 'click .btn-chooseone': function (e, value, row, index) {
  279. // Fast.api.close({url: row.url, multiple: multiple,task_id:row.fault_id});
  280. // },
  281. // }, formatter: function () {
  282. // return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  283. // }
  284. // }
  285. ]
  286. ]
  287. });
  288. // 为表格绑定事件
  289. Table.api.bindevent(table);
  290. // 选中多个
  291. $(document).on("click", ".btn-choose-multi", function () {
  292. var exam_collection_type = Config.rowinfo.exam_collection_type;
  293. var ids = Table.api.selectedids(table);
  294. if(ids.length!=3 && exam_collection_type==3){
  295. Layer.alert('故障内容只允许选择3个');
  296. return false
  297. }
  298. if(exam_collection_type==1 && ids.length>3){
  299. Layer.alert('故障内容最多允许选择3个');
  300. return false
  301. }
  302. console.log(ids)
  303. var taskname = [];
  304. var ptaskids = [];
  305. var datas = $("#table").bootstrapTable('getSelections');
  306. $.each(datas,function (index,val) {
  307. taskname.push(val.name)
  308. // var index = ptaskids.indexOf(val.parent_fault_id);
  309. // if (index > -1) {
  310. // Layer.alert('一个故障现象下只允许申请一个故障部位');
  311. // return false
  312. // }
  313. ptaskids.push(val.parent_fault_id)
  314. })
  315. console.log(taskname)
  316. console.log('taskname')
  317. console.log(ptaskids);
  318. var obj = {};
  319. for (var i = 0; i < ptaskids.length; i++) {
  320. var str = ptaskids[i];
  321. if (obj[str]) {
  322. Layer.alert('一个故障现象下只允许申请一个故障部位');
  323. return;
  324. } else {
  325. obj[str] = str; // 存入对象中做标记
  326. }
  327. }
  328. Fast.api.close({url: '', multiple: multiple, task_id:ids,task_name:taskname});
  329. });
  330. $("button[name=commonSearch]").css('display','none');
  331. },
  332. add: function () {
  333. Controller.api.bindevent1();
  334. },
  335. adduser: function () {
  336. Controller.api.bindevent2();
  337. },
  338. edituser: function () {
  339. Controller.api.bindevent2();
  340. },
  341. edit: function () {
  342. Controller.api.bindevent1();
  343. },
  344. api: {
  345. bindevent1: function () {
  346. Form.api.bindevent($("form[role=form]"));
  347. },
  348. initSubTable: function (index, row, $detail,parent_table) {
  349. var admin_id = row.id;
  350. var cur_table = $detail.html('<table id="sub_'+ admin_id +'" style="background-color:#d7d1d147"></table>').find('table');
  351. var sub_table = $(cur_table);
  352. var parent_options = parent_table.bootstrapTable("getOptions");
  353. var parent_selectids = parent_options.selectedIds;
  354. var checked = false;
  355. if (parent_selectids.indexOf(admin_id) !== -1) {
  356. checked = true;
  357. }
  358. parent_options.subSelectedIds[admin_id] = [];
  359. sub_table.bootstrapTable({
  360. // url: 'area/index',
  361. toolbar: false,
  362. showColumns: false,
  363. showToggle: false,
  364. showExport: false,
  365. search: false,
  366. pagination:false,
  367. commonSearch: false,
  368. sortOrder: 'ASC',
  369. checkboxHeader: false,
  370. columns: [
  371. {checkbox: true,
  372. formatter: function(value,rows,index){
  373. if(Config.user_ids.length==0){
  374. return false;
  375. }else if(Config.user_ids.indexOf(rows.id)>-1){
  376. return true;
  377. }else{
  378. return {disabled : true}
  379. }
  380. }
  381. },
  382. // {field: 'id', title: 'ID'},
  383. {field: 'username', title: __('学号')},
  384. {field: 'nickname', title: __('姓名')},
  385. ],
  386. data: row.alluser
  387. });
  388. Table.api.bindevent(sub_table);
  389. if(checked){
  390. sub_table.bootstrapTable("checkAll");
  391. }else{
  392. sub_table.bootstrapTable("uncheckAll");
  393. }
  394. sub_table.on("check.bs.table uncheck.bs.table check-all.bs.table uncheck-all.bs.table post-body.bs.table", function (e) {
  395. var selectedIds = Table.api.selectedids(sub_table);
  396. // selectedData = Table.api.selecteddata(sub_table);
  397. // parent_options.subSelectedIds= [];
  398. // parent_options.subSelectedIds[admin_id] = selectedIds;
  399. // parent_options.subSelectedData[admin_id] = selectedData;
  400. //
  401. // var allSubselectIds = [];
  402. // var allSubselectData = [];
  403. // var allSubselectProjectlib = [];
  404. // for (var i in parent_options.subSelectedIds) {
  405. // allSubselectIds.push.apply(allSubselectIds, parent_options.subSelectedIds[i]);
  406. // }
  407. // for (var j in parent_options.subSelectedData) {
  408. // allSubselectData.push.apply(allSubselectData, parent_options.subSelectedData[j]);
  409. // }
  410. // parent_options.allSubselectIds = allSubselectIds;
  411. // parent_options.allSubselectData = allSubselectData;
  412. console.log(selectedIds);
  413. $(".xueyuan_input").val(selectedIds.length);
  414. $(".xueyuan_total").html(selectedIds.length);
  415. $(".depart_ids").val(selectedIds.join());
  416. });
  417. },
  418. bindevent2: function () {
  419. var rel_Ids = [];
  420. var qudui_total = 0;
  421. var xueyuan_total = 0;
  422. Table.api.init({
  423. extend: {
  424. index_url: 'department/admin/departadmintotal' + location.search,
  425. // index_url: 'auth/admin/admintotal' + location.search,
  426. }
  427. });
  428. var table = $("#table1");
  429. table.on('post-body.bs.table', function (e, data) {
  430. $('#table1').bootstrapTable('expandAllRows');
  431. });
  432. // var oInit = new Object();
  433. // 初始化表格
  434. table.bootstrapTable({
  435. url: $.fn.bootstrapTable.defaults.extend.index_url,
  436. pk: 'id',
  437. sortName: 'id',
  438. fixedColumns: true,
  439. fixedRightNumber: 1,
  440. searchFormVisible:false,
  441. subSelectedIds: {},
  442. subSelectedData: {},
  443. allSubselectIds: [],
  444. allSubselectData: [],
  445. // pagination:false,
  446. detailView: true,//父子表
  447. Search:false,
  448. showExport:false,
  449. showToggle:false,
  450. showColumns: false,
  451. columns: [
  452. [
  453. {checkbox: true},
  454. {field: 'department_name', title: __('区队名称'), operate: false,width: '400px', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
  455. {field: 'department_admin_count', title: __('人员数量'),operate: false},
  456. ]
  457. ],
  458. onExpandRow: function (index, row, $detail) {
  459. Controller.api.initSubTable(index, row, $detail,table);
  460. },
  461. onCheck: function (row, $element) {
  462. $('.btn-disabled').addClass('disabled');
  463. var id = row.id;
  464. console.log('选中了')
  465. $("#sub_" + id).bootstrapTable("checkAll");
  466. },
  467. onUncheck: function (row) {
  468. var id = row.id;
  469. $("#sub_" + id).bootstrapTable("uncheckAll");
  470. },
  471. });
  472. // 为表格绑定事件
  473. Table.api.bindevent(table);
  474. $(document).on('change', '#c-question_setting_method', function () {
  475. if($(this).val()==1){
  476. $(".btn-sm,.btn-task").css('display','none');
  477. }else if($(this).val()==2){
  478. $(".btn-sm").show();
  479. $(".btn-task").css('display','none');
  480. }else if($(this).val()==3){
  481. $(".btn-sm").css('display','none');
  482. $(".btn-task").show();
  483. }
  484. $(".question_ids").val(0);
  485. $(".task_id").val(0);
  486. $("#c-task_name").val('');
  487. $("#c-fault_name").val('');
  488. $("#c-question_name").val('');
  489. $(".tasks,.questions").css('display','none')
  490. });
  491. //考题
  492. $(document).on('click', '.btn-sm', function () {
  493. var simtype = $("#c-sim_type").val();
  494. if(!simtype){
  495. Layer.alert('请选择模拟器类型');
  496. return false
  497. }
  498. var examid = $(".examid").val();
  499. var title = '选择考题';
  500. Fast.api.open(Fast.api.fixurl("teacher/collection/faults/type/"+simtype+"/ids/"+examid), 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 examid = $(".examid").val();
  526. var title = '选择任务';
  527. parent.Fast.api.open(Fast.api.fixurl("teacher/collection/task/type/"+simtype+"/ids/"+examid), title, {
  528. area: ["65%", "70%"],
  529. maxmin: true,
  530. moveOut: false,
  531. offset: ['40px'],
  532. callback: function(value) {
  533. console.log(value);
  534. if (value.task_id) {
  535. $(".tasks").css('display','block')
  536. $(".task_id").val(value.task_id);
  537. $("#c-task_name").val(value.task_name);
  538. $("#c-fault_name").val(value.fault_name);
  539. $(".questions").css('display','none')
  540. $(".question_ids").val(0);
  541. $("#c-question_name").val('');
  542. }
  543. }
  544. });
  545. });
  546. $("button[name=commonSearch]").css('display','none');
  547. $("input[name='btSelectAll']").css('display','none');
  548. Form.api.bindevent($("form[role=form]"));
  549. },
  550. }
  551. };
  552. return Controller;
  553. });