grade.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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: 'exam/grade/index' + location.search,
  8. // add_url: 'exam/grade/add',
  9. // edit_url: 'exam/grade/edit',
  10. del_url: 'exam/grade/del',
  11. // multi_url: 'exam/grade/multi',
  12. // import_url: 'exam/grade/import',
  13. table: 'exam_grade',
  14. }
  15. });
  16. var table = $("#table");
  17. table.on('post-common-search.bs.table', function (event, table) {
  18. let form = $("form", table.$commonsearch);
  19. $("input[name='cate_id']", form).addClass("selectpage").data("source", "exam/cate/selectpage").data("params", {"custom[kind]": "QUESTION"}).data("orderBy", "sort desc");
  20. $("input[name='user_id']", form).addClass("selectpage").data("source", "user/user/index").data("field", "nickname");
  21. $("input[name='paper_id']", form).addClass("selectpage").data("source", "exam/paper/index").data("field", "title");
  22. Form.events.cxselect(form);
  23. Form.events.selectpage(form);
  24. });
  25. //当内容渲染完成给编辑按钮添加`data-area`属性,点击列表编辑按钮时全屏
  26. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  27. $(".btn-detail").data("area", ["80%", "80%"]);
  28. });
  29. // 初始化表格
  30. table.bootstrapTable({
  31. url: $.fn.bootstrapTable.defaults.extend.index_url,
  32. pk: 'id',
  33. sortName: 'id',
  34. fixedColumns: true,
  35. fixedRightNumber: 1,
  36. search: false,
  37. columns: [
  38. [
  39. {checkbox: true},
  40. {field: 'id', title: __('Id')},
  41. // {field: 'cate_id', title: __('Cate_id'), visible: false},
  42. // {field: 'cate.name', title: __('Cate_id'), operate: false},
  43. {field: 'user_id', title: __('User_id')},
  44. {field: 'user.nickname', title: __('答题人昵称'), operate: 'LIKE'},
  45. // {field: 'user.mobile', title: __('交卷人手机'), operate: 'LIKE'},
  46. {field: 'paper_id', title: __('Paper_id')},
  47. {field: 'paper.title', title: __('Paper.title'), operate: false},
  48. {field: 'score', title: __('Score'), operate: false,sortable:true },
  49. /*{
  50. field: 'is_pass', title: __('Is_pass'), searchList: {"1": __('及格'), "0": __('不及格')},
  51. formatter: Table.api.formatter.normal
  52. },*/
  53. {field: 'total_score', title: __('Total_score'), operate: 'BETWEEN',},
  54. {field: 'total_count', title: __('Total_count'), operate: false},
  55. {field: 'right_count', title: __('Right_count'), operate: false},
  56. {field: 'error_count', title: __('Error_count'), operate: false},
  57. /* {
  58. field: 'grade_time',
  59. title: __('Grade_time'),
  60. operate: false,
  61. formatter: Controller.formatter.formatSecond
  62. },
  63. {
  64. field: 'start_time',
  65. title: __('Start_time'),
  66. operate: 'RANGE',
  67. addclass: 'datetimerange',
  68. autocomplete: false,
  69. formatter: Table.api.formatter.datetime
  70. },
  71. {
  72. field: 'finish_time',
  73. title: __('Finish_time'),
  74. operate: 'RANGE',
  75. addclass: 'datetimerange',
  76. autocomplete: false,
  77. formatter: Table.api.formatter.datetime
  78. },*/
  79. {
  80. field: 'operate', title: __('Operate'), table: table,
  81. events: Table.api.events.operate,
  82. buttons: [{
  83. name: 'detail',
  84. text: __('Detail'),
  85. icon: 'fa fa-list',
  86. classname: 'btn btn-info btn-xs btn-detail btn-dialog',
  87. url: 'exam/grade/detail'
  88. }],
  89. formatter: Table.api.formatter.operate
  90. }
  91. ]
  92. ]
  93. });
  94. // 为表格绑定事件
  95. Table.api.bindevent(table);
  96. },
  97. add: function () {
  98. Controller.api.bindevent();
  99. },
  100. edit: function () {
  101. Controller.api.bindevent();
  102. },
  103. detail: function () {
  104. Controller.api.bindevent();
  105. },
  106. api: {
  107. bindevent: function () {
  108. Form.api.bindevent($("form[role=form]"));
  109. },
  110. },
  111. formatter: {
  112. formatSecond: function(second) {
  113. if (second == 0) return '0秒'
  114. let result = parseInt(second)
  115. let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
  116. let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  117. let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
  118. let res = '';
  119. if(h !== '00') res += `${h}时`;
  120. if(m !== '00') res += `${m}分`;
  121. res += `${s}秒`;
  122. return res;
  123. }
  124. }
  125. };
  126. return Controller;
  127. });
  128. //打印ctrl+P
  129. function printPage() {
  130. window.print();
  131. }