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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'user.nickname', title: __('User.nickname'), operate:false},
                        {field: 'id_num', title: __('Id_num'), operate:false},
                        {field: 'identity', title: __('Identity'), operate:false},
                        {field: 'name', title: __('Name'), operate:false},
                        {field: 'address', title: __('Address')},
                        {field: 'status', title: __('Status'),formatter: Table.api.formatter.label,searchList:{'0': '未认证', '1': '已认证','2':'已拒绝'}},

                        {field: 'id', title: __('按钮组'), table: table, events: Table.api.events.operate, buttons:
                            [
                                {
                                    text: '认证详情',
                                    title: '认证详情',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'farm/detail',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                },
                                {
                                    name: 'name1',
                                    text: '项目列表',
                                    title: '项目列表',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'profarm/index1',
                                    // extend: 'data-area=\'["80%","80%"]\'',
                                    // callback:function(data){
                                    //
                                    // }
                                },
                                {
                                    name: 'name2',
                                    text: '粉丝列表',
                                    title: '粉丝列表',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'proguan/index1',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                    callback:function(data){

                                    }
                                },
                            ], operate:false, formatter: Table.api.formatter.buttons
                        },


                        {field: 'fun_num', title: __('Fun_num'), operate:false},
                        {field: 'attention_num', title: __('Attention_num'), operate:false},
                        {field: 'project_num', title: __('Project_num'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'user.identity', title: __('User.identity'),formatter: Table.api.formatter.label,searchList:{'1': '游客', '2': '农场主','3':'企业单位','4':'政府单位'}},
                        {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;
});