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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
//                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'contacts', title: __('Contacts'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
//                        {field: 'province_name', title: __('Province_name'), operate: 'LIKE'},
//                        {field: 'city_name', title: __('City_name'), operate: 'LIKE'},
//                        {field: 'area_name', title: __('Area_name'), operate: 'LIKE'},
//                        {field: 'province_id', title: __('Province_id')},
//                        {field: 'city_id', title: __('City_id')},
//                        {field: 'area_id', title: __('Area_id')},
//                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'full_address', title: __('Full_address'), operate: 'LIKE'},
//                        {field: 'longitude', title: __('Longitude'), operate:'BETWEEN'},
//                        {field: 'latitude', title: __('Latitude'), operate:'BETWEEN'},
//                        {field: 'aptitude_images', title: __('Aptitude_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'status', title: __('Status'), searchList: {"-1":__('Status -1'),"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'is_open', title: __('Is_open'), searchList: {"0":__('Is_open 0'),"1":__('Is_open 1')}, formatter: Table.api.formatter.normal},
                        {field: 'open_hours', title: __('Open_hours'), operate: 'LIKE'},
//                        {field: 'agent_id', title: __('Agent_id')},
//                        {field: 'mini_code', title: __('Mini_code'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'wallet.money', title: __('Wallet.money'), operate:'BETWEEN'},
                        {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 () {
                $("#c-city_id").data("params",function(){
                    return {custom:{pid:$("#c-province_id").val()}};
                });
                $("#c-area_id").data("params",function(){
                    return {custom:{pid:$("#c-city_id").val()}};
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});