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

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

            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: 'uid', title: __('Uid')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'project_id', title: __('Project_id')},
                        {field: 'project_user_id', title: __('Project_user_id')},
                        {field: 'total_num', title: __('Total_num')},
                        {field: 'order_sn', title: __('Order_sn'), operate: 'LIKE'},
                        {field: 'order_status', title: __('Order_status'), searchList: {"0":__('Order_status 0'),"1":__('Order_status 1'),"-1":__('Order_status -1'),"2":__('Order_status 2'),"3":__('Order_status 3'),"4":__('Order_status 4'),"5":__('Order_status 5'),"6":__('Order_status 6')}, formatter: Table.api.formatter.status},
                        {field: 'add_time', title: __('Add_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'delivery_name', title: __('Delivery_name'), operate: 'LIKE'},
                        {field: 'delivery_id', title: __('Delivery_id'), operate: 'LIKE'},
                        {field: 'delivery_time', title: __('Delivery_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'verify_time', title: __('Verify_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'verify_admin', title: __('Verify_admin')},
                        {field: 'verify_remark', title: __('Verify_remark'), operate: 'LIKE'},
                        {field: 'receiving_admin', title: __('Receiving_admin')},
                        {field: 'receiving_time', title: __('Receiving_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'receiving_remark', title: __('Receiving_remark'), operate: 'LIKE'},
                        {field: 'matter', title: __('Matter'), operate: 'LIKE'},
                        {field: 'qc', title: __('Qc'), operate: 'LIKE'},
                        {field: 'worth', title: __('Worth'), operate: 'LIKE'},
                        {field: 'total_amount', title: __('Total_amount'), operate:'BETWEEN'},
                        {field: 'logistics', title: __('Logistics'), operate: 'LIKE'},
                        {field: 'feedback', title: __('Feedback'), operate: 'LIKE'},
                        {field: 'feedback_admin', title: __('Feedback_admin')},
                        {field: 'feedback_time', title: __('Feedback_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'out_delivery_admin', title: __('Out_delivery_admin')},
                        {field: 'out_delivery_time', title: __('Out_delivery_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'out_delivery_remark', title: __('Out_delivery_remark'), 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-project_id").data("params", function (obj) {
                return {custom: {cid: $("#c-cid").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-project_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;
});