define(['table', 'upload','form'], function (Table,Upload,Form) {
    var User = {
        //Do setup work hereAction
        index: function () {
            
            Table.api.init({
                extend: {
                    index_url: 'category/select',
                    add_url: 'category/insert',
                    edit_url: 'category/update',
                    del_url: 'category/delete',
                    multi_url: 'category/multi',
                    dragsort_url: 'category/weigh',
                    table: 'category',
                }
            });
            var categorytype = [];
            for (const key in Config.categorytype) {
                categorytype.push({
                    label:Config.categorytype[key],
                    value:key
                });
            }
            window.categorytype = categorytype;

            var table = $("#table");
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                commonSearch: false,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        {
                            field: 'id',
                            title: 'ID',
                            filter: "number",
                            sortable: true    // 是否排序
                        },
                        {
                            title: "类型",
                            field: "type",
                            filter: "select",
                            filterOption: "categorytype",
                            formatter:function(v,d){
                                return '<label class="label label-primary">'+(Config.categorytype[v] || v) +'</label>';
                            }
                        },
                        {
                            title: "标志",
                            field: "name",
                            filter: "string",
                        },
                        {
                            title: "标题",
                            field: "title",
                            filter: "string",
                        },
                        {
                            title: "状态",
                            field: "status",
                            formatter: Table.api.formatter.switch
                        },
                        {field: 'operate', title: '操作', table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        update:function(){
            Config['upload_url'] = '/files/avatar';
            var form = $('form');
            Form.api.bindevent(form)
        },
        insert:function(){
            Config['upload_url'] = '/files/avatar';
            var form = $('form');
            Form.api.bindevent(form)
        }
    };
    return User
});