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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'wscircleid',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'wscircleid', title: __('Circleid')},
                        {field: 'title', title: __('Title')},
                        {field: 'icon_image', title: __('Icon_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'bg_image', title: __('Bg_image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'circle_type_list', title: __('Circle_type_list'), searchList: {"1":__('Circle_type_list 1'),"2":__('Circle_type_list 2')}, formatter: Table.api.formatter.normal},
                        {field: 'Attention', title: __('Attention')},
                        {field: 'circle_state', title: __('Circle_state'), searchList: {"1":__('Circle_state 1'),"2":__('Circle_state 2')}, formatter: Table.api.formatter.normal},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'circle_open_state', title: __('Circle_open_state'), searchList: {"1":__('Circle_open_state 1'),"2":__('Circle_open_state 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', 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;
});