123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'train/exam/index' + location.search,
- add_url: 'train/exam/add',
- edit_url: 'train/exam/edit',
- del_url: 'train/exam/del',
- multi_url: 'train/exam/multi',
- table: 'train_exam',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- columns: [
- [
- {checkbox: true},
- // {field: 'id', title: __('Id')},
- {field: 'title', title: __('Title'), width: '200'},
- {field: 'start_time', title: __('Start_time'), operate: 'RANGE', addclass: 'datetimerange'},
- {field: 'end_time', title: __('End_time'), operate: 'RANGE', addclass: 'datetimerange'},
- {field: 'duration', title: __('Duration'), searchable: false},
- {field: 'total', title: __('总分'), searchable: false},
- {field: 'qualified', title: __('Qualified'), searchable: false},
- {
- field: 'status',
- title: __('Status'),
- formatter: Table.api.formatter.status,
- searchList: {0: '待发布', 1: '已发布'},
- custom: {0: 'gray', 2: 'success'}
- },
- {
- field: 'operate',
- title: __('Operate'),
- width: '300',
- table: table,
- events: Table.api.events.operate,
- formatter: Table.api.formatter.operate,
- buttons: [
- {
- name : 'manage_questions',
- title : '配置考题',
- text : '配置考题',
- icon : 'fa fa-calendar-o',
- classname: 'btn btn-xs btn-info btn-dialog',
- url : 'train/exam/manageQuestions',
- visible : function (row){
- return row.status === 1 ? false : true
- },
- extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\''
- },
- {
- name : 'manage_questions',
- title : '查看考题',
- text : '查看考题',
- icon : 'fa fa-calendar-check-o',
- classname: 'btn btn-xs btn-info btn-dialog',
- url : 'train/exam/examQuestionList',
- visible : function (row){
- return row.status === 1 ? true : false
- },
- extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\''
- },
- {
- name : 'manage_users',
- title : '管理考生',
- text : '管理考生',
- icon : 'fa fa-user-o',
- classname: 'btn btn-xs btn-warning btn-dialog',
- extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\'',
- visible : function (row){
- return row.status === 1 ? false : true
- },
- url : 'train/exam/manageAdmins',
- },
- {
- name : 'manage_users',
- title : '查看考生',
- text : '查看考生',
- icon : 'fa fa-user',
- classname: 'btn btn-xs btn-warning btn-dialog',
- extend : 'data-toggle="tooltip" data-area=\'["1100px","600px"]\'',
- visible : function (row){
- return row.status === 1 ? true : false
- },
- url : 'train/exam/examAdminList',
- },
- {
- name : 'push_exam',
- title : '发布',
- text : '发布',
- extend : 'data-toggle="tooltip"',
- icon : 'fa fa-hand-stop-o',
- classname: 'btn btn-xs btn-info btn-ajax',
- confirm : '确认发布考试?',
- url : 'train/exam/pushExam',
- visible : function (row){
- return row.status === 1 ? false : true
- },
- success: function (data, ret) {
- table.bootstrapTable('refresh')
- },
- },
- {
- name : 'push_exam',
- text : '发布',
- icon : 'fa fa-hand-stop-o',
- classname: 'btn btn-xs btn-default disabled',
- visible : function (row){
- return row.status === 1 ? true : false
- },
- }
- ],
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- managequestions: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'train/question/index' + location.search,
- table: 'train_question',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- clickToSelect:false,
- queryParams: function queryParams(params) {
- params.exam_id = $('input[name="exam_id"]').val();
- return params;
- },
- columns: [
- [
- {checkbox: true, field: 'checkbox'},
- {field: 'title', title: __('题目标题'), width: '50%', operate: 'LIKE %...%',},
- {
- field: 'class_id',
- title: __('分类'),
- formatter: Table.api.formatter.label,
- searchList: $.getJSON('train/class_dict/classSelectList')
- },
- {
- field: 'type',
- title: __('类型'),
- formatter: Table.api.formatter.label,
- searchList: {1: '单选', 2: '多选', 3: '判断'},
- },
- {field: 'result', title: __('正确答案'), searchable: false},
- {field: 'created_at', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange'},
- {
- field: 'operate',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- formatter: Table.api.formatter.operate,
- buttons: [
- {
- name : 'detail',
- title : '详情',
- text : '详情',
- extend : 'data-toggle="tooltip"',
- icon : 'fa fa-th-list',
- classname: 'btn btn-xs btn-warning btn-dialog',
- url : 'train/question/detail',
- }
- ]
- }
- ]
- ]
- });
- table.on('post-body.bs.table', function (e, settings, json, xhr) {
- $('.form-commonsearch input[name="createdAt"]').attr('autocomplete','off')
- })
- $('.btn-manage').click(function (){
- var question_ids = Table.api.selectedids(table)
- var exam_id = $('input[name="exam_id"]').val()
- Fast.api.ajax({
- url: 'train/exam/manageQuestions',
- data: {
- question_ids: question_ids,
- ids: exam_id
- }
- }, function (data) {
- table.bootstrapTable('refresh')
- });
- })
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- examquestionlist: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'train/question/index' + location.search,
- table: 'train_question',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- clickToSelect:false,
- queryParams: function queryParams(params) {
- params.show_exam_id = $('input[name="exam_id"]').val();
- return params;
- },
- columns: [
- [
- {checkbox: true},
- {field: 'title', title: __('题目标题'), width: '50%', operate: 'LIKE %...%',},
- {
- field: 'class_id',
- title: __('分类'),
- formatter: Table.api.formatter.label,
- searchList: $.getJSON('train/class_dict/classSelectList')
- },
- {
- field: 'type',
- title: __('类型'),
- formatter: Table.api.formatter.label,
- searchList: {1: '单选', 2: '多选', 3: '判断'},
- },
- {field: 'score', title: __('分数'), searchable: false},
- {field: 'result', title: __('正确答案'), searchable: false},
- {field: 'created_at', title: __('创建时间'), operate:'RANGE', addclass:'datetimerange'},
- {
- field: 'operate',
- title: __('Operate'),
- table: table,
- events: Table.api.events.operate,
- formatter: Table.api.formatter.operate,
- buttons: [
- {
- name : 'detail',
- title : '详情',
- text : '详情',
- extend : 'data-toggle="tooltip"',
- icon : 'fa fa-th-list',
- classname: 'btn btn-xs btn-warning btn-dialog',
- url : 'train/question/detail',
- }
- ]
- }
- ]
- ]
- });
- table.on('post-body.bs.table', function (e, settings, json, xhr) {
- $('.form-commonsearch input[name="createdAt"]').attr('autocomplete','off')
- })
- //当加载数据成功时
- // table.on('load-success.bs.table', function (e, data) {
- // $('.total-score').text('总分数:' + data.total_score)
- // $('.qualified').text('合格分数:' + data.qualified)
- // });
- $('.btn-remove').click(function (){
- var question_ids = Table.api.selectedids(table)
- var exam_id = $('input[name="exam_id"]').val()
- Fast.api.ajax({
- url: 'train/exam/removeQuestions',
- data: {
- question_ids: question_ids,
- ids: exam_id
- }
- }, function (data) {
- table.bootstrapTable('refresh')
- });
- })
- $('.btn-set-score').click(function (){
- layer.prompt({title: '输入分数,并确认', formType: 0}, function (value, index) {
- var question_ids = Table.api.selectedids(table)
- var exam_id = $('input[name="exam_id"]').val()
- Fast.api.ajax({
- url: 'train/exam/setScore',
- data: {
- question_ids: question_ids,
- ids: exam_id,
- score: value
- }
- }, function (data, ret) {
- table.bootstrapTable('refresh')
- updateScoreText(exam_id)
- layer.close(index);
- }, function (data, ret) {
- Toastr.error(ret.msg)
- });
- });
- })
- updateScoreText = function (exam_id) {
- Fast.api.ajax({
- url: 'train/exam/getExam',
- data: {ids: exam_id}
- }, function (data) {
- $('#exam_total').text(data.total)
- $('#exam_qualified').text(data.qualified)
- })
- }
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- manageadmins: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'train/exam/adminIndex',
- }
- });
- let table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- showToggle: false,
- showColumns: false,
- queryParams: function queryParams(params) {
- params.exam_id = $('input[name="exam_id"]').val();
- return params;
- },
- columns: [
- [
- {field: 'checkbox', checkbox: true},
- {field: 'avatar', title: __('头像'), formatter: Table.api.formatter.image, searchable: false},
- {field: 'name', title: __('姓名'), operate: 'LIKE %...%'},
- {field: 'title', title: __('职位'), operate: 'LIKE %...%'},
- {field: 'mobile', title: __('手机号')},
- ]
- ]
- });
- $('.btn-manage').click(function (){
- var admin_ids = Table.api.selectedids(table)
- var exam_id = $('input[name="exam_id"]').val()
- Fast.api.ajax({
- url: 'train/exam/manageAdmins',
- data: {
- admin_ids: admin_ids,
- ids: exam_id
- }
- }, function (data) {
- table.bootstrapTable('refresh')
- });
- })
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- examadminlist: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'train/exam/adminIndex',
- }
- });
- let table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- showToggle: false,
- showColumns: false,
- queryParams: function queryParams(params) {
- params.show_exam_id = $('input[name="exam_id"]').val();
- let filter = JSON.parse(params.filter);
- let op = JSON.parse(params.op);
- if(op.groups_text){
- params.group_id = filter.groups_text;
- delete(filter.groups_text)
- delete(op.groups_text)
- }
- params.filter = JSON.stringify(filter);
- params.op = JSON.stringify(op);
- return params;
- },
- columns: [
- [
- {field: 'checkbox', checkbox: true, },
- {field: 'avatar', title: __('头像'), formatter: Table.api.formatter.image, searchable: false},
- {field: 'name', title: __('姓名'), operate: 'LIKE %...%'},
- {field: 'title', title: __('职位'), operate: 'LIKE %...%'},
- {field: 'mobile', title: __('手机号')},
- {
- field: 'scores',
- title: __('得分'),
- formatter: function (val, row) {
- if (row.status !== 2) {
- return '<span class="text-gray">未考</span>';
- }
- return '<span class="text-bold">'+ val +'</span>';
- }
- },
- {
- field: 'showMistakes',
- title: __('Operate'),
- width: '300',
- table: table,
- events: Table.api.events.operate,
- formatter: Table.api.formatter.operate,
- buttons: [
- {
- name : 'showMistakes',
- title : '查看错题',
- text : '查看错题',
- icon : 'fa fa-exclamation-circle',
- classname: 'btn btn-xs btn-warning btn-dialog',
- url : 'train/exam/showMistakes?result_id={result_id}',
- visible : function (row){
- return row.status === 2 ? true : false
- },
- extend : 'data-toggle="tooltip" data-area=\'["800px","500px"]\''
- },
- {
- name : 'showMistakes',
- title : '查看错题',
- text : '查看错题',
- icon : 'fa fa-exclamation-circle',
- classname: 'btn btn-xs btn-default disabled',
- visible : function (row){
- return row.status !== 2 ? true : false
- },
- }
- ],
- }
- ]
- ]
- });
- $('.btn-remove').click(function (){
- var admin_ids = Table.api.selectedids(table)
- var exam_id = $('input[name="exam_id"]').val()
- Fast.api.ajax({
- url: 'train/exam/removeAdmins',
- data: {
- admin_ids: admin_ids,
- ids: exam_id
- }
- }, function (data) {
- table.bootstrapTable('refresh')
- });
- })
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|