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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'company_name', title: __('Company_name'), operate: 'LIKE'},
                        {field: 'company_tel', title: __('Company_tel'), operate: 'LIKE'},
                        {field: 'sys_appid', title: __('Sys_appid'), operate: 'LIKE'},
                        {field: 'sys_appsecret', title: __('Sys_appsecret'), operate: 'LIKE'},
                        {field: 'wechat_appid', title: __('Wechat_appid'), operate: 'LIKE'},
                        {field: 'wechat_appsecret', title: __('Wechat_appsecret'), operate: 'LIKE'},
                        {field: 'wechat_token', title: __('Wechat_token'), operate: 'LIKE'},
                        {field: 'wechat_encode', title: __('Wechat_encode'), searchList: {"0":__('Wechat_encode 0'),"1":__('Wechat_encode 1'),"2":__('Wechat_encode 2')}, formatter: Table.api.formatter.normal},
                        {field: 'wechat_encodingaeskey', title: __('Wechat_encodingaeskey'), operate: 'LIKE'},
                        {field: 'wechat_share_image', title: __('Wechat_share_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'wechat_qrcode', title: __('Wechat_qrcode'), operate: 'LIKE'},
                        {field: 'pay_weixin_open', title: __('Pay_weixin_open'), searchList: {"0":__('Pay_weixin_open 0'),"1":__('Pay_weixin_open 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_weixin_mchid', title: __('Pay_weixin_mchid'), operate: 'LIKE'},
                        {field: 'pay_weixin_client_certfile', title: __('Pay_weixin_client_certfile'), operate: false},
                        {field: 'pay_weixin_client_keyfile', title: __('Pay_weixin_client_keyfile'), operate: false},
                        {field: 'pay_weixin_key', title: __('Pay_weixin_key'), 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;
});