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

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

            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.username', title: __('User.username'), operate: 'LIKE'},
//                        {field: 'user_id', title: __('User_id')},
                        {field: 'decorate_id', title: __('Decorate_id')},
                        {field: 'decorate.name', title: __('Decorate.name'), operate: 'LIKE'},
                        {field: 'decorate_type', title: __('Decorate_type'), searchList: {"1":__('Decorate_type 1'),"2":__('Decorate_type 2'),"3":__('Decorate_type 3'),"4":__('Decorate_type 4')}, formatter: Table.api.formatter.normal},
                        {field: 'is_using', title: __('Is_using'), searchList: {"1":__('Is_using 1'),"0":__('Is_using 0')}, formatter: Table.api.formatter.normal},
                        {field: 'end_time', title: __('End_time'), 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: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

//                        {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;
});