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', title: '序号', search: false},
                    {field: 'uid', title: '用户id'},
                    {field: 'order_id', title: '平台订单号'},
                    {field: 'cp_order_id', title: 'CP订单号'},
                    {field: 'ver', title: '渠道号'},
                    {field: 'appid', title: '游戏ID'},
                    {field: 'server_id', title: '服务器ID', search: false},
                    {field: 'server_name', title: '区服名称', search: false},
                    {field: 'role_id', title: '角色ID', search: false},
                    {field: 'role_name', title: '角色名'},
                    {field: 'role_level', title: '角色等级', search: false},
                    {
                        field: 'status',
                        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',
                        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', title: '下单金额(元)', search: false},
                    {field: 'amount', title: '到账金额(元)', search: false},
                    {field: 'subject', title: '商品标题', search: false},
                    {field: 'wap_number', title: '补发次数', search: false},
                    {field: 'create_time', title: '下单时间', search: 'range'},
                    {
                        title: '操作',
                        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;
});
