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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'sos_id', title: __('Sos_id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'latitude', title: __('Latitude'), operate: 'LIKE'},
                        {field: 'longitude', title: __('Longitude'), operate: 'LIKE'},
                        {field: 'rescue_id', title: __('Rescue_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'processtime', title: __('Processtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'process_remark', title: __('Process_remark'), operate: 'LIKE'},
                        {field: 'user_phone', title: __('User_phone'), operate: 'LIKE'},
                        {field: 'user_phone_show', title: __('User_phone_show'), operate: 'LIKE'},
                        {field: 'rescue_phone', title: __('Rescue_phone'), operate: 'LIKE'},
                        {field: 'rescue_phone_show', title: __('Rescue_phone_show'), operate: 'LIKE'},
                        {field: 'channel_number', title: __('Channel_number'), operate: 'LIKE'},
                        {field: 'confirmtime', title: __('Confirmtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"-1":__('Status -1'),"-2":__('Status -2')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            $("#c-user_id").data("params", function (obj) {
                return {custom: {cid: $("#c-cid").val()}};
            });
            $("#c-rescue_id").data("params", function (obj) {
                return {custom: {cid: $("#c-cid").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-user_id").data("params", function (obj) {
                return {custom: {cid: $("#c-cid").val()}};
            });
            $("#c-rescue_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;
});