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',
                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_image', title: __('Wechat_qrcode_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {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: 'routine_appid', title: __('Routine_appid'), operate: 'LIKE'},
                        {field: 'routine_appsecret', title: __('Routine_appsecret'), operate: 'LIKE'},
                        {field: 'routine_qrcode_image', title: __('Routine_qrcode_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'pay_routine_open', title: __('Pay_routine_open'), searchList: {"0":__('Pay_routine_open 0'),"1":__('Pay_routine_open 1')}, formatter: Table.api.formatter.normal},
                        {field: 'pay_routine_mchid', title: __('Pay_routine_mchid'), operate: 'LIKE'},
                        {field: 'pay_routine_key', title: __('Pay_routine_key'), operate: 'LIKE'},
                        {field: 'pay_routine_client_cert', title: __('Pay_routine_client_cert'), operate: 'LIKE'},
                        {field: 'pay_routine_client_key', title: __('Pay_routine_client_key'), operate: 'LIKE'},
                        {field: 'share_title', title: __('Share_title'), operate: 'LIKE'},
                        {field: 'share_info', title: __('Share_info'), operate: 'LIKE'},
                        {field: 'wx_open_platform', title: __('Wx_open_platform'), searchList: {"0":__('Wx_open_platform 0'),"1":__('Wx_open_platform 1')}, formatter: Table.api.formatter.normal},
                        {field: 'wx_open_appid', title: __('Wx_open_appid'), operate: 'LIKE'},
                        {field: 'wx_open_appsecret', title: __('Wx_open_appsecret'), 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;
});