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

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

            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: 'content', title: __('Content'), operate: 'LIKE'},
                        {field: 'goodnum', title: __('Goodnum')},
                        {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: 'longitude', title: __('Longitude'), operate: 'LIKE'},
                        {field: 'latitude', title: __('Latitude'), operate: 'LIKE'},
                        {field: 'is_hidden', title: __('Is_hidden'), searchList: {"1":__('Is_hidden 1'),"0":__('Is_hidden 0')}, formatter: Table.api.formatter.normal},
                        {field: 'user.username', title: __('User.username'), 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;
});