exam.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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: 'train/exam/index' + location.search,
  8. add_url: 'train/exam/add',
  9. edit_url: 'train/exam/edit',
  10. del_url: 'train/exam/del',
  11. multi_url: 'train/exam/multi',
  12. table: 'train_exam',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'id',
  21. columns: [
  22. [
  23. {checkbox: true},
  24. // {field: 'id', title: __('Id')},
  25. {field: 'title', title: __('Title'), width: '200'},
  26. {field: 'start_time', title: __('Start_time'), operate: 'RANGE', addclass: 'datetimerange'},
  27. {field: 'end_time', title: __('End_time'), operate: 'RANGE', addclass: 'datetimerange'},
  28. {field: 'duration', title: __('Duration'), searchable: false},
  29. {field: 'total', title: __('总分'), searchable: false},
  30. {field: 'qualified', title: __('Qualified'), searchable: false},
  31. {
  32. field: 'status',
  33. title: __('Status'),
  34. formatter: Table.api.formatter.status,
  35. searchList: {0: '待发布', 1: '已发布'},
  36. custom: {0: 'gray', 2: 'success'}
  37. },
  38. {
  39. field: 'operate',
  40. title: __('Operate'),
  41. width: '300',
  42. table: table,
  43. events: Table.api.events.operate,
  44. formatter: Table.api.formatter.operate,
  45. buttons: [
  46. {
  47. name : 'manage_questions',
  48. title : '配置考题',
  49. text : '配置考题',
  50. icon : 'fa fa-calendar-o',
  51. classname: 'btn btn-xs btn-info btn-dialog',
  52. url : 'train/exam/manageQuestions',
  53. visible : function (row){
  54. return row.status === 1 ? false : true
  55. },
  56. extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\''
  57. },
  58. {
  59. name : 'manage_questions',
  60. title : '查看考题',
  61. text : '查看考题',
  62. icon : 'fa fa-calendar-check-o',
  63. classname: 'btn btn-xs btn-info btn-dialog',
  64. url : 'train/exam/examQuestionList',
  65. visible : function (row){
  66. return row.status === 1 ? true : false
  67. },
  68. extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\''
  69. },
  70. {
  71. name : 'manage_users',
  72. title : '管理考生',
  73. text : '管理考生',
  74. icon : 'fa fa-user-o',
  75. classname: 'btn btn-xs btn-warning btn-dialog',
  76. extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\'',
  77. visible : function (row){
  78. return row.status === 1 ? false : true
  79. },
  80. url : 'train/exam/manageAdmins',
  81. },
  82. {
  83. name : 'manage_users',
  84. title : '查看考生',
  85. text : '查看考生',
  86. icon : 'fa fa-user',
  87. classname: 'btn btn-xs btn-warning btn-dialog',
  88. extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\'',
  89. visible : function (row){
  90. return row.status === 1 ? true : false
  91. },
  92. url : 'train/exam/examAdminList',
  93. },
  94. {
  95. name : 'push_exam',
  96. title : '发布',
  97. text : '发布',
  98. extend : 'data-toggle="tooltip"',
  99. icon : 'fa fa-hand-stop-o',
  100. classname: 'btn btn-xs btn-info btn-ajax',
  101. confirm : '确认发布考试?',
  102. url : 'train/exam/pushExam',
  103. visible : function (row){
  104. return row.status === 1 ? false : true
  105. },
  106. success: function (data, ret) {
  107. table.bootstrapTable('refresh')
  108. },
  109. },
  110. {
  111. name : 'push_exam',
  112. text : '发布',
  113. icon : 'fa fa-hand-stop-o',
  114. classname: 'btn btn-xs btn-default disabled',
  115. visible : function (row){
  116. return row.status === 1 ? true : false
  117. },
  118. }
  119. ],
  120. }
  121. ]
  122. ]
  123. });
  124. // 为表格绑定事件
  125. Table.api.bindevent(table);
  126. },
  127. managequestions: function () {
  128. // 初始化表格参数配置
  129. Table.api.init({
  130. extend: {
  131. index_url: 'train/question/index' + location.search,
  132. table: 'train_question',
  133. }
  134. });
  135. var table = $("#table");
  136. // 初始化表格
  137. table.bootstrapTable({
  138. url: $.fn.bootstrapTable.defaults.extend.index_url,
  139. pk: 'id',
  140. sortName: 'id',
  141. clickToSelect:false,
  142. queryParams: function queryParams(params) {
  143. params.exam_id = $('input[name="exam_id"]').val();
  144. return params;
  145. },
  146. columns: [
  147. [
  148. {checkbox: true, field: 'checkbox'},
  149. {field: 'title', title: __('题目标题'), width: '50%', operate: 'LIKE %...%',},
  150. {
  151. field: 'class_id',
  152. title: __('分类'),
  153. formatter: Table.api.formatter.label,
  154. searchList: $.getJSON('train/class_dict/classSelectList')
  155. },
  156. {
  157. field: 'type',
  158. title: __('类型'),
  159. formatter: Table.api.formatter.label,
  160. searchList: {1: '单选', 2: '多选', 3: '判断'},
  161. },
  162. {field: 'result', title: __('正确答案'), searchable: false},
  163. {field: 'created_at', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange'},
  164. {
  165. field: 'operate',
  166. title: __('Operate'),
  167. table: table,
  168. events: Table.api.events.operate,
  169. formatter: Table.api.formatter.operate,
  170. buttons: [
  171. {
  172. name : 'detail',
  173. title : '详情',
  174. text : '详情',
  175. extend : 'data-toggle="tooltip"',
  176. icon : 'fa fa-th-list',
  177. classname: 'btn btn-xs btn-warning btn-dialog',
  178. url : 'train/question/detail',
  179. }
  180. ]
  181. }
  182. ]
  183. ]
  184. });
  185. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  186. $('.form-commonsearch input[name="createdAt"]').attr('autocomplete','off')
  187. })
  188. $('.btn-manage').click(function (){
  189. var question_ids = Table.api.selectedids(table)
  190. var exam_id = $('input[name="exam_id"]').val()
  191. Fast.api.ajax({
  192. url: 'train/exam/manageQuestions',
  193. data: {
  194. question_ids: question_ids,
  195. ids: exam_id
  196. }
  197. }, function (data) {
  198. table.bootstrapTable('refresh')
  199. });
  200. })
  201. // 为表格绑定事件
  202. Table.api.bindevent(table);
  203. },
  204. examquestionlist: function () {
  205. // 初始化表格参数配置
  206. Table.api.init({
  207. extend: {
  208. index_url: 'train/question/index' + location.search,
  209. table: 'train_question',
  210. }
  211. });
  212. var table = $("#table");
  213. // 初始化表格
  214. table.bootstrapTable({
  215. url: $.fn.bootstrapTable.defaults.extend.index_url,
  216. pk: 'id',
  217. sortName: 'id',
  218. clickToSelect:false,
  219. queryParams: function queryParams(params) {
  220. params.show_exam_id = $('input[name="exam_id"]').val();
  221. return params;
  222. },
  223. columns: [
  224. [
  225. {checkbox: true},
  226. {field: 'title', title: __('题目标题'), width: '50%', operate: 'LIKE %...%',},
  227. {
  228. field: 'class_id',
  229. title: __('分类'),
  230. formatter: Table.api.formatter.label,
  231. searchList: $.getJSON('train/class_dict/classSelectList')
  232. },
  233. {
  234. field: 'type',
  235. title: __('类型'),
  236. formatter: Table.api.formatter.label,
  237. searchList: {1: '单选', 2: '多选', 3: '判断'},
  238. },
  239. {field: 'score', title: __('分数'), searchable: false},
  240. {field: 'result', title: __('正确答案'), searchable: false},
  241. {field: 'created_at', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange'},
  242. {
  243. field: 'operate',
  244. title: __('Operate'),
  245. table: table,
  246. events: Table.api.events.operate,
  247. formatter: Table.api.formatter.operate,
  248. buttons: [
  249. {
  250. name : 'detail',
  251. title : '详情',
  252. text : '详情',
  253. extend : 'data-toggle="tooltip"',
  254. icon : 'fa fa-th-list',
  255. classname: 'btn btn-xs btn-warning btn-dialog',
  256. url : 'train/question/detail',
  257. }
  258. ]
  259. }
  260. ]
  261. ]
  262. });
  263. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  264. $('.form-commonsearch input[name="createdAt"]').attr('autocomplete','off')
  265. })
  266. //当加载数据成功时
  267. // table.on('load-success.bs.table', function (e, data) {
  268. // $('.total-score').text('总分数:' + data.total_score)
  269. // $('.qualified').text('合格分数:' + data.qualified)
  270. // });
  271. $('.btn-remove').click(function (){
  272. var question_ids = Table.api.selectedids(table)
  273. var exam_id = $('input[name="exam_id"]').val()
  274. Fast.api.ajax({
  275. url: 'train/exam/removeQuestions',
  276. data: {
  277. question_ids: question_ids,
  278. ids: exam_id
  279. }
  280. }, function (data) {
  281. table.bootstrapTable('refresh')
  282. });
  283. })
  284. $('.btn-set-score').click(function (){
  285. layer.prompt({title: '输入分数,并确认', formType: 0}, function (value, index) {
  286. var question_ids = Table.api.selectedids(table)
  287. var exam_id = $('input[name="exam_id"]').val()
  288. Fast.api.ajax({
  289. url: 'train/exam/setScore',
  290. data: {
  291. question_ids: question_ids,
  292. ids: exam_id,
  293. score: value
  294. }
  295. }, function (data, ret) {
  296. table.bootstrapTable('refresh')
  297. updateScoreText(exam_id)
  298. layer.close(index);
  299. }, function (data, ret) {
  300. Toastr.error(ret.msg)
  301. });
  302. });
  303. })
  304. updateScoreText = function (exam_id) {
  305. Fast.api.ajax({
  306. url: 'train/exam/getExam',
  307. data: {ids: exam_id}
  308. }, function (data) {
  309. $('#exam_total').text(data.total)
  310. $('#exam_qualified').text(data.qualified)
  311. })
  312. }
  313. // 为表格绑定事件
  314. Table.api.bindevent(table);
  315. },
  316. manageadmins: function () {
  317. // 初始化表格参数配置
  318. Table.api.init({
  319. extend: {
  320. index_url: 'train/exam/adminIndex',
  321. }
  322. });
  323. let table = $("#table");
  324. // 初始化表格
  325. table.bootstrapTable({
  326. url: $.fn.bootstrapTable.defaults.extend.index_url,
  327. showToggle: false,
  328. showColumns: false,
  329. queryParams: function queryParams(params) {
  330. params.exam_id = $('input[name="exam_id"]').val();
  331. return params;
  332. },
  333. columns: [
  334. [
  335. {field: 'checkbox', checkbox: true},
  336. {field: 'avatar', title: __('头像'), formatter: Table.api.formatter.image, searchable: false},
  337. {field: 'name', title: __('姓名'), operate: 'LIKE %...%'},
  338. {field: 'title', title: __('职位'), operate: 'LIKE %...%'},
  339. {field: 'mobile', title: __('手机号')},
  340. ]
  341. ]
  342. });
  343. $('.btn-manage').click(function (){
  344. var admin_ids = Table.api.selectedids(table)
  345. var exam_id = $('input[name="exam_id"]').val()
  346. Fast.api.ajax({
  347. url: 'train/exam/manageAdmins',
  348. data: {
  349. admin_ids: admin_ids,
  350. ids: exam_id
  351. }
  352. }, function (data) {
  353. table.bootstrapTable('refresh')
  354. });
  355. })
  356. // 为表格绑定事件
  357. Table.api.bindevent(table);
  358. },
  359. examadminlist: function () {
  360. // 初始化表格参数配置
  361. Table.api.init({
  362. extend: {
  363. index_url: 'train/exam/adminIndex',
  364. }
  365. });
  366. let table = $("#table");
  367. // 初始化表格
  368. table.bootstrapTable({
  369. url: $.fn.bootstrapTable.defaults.extend.index_url,
  370. showToggle: false,
  371. showColumns: false,
  372. queryParams: function queryParams(params) {
  373. params.show_exam_id = $('input[name="exam_id"]').val();
  374. let filter = JSON.parse(params.filter);
  375. let op = JSON.parse(params.op);
  376. if(op.groups_text){
  377. params.group_id = filter.groups_text;
  378. delete(filter.groups_text)
  379. delete(op.groups_text)
  380. }
  381. params.filter = JSON.stringify(filter);
  382. params.op = JSON.stringify(op);
  383. return params;
  384. },
  385. columns: [
  386. [
  387. {field: 'checkbox', checkbox: true, },
  388. {field: 'avatar', title: __('头像'), formatter: Table.api.formatter.image, searchable: false},
  389. {field: 'name', title: __('姓名'), operate: 'LIKE %...%'},
  390. {field: 'title', title: __('职位'), operate: 'LIKE %...%'},
  391. {field: 'mobile', title: __('手机号')},
  392. {
  393. field: 'scores',
  394. title: __('得分'),
  395. formatter: function (val, row) {
  396. if (row.status !== 2) {
  397. return '<span class="text-gray">未考</span>';
  398. }
  399. return '<span class="text-bold">'+ val +'</span>';
  400. }
  401. },
  402. {
  403. field: 'showMistakes',
  404. title: __('Operate'),
  405. width: '300',
  406. table: table,
  407. events: Table.api.events.operate,
  408. formatter: Table.api.formatter.operate,
  409. buttons: [
  410. {
  411. name : 'showMistakes',
  412. title : '查看错题',
  413. text : '查看错题',
  414. icon : 'fa fa-exclamation-circle',
  415. classname: 'btn btn-xs btn-warning btn-dialog',
  416. url : 'train/exam/showMistakes?result_id={result_id}',
  417. visible : function (row){
  418. return row.status === 2 ? true : false
  419. },
  420. extend : 'data-toggle="tooltip" data-area=\'["800px","500px"]\''
  421. },
  422. {
  423. name : 'showMistakes',
  424. title : '查看错题',
  425. text : '查看错题',
  426. icon : 'fa fa-exclamation-circle',
  427. classname: 'btn btn-xs btn-default disabled',
  428. visible : function (row){
  429. return row.status !== 2 ? true : false
  430. },
  431. }
  432. ],
  433. }
  434. ]
  435. ]
  436. });
  437. $('.btn-remove').click(function (){
  438. var admin_ids = Table.api.selectedids(table)
  439. var exam_id = $('input[name="exam_id"]').val()
  440. Fast.api.ajax({
  441. url: 'train/exam/removeAdmins',
  442. data: {
  443. admin_ids: admin_ids,
  444. ids: exam_id
  445. }
  446. }, function (data) {
  447. table.bootstrapTable('refresh')
  448. });
  449. })
  450. // 为表格绑定事件
  451. Table.api.bindevent(table);
  452. },
  453. add: function () {
  454. Controller.api.bindevent();
  455. },
  456. edit: function () {
  457. Controller.api.bindevent();
  458. },
  459. api: {
  460. bindevent: function () {
  461. Form.api.bindevent($("form[role=form]"));
  462. }
  463. }
  464. };
  465. return Controller;
  466. });