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

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

            var table = $("#table");
            $.fn.bootstrapTable.locales[Table.defaults.locale]['formatSearch'] = function(){return "请输入商品名称";};
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'goods_id',
                sortName: 'goods_id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'goods_id', title: __('商品id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'photo', title: __('Photo'),operate:false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        /*{field: 'intro', title: __('Intro'), operate: 'LIKE'},*/
                        {field: 'num', title: __('Num')},
                        /*{field: 'cate_id', title: __('Cate_id')},
                        {field: 'shop_id', title: __('Shop_id')},*/
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'mall_price', title: __('Mall_price'), operate:'BETWEEN'},
                        {field: 'goods_freight', title: __('Goods_freight'), operate:'BETWEEN'},
                        {field: 'sold_num', title: __('Sold_num')},
                        {field: 'views', title: __('Views')},
                        {field: 'closed', title: __('Closed'),searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.status},
                        {field: 'orderby', title: __('Orderby')},
                        /*{field: 'goods_type', title: __('Goods_type')},
                        {field: 'spec_type', title: __('Spec_type')},*/
                        {field: 'remark', title: __('Remark'), operate: 'LIKE'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        /*{field: 'create_ip', title: __('Create_ip'), 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;
});
