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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pageSize: 12,
                pageList: [],
                pk: 'id',
                sortName: 'id',
                commonSearch: false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'plane.title', title: __('Plane_id'), operate: 'FALSE'},
                        {field: 'base_title', title: __('基地'), operate: 'LIKE'},
                        {field: 'time.title', title: __('Time.title'), operate: 'LIKE'},
                        // {field: 'time_id', title: __('Time_id')},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"1": __('Status 1'), "2": __('Status 2'), "3": __('Status 3')},
                            formatter: Table.api.formatter.status
                        },
                        // {field: 'plane_id', title: __('Plane_id')},
                        // {field: 'user_id', title: __('User_id'), operate: 'LIKE'},
                        // {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {
                            field: 'createtime',
                            title: __('时间'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            autocomplete: false,
                            formatter: Table.api.formatter.datetime,
                            datetimeFormat: "YYYY-MM-DD"
                        },
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.nickname', title: __('预约人'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            //点击按钮获取选中的table中的数据
            $("#button").on("click", function () {
                var temp = Table.api.selectedids(table);
                //发送给控制器
                Fast.api.ajax({
                    url: "sun/Cache?temp=" + temp,
                    type: "GET",
                    data: {},
                }, function (data, ret) {
                    return false;
                }, function (data, ret) {
                    return false;
                });
                Fast.api.close();
            });
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        updateing: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});