room_grade.js 6.9 KB

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