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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cid', title: __('Cid')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'card_id', title: __('Card_id'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'tel', title: __('Tel'), operate: 'LIKE'},
                        {field: 'contacts', title: __('Contacts'), operate: 'LIKE'},
                        {field: 'anonymous', title: __('Anonymous'), searchList: {"0":__('Anonymous 0'),"1":__('Anonymous 1')}, formatter: Table.api.formatter.normal},
                        {field: 'invoice', title: __('Invoice'), searchList: {"0":__('Invoice 0'),"1":__('Invoice 1')}, formatter: Table.api.formatter.normal},
                        {field: 'user_type', title: __('User_type'), searchList: {"0":__('User_type 0'),"1":__('User_type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'logistics', title: __('Logistics'), operate: 'LIKE'},
                        {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;
});