define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'app.order/index',
        add_url: 'app.order/add',
        edit_url: 'app.order/edit',
        delete_url: 'app.order/delete',
        budan_url: 'app.order/budan',
        export_url: 'app.order/export',
        modify_url: 'app.order/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh'],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', width:80,title: '序号', search: false},
                    {field: 'uid', width:100,title: '用户id'},
                    {field: 'order_id', width:200,title: '平台订单号'},
                    {field: 'cp_order_id', width:150,title: 'CP订单号'},
                    {field: 'ver', width:100,title: '渠道号'},
                    {field: 'appid', width:100,title: '游戏ID'},
                    {field: 'server_id', width:100,title: '服务器ID', search: false},
                    {field: 'server_name', width:100,title: '区服名称', search: false},
                    {field: 'role_id', width:100,title: '角色ID', search: false},
                    {field: 'role_name', width:100,title: '角色名'},
                    {field: 'role_level', width:100,title: '角色等级', search: false},
                    {
                        field: 'status',
                        width:100,
                        title: '订单状态',
                        search: false,
                        templet: function (d) {
                            if (d.status === 0) {
                                // label pull-right layui-bg-orange
                                return '<span class="layui-badge layui-bg-orange">未支付</span>';
                            } else if (d.status === 1) {
                                return '<span class="layui-badge layui-bg-green">充值成功</span>';
                            } else {
                                return '<span class="layui-badge layui-bg-red">充值失败</span>';
                            }
                        }
                    },
                    {
                        field: 'gstatus',
                        width:100,
                        title: '游戏状态',
                        search: false,
                        templet: function (d) {
                            if (d.gstatus === 0) {
                                return '<span class="layui-badge layui-bg-orange">未发货</span>';
                            } else if (d.gstatus === 1) {
                                return '<span class="layui-badge layui-bg-green">发货成功</span>';
                            } else {
                                return '<span class="layui-badge layui-bg-red">发货失败</span>';
                            }
                        }
                    },
                    {field: 'money', width:100,title: '下单金额(元)', search: false},
                    {field: 'amount', width:100,title: '到账金额(元)', search: false},
                    {field: 'subject', width:100,title: '商品标题', search: false},
                    {field: 'wap_number', width:100,title: '补发次数', search: false},
                    {field: 'create_time', width:200,title: '下单时间', search: 'range'},
                    {
                        title: '操作',
                        width:150,
                        templet: ea.table.tool,
                        operat: [
                            [
                                {
                                    text: '查看',
                                    url: init.edit_url,
                                    method: 'open',
                                    auth: 'edit',
                                    class: 'layui-btn layui-btn-xs layui-btn-normal',
                                },
                                {
                                    text: '补单',
                                    title: '是否确定执行补单？',
                                    url: init.budan_url,
                                    method: 'request',
                                    auth: 'refresh',
                                    class: 'layui-btn layui-btn-sm layui-btn-orange',
                                    extend: 'data-table="' + init.table_render_id + '"',
                                }
                            ]
                        ]
                    },
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});
