define(['table', 'upload','form'], function (Table,Upload,Form) {
    var User = {
        //Do setup work hereAction
        index: function () {
            window.filterData = {
            };
            window.statuskOption=Config.statusList;
            
            Table.api.init({
                extend: {
                    index_url: 'productorder/select',
                    add_url: null,
                    edit_url: 'productorder/update',
                    del_url: null,
                    multi_url: null,
                    dragsort_url: null,
                    table: 'productorder',
                }
            });

            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: "product.title"
                        },
                        {
                            title: "数量",
                            field: "quantity",
                        },
                        {
                            title: "加速",
                            field: "accelerate",
                            formatter:function(v,row){
                                return v ? '是' : '否';
                            }
                        },
                        {
                            title: "进度",
                            field: "assigned",
                            filter:'number',
                            formatter:function(v,row){
                                return parseInt(v/row.total*100)+'%';
                            }
                        },
                        {
                            title: "创建时间",
                            field: "created_at",
                        },
                        {
                            title: "更新时间",
                            field: "updated_at",
                            formatter:Table.api.formatter.datetime,
                            visible: false,
                        },
                        {
                            title: "状态",
                            field: "status",
                            sortable: true,
                            formatter:Table.api.formatter.status,
                            searchList:window.statuskOption,
                            operate:false,
                            filter: "select",
                            filterOption:"statuskOption"
                        },
                        {
                            field: 'operate', title: '操作', 
                            table: table, events: Table.api.events.operate, 
                            formatter: Table.api.formatter.operate,
                            // buttons:[
                            //     {
                            //         text:"详情",
                            //         name:"servers",
                            //         icon:"mdi mdi-account-group-outline",
                            //         classname:"btn btn-xs btn-info btn-dialog",
                            //         url:'workrecord/index'
                            //     }
                            // ]
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        update:function(){
            var form = $('form');
            Form.api.bindevent(form)
        },
        insert:function(){
            var form = $('form');
            Form.api.bindevent(form)
        }
    };
    return User
});