define(['table', 'upload','form'], function (Table,Upload,Form) {
    var Archives = {
        //Do setup work hereAction
        index: function () {
            window.filterData['type'] = {value1:"article",symbol:'=','value2':''};
            
            Table.api.init({
                extend: {
                    index_url: 'article/select',
                    add_url: 'article/insert',
                    edit_url: 'article/update',
                    del_url: 'article/delete',
                    multi_url: 'article/multi',
                    dragsort_url: 'article/weigh',
                    table: 'archives',
                }
            });
            var _categoryList = [];
            for (let i = 0; i < Config.categoryList.length; i++) {
                const element = Config.categoryList[i];
                _categoryList.push({
                    value:element.id,
                    label:element.title
                });
            }
            window.categoryList = _categoryList;
            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: "category_id",
                            filter: "select",
                            filterOption:'categoryList',
                            formatter:function(v,row){
                                return '<label class="label label-primary">'+row.category.title +'</label>';
                            }
                        },
                        {
                            title: "标题",
                            field: "title",
                            filter: "string",
                        },
                        {
                            title: "创建时间",
                            field: "created_at"
                        },
                        {
                            title: "更新时间",
                            field: "updated_at"
                        },
                        {
                            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(){
            this.bindevent();
        },
        insert:function(){
            this.bindevent();
        },
        bindevent:function(){
            Config['upload_url'] = 'files/upload';
            var form = $('form');
            Form.api.bindevent(form)
        }
    };
    return Archives
});