grade.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. columns: [
  37. [
  38. {checkbox: true},
  39. {field: 'id', title: __('Id')},
  40. {field: 'cate_id', title: __('Cate_id'), visible: false},
  41. {field: 'cate.name', title: __('Cate_id'), operate: false},
  42. {field: 'user_id', title: __('User_id')},
  43. {field: 'user.nickname', title: __('交卷人昵称'), operate: 'LIKE'},
  44. // {field: 'user.mobile', title: __('交卷人手机'), operate: 'LIKE'},
  45. {field: 'paper_id', title: __('Paper_id')},
  46. {field: 'paper.title', title: __('Paper.title'), operate: false},
  47. {field: 'score', title: __('Score'), operate: false,sortable:true },
  48. {
  49. field: 'is_pass', title: __('Is_pass'), searchList: {"1": __('及格'), "0": __('不及格')},
  50. formatter: Table.api.formatter.normal
  51. },
  52. {field: 'total_score', title: __('Total_score'), operate: 'BETWEEN',},
  53. {field: 'total_count', title: __('Total_count'), operate: false},
  54. {field: 'right_count', title: __('Right_count'), operate: false},
  55. {field: 'error_count', title: __('Error_count'), operate: false},
  56. {
  57. field: 'grade_time',
  58. title: __('Grade_time'),
  59. operate: false,
  60. formatter: Controller.formatter.formatSecond
  61. },
  62. {
  63. field: 'start_time',
  64. title: __('Start_time'),
  65. operate: 'RANGE',
  66. addclass: 'datetimerange',
  67. autocomplete: false,
  68. formatter: Table.api.formatter.datetime
  69. },
  70. {
  71. field: 'finish_time',
  72. title: __('Finish_time'),
  73. operate: 'RANGE',
  74. addclass: 'datetimerange',
  75. autocomplete: false,
  76. formatter: Table.api.formatter.datetime
  77. },
  78. {
  79. field: 'operate', title: __('Operate'), table: table,
  80. events: Table.api.events.operate,
  81. buttons: [{
  82. name: 'detail',
  83. text: __('Detail'),
  84. icon: 'fa fa-list',
  85. classname: 'btn btn-info btn-xs btn-detail btn-dialog',
  86. url: 'exam/grade/detail'
  87. }],
  88. formatter: Table.api.formatter.operate
  89. }
  90. ]
  91. ]
  92. });
  93. // 为表格绑定事件
  94. Table.api.bindevent(table);
  95. },
  96. add: function () {
  97. Controller.api.bindevent();
  98. },
  99. edit: function () {
  100. Controller.api.bindevent();
  101. },
  102. detail: function () {
  103. Controller.api.bindevent();
  104. },
  105. api: {
  106. bindevent: function () {
  107. Form.api.bindevent($("form[role=form]"));
  108. },
  109. },
  110. formatter: {
  111. formatSecond: function(second) {
  112. if (second == 0) return '不限时'
  113. let result = parseInt(second)
  114. let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
  115. let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  116. let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
  117. let res = '';
  118. if(h !== '00') res += `${h}时`;
  119. if(m !== '00') res += `${m}分`;
  120. res += `${s}秒`;
  121. return res;
  122. }
  123. }
  124. };
  125. return Controller;
  126. });