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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'chufaname', title: __('Chufaname'), operate: 'LIKE'},
                        {field: 'chufatype', title: __('Chufatype'), searchList: {"1":__('Chufatype 1'),"2":__('Chufatype 2')}, formatter: Table.api.formatter.normal},
                        {field: 'longitude', title: __('Longitude'), operate: 'LIKE'},
                        {field: 'latitude', title: __('Latitude'), operate: 'LIKE'},

                        {field: 'road_id', title: __('Road_id')},
                        {field: 'road.roadname', title: __('Road.roadname'), operate: 'LIKE'},
                        {field: 'product_id', title: __('Product_id')},
                        {field: 'product.name', title: __('Product.name'), 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;
});

$("#c-road_id").data("params", function (obj) {
    return {
        custom: {product_id: $("#c-product_id").val(),roadtype:['IN','1,2']}
    };
});
$(document).on("change","#c-product_id",function(){
    $("#c-road_id").selectPageClear();
})
