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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                asyndownload: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'activity_order_id', title: __('Activity_order_id') ,visible:false},
                        {field: 'activity_id', title: __('活动id') ,visible:false},
                        {field: 'activity_order_detail_id', title: __('订单详情id') ,visible:false},
                        {field: 'withdrawal_log_id',visible:false, title: __('Withdrawal_log_id') },
                        {field: 'to_user_id', title: __('To_user_id')},
                        {field: 'touser.nickname', title: __('Touser.nickname'), operate: 'LIKE'},
                        {field: 'touser.realname',visible:false, title: __('Touser.realname'), operate: 'LIKE'},
                        {field: 'touser.mobile', title: __('Touser.mobile'), operate: 'LIKE'},
                        {field: 'touser.avatar',visible:false, title: __('Touser.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},

                        {field: 'pay_user_id', title: __('Pay_user_id')},
                        {field: 'payuser.nickname', title: __('Payuser.nickname'), operate: 'LIKE'},
                        {field: 'payuser.realname',visible:false, title: __('Payuser.realname'), operate: 'LIKE'},
                        {field: 'payuser.mobile', title: __('Payuser.mobile'), operate: 'LIKE'},
                        {field: 'payuser.avatar', visible:false,title: __('Payuser.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},



                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"-1":__('Status -1')}, formatter: Table.api.formatter.status},


                        {field: 'order_price', title: __('Order_price'), operate:'BETWEEN'},
                        {field: 'fee_price', title: __('Fee_price'), operate:'BETWEEN'},
                        {field: 'fee_scale', title: __('Fee_scale'), operate:'BETWEEN'},
                        {field: 'settle_price', title: __('Settle_price'), operate:'BETWEEN'},


                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'log.id',visible:false, title: __('Log.id')},
                        {field: 'log.price',visible:false, title: __('Log.price'), operate:'BETWEEN'},



                        {field: 'settletime', title: __('Settletime'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'canceltime', title: __('Canceltime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'unfreezetime', title: __('Unfreezetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},


                        {field: 'operate', title: __('Operate'), table: table , buttons: [

                                {
                                    name: 'order',
                                    text: __('源头订单信息'),
                                    title: __('源头订单信息'),
                                    classname: 'btn btn-xs btn-warning btn-magic btn-dialog',
                                    icon: 'fa fa-calendar',
                                    // dropdown : '更多',
                                    url: order_url,
                                    callback: function (data) {

                                    },
                                    // visible: function (row) {
                                    //     return row.paytime;
                                    // }
                                },


                            ], events: Table.api.events.operate, formatter: Table.api.formatter.operate},



                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'school/activity/order/settle_log/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'school/activity/order/settle_log/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'school/activity/order/settle_log/destroy',
                                    refresh: true
                                }
                            ],
                            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]"));
            }
        }
    };


    var order_url = function (row,dom) {
        return 'school/activity/order/order/index?id='+row.activity_order_id;
    }


    return Controller;
});
