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

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'usertrainevaluate/index' + location.search,
                    add_url: 'usertrainevaluate/add',
                    edit_url: 'usertrainevaluate/edit',
                    del_url: 'usertrainevaluate/del',
                    multi_url: 'usertrainevaluate/multi',
                    import_url: 'usertrainevaluate/import',
                    table: 'user_train_evaluate',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'train_id', title: __('Train_id')},
                        {field: 'active.name', title: __('Active.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'active.number', title: __('Active.number'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'user_id', title: __('User_id')},
//                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
//                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.idcard_status', title: __('User.idcard_status'), searchList: {"-1":__('User.idcard_status -1'),"0":__('User.idcard_status 0'),"1":__('User.idcard_status 1'),"2":__('User.idcard_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'evaluate_time', title: __('Evaluate_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'score', title: __('Score')},

//                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            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;
});
