room.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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/index' + location.search,
  8. add_url: 'exam/room/add',
  9. edit_url: 'exam/room/edit',
  10. del_url: 'exam/room/del',
  11. multi_url: 'exam/room/multi',
  12. import_url: 'exam/room/import',
  13. table: 'exam_room',
  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='paper_id']", form).addClass("selectpage").data("source", "exam/paper/index").data("field", "title").data("orderBy", "id desc");
  22. Form.events.cxselect(form);
  23. Form.events.selectpage(form);
  24. });
  25. table.on('post-body.bs.table', function () {
  26. $(".btn-editone").data("area", ["50%", "80%"]);
  27. $("a.btn-add").attr('data-area', '["50%","80%"]');
  28. $("a.btn-edit").attr('data-area', '["50%","80%"]');
  29. $("a.btn-signup").attr('data-area', '["80%","80%"]');
  30. $("a.btn-grade").attr('data-area', '["80%","80%"]');
  31. });
  32. // 初始化表格
  33. table.bootstrapTable({
  34. url: $.fn.bootstrapTable.defaults.extend.index_url,
  35. pk: 'id',
  36. sortName: 'weigh',
  37. fixedColumns: true,
  38. fixedRightNumber: 1,
  39. dblClickToEdit: false, // 是否启用双击编辑
  40. columns: [
  41. [
  42. {checkbox: true},
  43. {field: 'id', title: __('Id')},
  44. {field: 'name', title: __('Name'), operate: 'LIKE'},
  45. {
  46. field: 'contents', title: __('Contents'), operate: false, formatter: Table.api.formatter.content
  47. // formatter: function (value) {
  48. // return value.length > 20 ? value.substr(0, 20) + '...' : value;
  49. // }
  50. },
  51. {field: 'cate_id', title: __('Cate_id'), visible: false},
  52. {field: 'paper_id', title: __('Paper_id'), visible: false},
  53. {field: 'cate.name', title: __('Cate.name'), operate: 'LIKE'},
  54. {field: 'paper.title', title: __('Paper.title'), operate: 'LIKE'},
  55. {
  56. field: 'people_count', title: __('People_count'), formatter: function (value) {
  57. return value > 0 ? value : '不限制';
  58. }
  59. },
  60. {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  61. {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  62. {field: 'weigh', title: __('Weigh'), operate: false},
  63. {field: 'status', title: __('Status'), searchList: {"NORMAL":__('Normal'),"HIDDEN":__('Hidden')}, formatter: Table.api.formatter.status},
  64. {field: 'signup_mode', title: __('Signup_mode'), searchList: {"NORMAL":__('Signup_mode normal'),"PASSWORD":__('Signup_mode password'),"AUDIT":__('Signup_mode audit')}, formatter: Table.api.formatter.normal},
  65. {
  66. field: 'password', title: __('Password'), operate: false, formatter: function (value) {
  67. return value ? value : '未设置';
  68. }
  69. },
  70. {field: 'is_makeup', title: __('Is_makeup'), searchList: {"0":__('Is_makeup 0'),"1":__('Is_makeup 1')}, formatter: Table.api.formatter.normal},
  71. {
  72. field: 'makeup_count', title: __('Makeup_count'), formatter: function (value) {
  73. return value > 0 ? value : '不补考';
  74. }
  75. },
  76. // {field: 'is_rank', title: '排名', searchList: {"0":'未排名',"1":'已排名'}, formatter: Table.api.formatter.normal},
  77. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  78. // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  79. {
  80. field: 'operate',
  81. title: __('Operate'),
  82. table: table,
  83. events: Table.api.events.operate,
  84. formatter: function (value, row, index) {
  85. var that = $.extend({}, this);
  86. var table = $(this.table).clone(true);
  87. // 过期隐藏编辑、删除按钮
  88. if (row.end_time < Controller.api.getTimestamp()) {
  89. $(table).data('operate-edit', null);
  90. $(table).data('operate-del', null);
  91. }
  92. // 开启状态、已有报考隐藏删除按钮
  93. if (row.status == 1 || row.signup_count > 0) {
  94. $(table).data('operate-del', null);
  95. }
  96. that.table = table;
  97. return Table.api.formatter.operate.call(that, value, row, index);
  98. },// Table.api.formatter.operate,
  99. buttons: [
  100. {
  101. name: 'signup',
  102. text: '报名列表',
  103. title: '报名列表',
  104. icon: 'fa fa-list',
  105. classname: 'btn btn-xs btn-info btn-dialog btn-signup',
  106. url: function (row) {
  107. return 'exam/room_signup/index?room_id=' + row.id
  108. },
  109. },
  110. {
  111. name: 'grade',
  112. text: '成绩列表',
  113. title: '成绩列表',
  114. icon: 'fa fa-list',
  115. classname: 'btn btn-xs btn-warning btn-dialog btn-grade',
  116. url: function (row) {
  117. return 'exam/room_grade/index?room_id=' + row.id
  118. },
  119. },
  120. // {
  121. // name: 'detail',
  122. // text: '详情',
  123. // title: '详情',
  124. // icon: 'fa fa-list',
  125. // classname: 'btn btn-xs btn-primary btn-dialog btn-detail',
  126. // url: 'room/detail',
  127. // },
  128. // {
  129. // name: 'rank',
  130. // text: '排行榜',
  131. // title: '排行榜',
  132. // icon: 'fa fa-flag',
  133. // classname: 'btn btn-xs btn-info btn-dialog',
  134. // url: 'room/rank',
  135. // // 按条件显示
  136. // visible: (row) => {
  137. // return row.is_rank > 0
  138. // // return row.end_time < Controller.api.getTimestamp()
  139. // }
  140. // },
  141. ],
  142. }
  143. ]
  144. ]
  145. });
  146. // 为表格绑定事件
  147. Table.api.bindevent(table);
  148. },
  149. recyclebin: function () {
  150. // 初始化表格参数配置
  151. Table.api.init({
  152. extend: {
  153. 'dragsort_url': ''
  154. }
  155. });
  156. var table = $("#table");
  157. // 初始化表格
  158. table.bootstrapTable({
  159. url: 'exam/room/recyclebin' + location.search,
  160. pk: 'id',
  161. sortName: 'id',
  162. columns: [
  163. [
  164. {checkbox: true},
  165. {field: 'id', title: __('Id')},
  166. {field: 'name', title: __('Name'), align: 'left'},
  167. {
  168. field: 'deletetime',
  169. title: __('Deletetime'),
  170. operate: 'RANGE',
  171. addclass: 'datetimerange',
  172. formatter: Table.api.formatter.datetime
  173. },
  174. {
  175. field: 'operate',
  176. width: '130px',
  177. title: __('Operate'),
  178. table: table,
  179. events: Table.api.events.operate,
  180. buttons: [
  181. {
  182. name: 'Restore',
  183. text: __('Restore'),
  184. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  185. icon: 'fa fa-rotate-left',
  186. url: 'exam/room/restore',
  187. refresh: true
  188. },
  189. {
  190. name: 'Destroy',
  191. text: __('Destroy'),
  192. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  193. icon: 'fa fa-times',
  194. url: 'exam/room/destroy',
  195. refresh: true
  196. }
  197. ],
  198. formatter: Table.api.formatter.operate
  199. }
  200. ]
  201. ]
  202. });
  203. // 为表格绑定事件
  204. Table.api.bindevent(table);
  205. },
  206. add: function () {
  207. Controller.api.bindevent();
  208. },
  209. edit: function () {
  210. Controller.api.bindevent();
  211. },
  212. api: {
  213. bindevent: function () {
  214. Form.api.bindevent($("form[role=form]"));
  215. Controller.api.bindSignupMode();
  216. Controller.api.bindMakeupMode();
  217. },
  218. // 绑定报名模式选择
  219. bindSignupMode: function () {
  220. $(document).on("change", "input[name='row[signup_mode]']", function(){
  221. if ($(this).val() == 'PASSWORD') {
  222. $('.password').show();
  223. $('#c-password').attr('data-rule', "required");
  224. $('form').validator("setField", "password", 'required');
  225. } else {
  226. $('.password').hide();
  227. $('#c-password').removeAttr('data-rule');
  228. $('form').validator("setField", "password", null);
  229. }
  230. console.log('signup_mode', $(this).val())
  231. });
  232. $("input[name='row[signup_mode]']:checked").trigger('change');
  233. },
  234. // 绑定补考模式选择
  235. bindMakeupMode: function () {
  236. $(document).on("change", "input[name='row[is_makeup]']", function(){
  237. if ($(this).val() == 1) {
  238. $('.makeup_count').show();
  239. $('#c-makeup_count').attr('data-rule', "required");
  240. $('form').validator("setField", "makeup_count", 'required');
  241. } else {
  242. $('.makeup_count').hide();
  243. $('#c-makeup_count').removeAttr('data-rule');
  244. $('form').validator("setField", "makeup_count", null);
  245. }
  246. console.log('is_makeup', $(this).val())
  247. });
  248. $("input[name='row[is_makeup]']:checked").trigger('change');
  249. },
  250. // 时间戳
  251. getTimestamp: function () {
  252. return (new Date()).getTime() / 1000;
  253. },
  254. }
  255. };
  256. return Controller;
  257. });