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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'cid', title: __('Cid')},
                        {field: 'help_id', title: __('Help_id')},
                        {field: 'sex', title: __('Sex'), searchList: {"0":__('Sex 0'),"1":__('Sex 1')}, formatter: Table.api.formatter.normal},
                        {field: 'politics', title: __('Politics'), searchList: {"0":__('Politics 0'),"1":__('Politics 1'),"2":__('Politics 2')}, formatter: Table.api.formatter.normal},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'company', title: __('Company'), operate: 'LIKE'},
                        {field: 'unit_nature', title: __('Unit_nature'), operate: 'LIKE'},
                        {field: 'monthly_income', title: __('Monthly_income'), operate:'BETWEEN'},
                        {field: 'annual_household_income', title: __('Annual_household_income'), operate:'BETWEEN'},
                        {field: 'annual_household_income_average', title: __('Annual_household_income_average'), operate:'BETWEEN'},
                        {field: 'identity', title: __('Identity'), operate: 'LIKE'},
                        {field: 'marriage', title: __('Marriage'), searchList: {"0":__('Marriage 0'),"1":__('Marriage 1')}, formatter: Table.api.formatter.normal},
                        {field: 'medical_insurance', title: __('Medical_insurance'), searchList: {"0":__('Medical_insurance 0'),"1":__('Medical_insurance 1')}, formatter: Table.api.formatter.normal},
                        {field: 'object_features', title: __('Object_features'), operate: 'LIKE'},
                        {field: 'reason', title: __('Reason'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-help_id").data("params", function (obj) {
                return {custom: {cid: $("#c-cid").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-help_id").data("params", function (obj) {
                return {custom: {cid: $("#c-cid").val()}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});