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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'uid', title: __('Uid')},
                        // {field: 'province_id', title: __('Province_id')},
                        // {field: 'state_id', title: __('State_id')},
                        // {field: 'county_id', title: __('County_id')},
                        // {field: 'reservoir_id', title: __('Reservoir_id')},
                        {field: 'reservoirprovince.name', title: __('Province_id'), operate: 'LIKE'},
                        {field: 'reservoirstate.name', title: __('State_id'), operate: 'LIKE'},
                        {field: 'reservoircounty.name', title: __('County_id'), operate: 'LIKE'},
                        {field: 'reservoirlist.name', title: __('Reservoir_id'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), 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-province_id").on("change",function(){
                $("#c-state_id").selectPageClear();
            });
            $("#c-state_id").on("change",function(){
                $("#c-county_id").selectPageClear();
            });
            $("#c-county_id").on("change",function(){
                $("#c-reservoir_id").selectPageClear();
            });
            $("#c-state_id").data("params", function (obj) {
                return {custom: {province_id: $("#c-province_id").val()}};
            });
            $("#c-county_id").data("params", function (obj) {
                return {custom: {state_id: $("#c-state_id").val()}};
            });
            $("#c-reservoir_id").data("params", function (obj) {
                return {custom: {county_id: $("#c-county_id").val()}};
            });
            Controller.api.bindevent();
        },
        edit: function () {
            $("#c-province_id").on("change",function(){
                $("#c-state_id").selectPageClear();
            });
            $("#c-state_id").on("change",function(){
                $("#c-county_id").selectPageClear();
            });
            $("#c-county_id").on("change",function(){
                $("#c-reservoir_id").selectPageClear();
            });
            $("#c-state_id").data("params", function (obj) {
                return {custom: {province_id: $("#c-province_id").val()}};
            });
            $("#c-county_id").data("params", function (obj) {
                return {custom: {state_id: $("#c-state_id").val()}};
            });
            $("#c-reservoir_id").data("params", function (obj) {
                return {custom: {county_id: $("#c-county_id").val()}};
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});