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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id'), operate: false,formatter: function (value,row,index) {
                            if(row){
                                console.log(row);
                                var html="id："+row.user_id;
                                html  = row.users.nickname?html+"<br/> 昵称：" + row.users.nickname:html;
                                html  = row.users.mobile?html+"<br/> 电话：" + row.users.mobile:html;
                                return html;
                            } else {
                                return "id：" + row.user_id;
                            }

                        }},
                        {field: 'amount', title: __('Amount'), operate:'BETWEEN'},
                        {field: 'payamount', title: __('Payamount'), operate:'BETWEEN'},
                        {field: 'paytype', title: __('Paytype'), operate: 'LIKE'},
                        {field: 'paytime', title: __('Paytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'ip', title: __('Ip'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"created":__('Status created'),"paid":__('Status paid'),"expired":__('Status expired')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, 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]"));
            }
        }
    };
    return Controller;
});
