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

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

            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: 'group_id', title: __('Group_id')},
                        // {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
                        {field: 'realname', title: __('Realname'), operate: 'LIKE'},
                        {field: 'work', title: __('Work'), operate: 'LIKE'},
                        // {field: 'password', title: __('Password'), operate: 'LIKE'},
                        // {field: 'salt', title: __('Salt'), operate: 'LIKE'},
                        // {field: 'email', title: __('Email'), operate: 'LIKE'},
                        {field: 'bio', title: __('Bio'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'gender', title: __('Gender'), visible: false, searchList: genderListJson, formatter: Table.api.formatter.normal},
                        // {field: 'level', title: __('Level')},
                        // {field: 'gender', title: __('Gender')},
                        // {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'bio', title: __('Bio'), operate: 'LIKE'},
                        // {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        // {field: 'score', title: __('Score')},
                        // {field: 'successions', title: __('Successions')},
                        // {field: 'maxsuccessions', title: __('Maxsuccessions')},
                        // {field: 'prevtime', title: __('Prevtime')},
                        // {field: 'logintime', title: __('Logintime')},
                        // {field: 'loginip', title: __('Loginip'), operate: 'LIKE'},
                        // {field: 'loginfailure', title: __('Loginfailure')},
                        // {field: 'loginfailuretime', title: __('Loginfailuretime')},
                        // {field: 'joinip', title: __('Joinip'), operate: 'LIKE'},
                        // {field: 'jointime', title: __('Jointime')},
                        // {field: 'createtime', title: __('Createtime')},
                        // {field: 'updatetime', title: __('Updatetime')},
                        // {field: 'token', title: __('Token'), operate: 'LIKE'},
                        // {field: 'status', title: __('Status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        // {field: 'verification', title: __('Verification'), operate: 'LIKE'},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                        {field: 'operate', title: __('Operate'), table: table , buttons: [
                                {
                                    name: 'classes_order',
                                    text: __('课程购买记录'),
                                    title: __('课程购买记录'),
                                    classname: 'btn btn-xs btn-danger btn-magic  btn-dialog',
                                    icon: 'fa fa-cart-arrow-down',
                                    url: classes_order_url,
                                    callback: function (data) {

                                    },
                                    // visible: function (row) {
                                    //     return row.status == '2'||row.status == '3';
                                    // }
                                },

                                {
                                    name: 'classes_hourorder',
                                    text: __('课时预约记录'),
                                    title: __('课时预约记录'),
                                    classname: 'btn btn-xs btn-danger btn-magic  btn-dialog',
                                    icon: 'fa fa-calendar',
                                    url: classes_hourorder_url,
                                    callback: function (data) {

                                    },
                                    // visible: function (row) {
                                    //     return row.status == '2'||row.status == '3';
                                    // }
                                },
                                {
                                    name: 'activity_order',
                                    text: __('机构活动订单'),
                                    title: __('机构活动订单'),
                                    classname: 'btn btn-dialog',
                                    icon: 'fa fa-cart-arrow-down',
                                    dropdown : '更多',
                                    url: activity_order_url,
                                    callback: function (data) {

                                    },
                                    // visible: function (row) {
                                    //     return row.status == '2'||row.status == '3';
                                    // }
                                },
                                {
                                    name: 'evaluate',
                                    text: __('查看用户评价'),
                                    title: __('查看用户评价'),
                                    classname: 'btn btn-dialog',
                                    icon: 'fa fa-handshake-o',
                                    dropdown : '更多',
                                    url: evaluate_url,
                                    callback: function (data) {

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

                            ], 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]"));
            }
        }
    };



     var classes_order_url = function (row,dom) {
        return 'school/classes/order/order/index?user_id='+row.id;
    }
    //classes_hourorder_url
     var classes_hourorder_url = function (row,dom) {
        return 'school/classes/hourorder/order/index?user_id='+row.id;
    }

    var evaluate_url= function (row,dom) {
        return 'school/classes/evaluate/index?user_id='+row.id;
    }
    var activity_order_url = function (row,dom) {
        return 'school/classes/activity/order/order/index?user_id='+row.shop_id;
    }

    return Controller;
});