collection.js 19 KB

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