define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'student/exam/index' + location.search,
                    table: 'teacher_exams',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'exam_id',
                sortName: 'exam_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                searchFormVisible:true,
                singleSelect : true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'exam_id', title: __('Exam_id')},
                        {field: 'exam_collection_name', title: __('考试名称')},
                        {field: 'sim_type', title: __('Sim_type'),searchList:{"0001":"FZD04B型侦毒器","0002":"FZB006型毒剂报警器","0003":"防化兵用毒剂报警器"},formatter: Table.api.formatter.simtype},
                        {field: 'user_username', title: __('学员学号')},
                        {field: 'user_nickname', title: __('学员姓名')},
                        {
                            field: 'user_depart_id',
                            title: __('Department'),
                            visible: false,
                            addclass: 'selectpage',
                            extend: 'data-source="department/index/index" data-field="name"',
                            operate: Config.groupIds !=8 ? 'in':false,
                            formatter: Table.api.formatter.search
                        },
                        // {
                        //     field: 'dadmin',
                        //     title: __('Department'),
                        //     formatter: function (value, row, index) {
                        //         if (value.length == 0)
                        //             return '-' ;
                        //         var department="";
                        //         $.each(value,function(i,v){  //arrTmp数组数据
                        //             if (v.department){
                        //                 department+=department?','+v.department.name:v.department.name;
                        //             }
                        //         });
                        //         return  Table.api.formatter.flag.call(this, department, row, index);
                        //     }, operate:false
                        // },
                        // {field: 'exam_collection_id', title: __('Exam_collection_id')},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'seat_id', title: __('Seat_id')},
                        // {field: 'sim_id', title: __('Sim_id')},
                        {field: 'exam_status', title: __('Exam_status'),searchList: {"0":"未登录","1":"已登录","2":"模拟器检查并下发故障中","3":"模拟器正常","4":"答题中","5":"已交卷","6":"计算成绩中","7":"获取到成绩报告","80":"教师标记缺考","81":"登录未开始答题","90":"模拟器异常结束"},formatter: Table.api.formatter.simexamstatus},
                        {field: 'total_score', title: __('Total_score')},
                        // {field: 'deduction_total_score', title: __('Deduction_total_score')},
                        {field: 'starttime', title: __('Start_time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'endtime', title: __('End_time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        // {field: 'login_time', title: __('Login_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'logout_time', title: __('Logout_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'create_by', title: __('Create_by'), operate: 'LIKE'},
                        // {field: 'createtime', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'update_by', title: __('Update_by'), operate: 'LIKE'},
                        // {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

            $(document).on('click', '.btn-view', function () {
                var ids = Table.api.selectedids(table);
                var title = '成绩详情';
                Fast.api.open(Fast.api.fixurl("student/exam/view/ids/"+ids), title, { area: ["60%", "95%"] });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
