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

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

            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: 'nickname', title: __('Nickname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'gender', title: __('Gender'), searchList: {"1":__('Gender 1'),"0":__('Gender 0')}, formatter: Table.api.formatter.normal},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'realname', title: __('Realname'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'idcard', title: __('Idcard'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'idcard_z_image', title: __('Idcard_z_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'idcard_f_image', title: __('Idcard_f_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'idcard_status', title: __('Idcard_status'), searchList: {"-1":__('Idcard_status -1'),"0":__('Idcard_status 0'),"1":__('Idcard_status 1'),"2":__('Idcard_status 2'),"3":__('Idcard_status 3')}, formatter: Table.api.formatter.status},
                        {field: 'doctor_image', title: __('Doctor_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'doctor_status', title: __('Doctor_status'), searchList: {"-1":__('Doctor_status -1'),"0":__('Doctor_status 0'),"1":__('Doctor_status 1'),"2":__('Doctor_status 2'),"3":__('Doctor_status 3')}, formatter: Table.api.formatter.status},
                        {field: 'english_status', title: __('English_status'), searchList: {"1":__('English_status 1'),"0":__('English_status 0')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0'),"-1":__('Status -1')}, formatter: Table.api.formatter.status},
                        {field: 'keshi_id', title: __('Keshi_id')},
                        {field: 'hospital', title: __('Hospital'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'goodat', title: __('Goodat'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'ordernum', title: __('Ordernum')},
                        {field: 'level_id', title: __('Level_id')},
                        {field: 'keshi.name', title: __('Keshi.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'level.name', title: __('Level.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {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;
});
