define(['table', 'upload','form'], function (Table,Upload,Form) {
    var Controller = {
        index: function () {
            window.statuskOption= Config.statusList;
            
            Table.api.init({
                extend: {
                    index_url: 'giftorder/select',
                    add_url: 'giftorder/insert',
                    edit_url: 'giftorder/update',
                    del_url: 'giftorder/delete',
                    multi_url: 'giftorder/multi',
                    //dragsort_url: 'giftorder/weigh',
                    table: 'giftorder',
                }
            });

            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: "user.username",
                        },
                        {
                            title: "礼品名称",
                            field: "gift.title",
                            filter: "string",
                        },
                        {
                            title: "数量",
                            field: "quantity",
                            formatter:Table.api.formatter.number
                        },
                        {
                            title: "总价",
                            field: "amount",
                            filter: "number",
                            formatter:Table.api.formatter.number
                        },
                        {
                            title: "面值",
                            field: "denomination",
                            filter: "number",
                            formatter:Table.api.formatter.number
                        },
                        {
                            title: "状态",
                            field: "status",
                            sortable: true,
                            formatter:Table.api.formatter.status,
                            searchList:window.statuskOption,
                            operate:false,
                            filter: "select",
                            filterOption:"statuskOption"
                        },
                        {
                            title: "memo",
                            field: "memo",
                            visible: false,
                        },
                        {
                            title: "创建时间",
                            field: "created_at",
                            visible: false,
                        },
                        {
                            title: "更新时间",
                            field: "updated_at",
                            visible: false,
                        },
                        {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(){
            var form = $('form');
            var that = this;
            Form.api.bindevent(form)
        }
    };
    return Controller
});