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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'task_id', title: __('Task_id')},
                        {field: 'finish_number', title: __('Finish_number')},
                        {field: 'pace', title: __('Pace')},
                        {field: 'is_finish', title: __('Is_finish'), searchList: {"1":__('Is_finish 1'),"0":__('Is_finish 0')}, formatter: Table.api.formatter.normal},
                        {field: 'is_reward', title: __('Is_reward'), searchList: {"1":__('Is_reward 1'),"0":__('Is_reward 0')}, formatter: Table.api.formatter.normal},
                        {field: 'finish_date', title: __('Finish_date'), operate: 'LIKE'},
                        {field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'task.name', title: __('Task.name'), operate: 'LIKE'},
                        {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;
});