define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'quote/index?controller='+Config.controller+"&ids="+Config.ids,
                    add_url: 'quote/add?controller='+Config.controller+"&ids="+Config.ids,
                    edit_url: 'quote/edit',
                    del_url: 'quote/del',
                    multi_url: 'quote/multi',
                    table: 'quote',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                sortOrder:'desc',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'quote_style', title: __('Quote_style')},
                        {field: 'form', title: __('Form'), searchList: {"0":__('Form 0'),"1":__('Form 1')}, formatter: Table.api.formatter.normal},
                        {field: 'line', title: __('Line'),formatter:Table.api.formatter.url},
                        {field: 'quote_id', title: __('Quote_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'title', title: __('Title')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                    ]
                ],
                search:false,
                commonSearch:false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {

            Controller.api.bindevent();
            $("#c-form").on("change",function () {
                var form_id=$(this).val();
                if(form_id==1){
                    //引用id去掉,使用用户输入的;
                    $("#quote_id").hide();
                    $('#c-quote_id_text').val("无");
                    $('#c-quote_id').val("0");
                    $("#line").show();
                    $("#content1").show();
                    $("#title").show();
                }else{
                    $("#line").hide();
                    $("#content1").hide();
                    $("#title").hide();
                    $("#quote_id").show();
                }
            });
            $("#c-quote_style").on("change",function () {
                $('#c-quote_id_text').val("");
                $('#c-quote_id').val("");
                var quote=$(this).val();
                $("#c-quote_id_text").data("selectPageObject").option.data=quote+"/index";
                if(quote!="pepole"){
                    $('#c-quote_id_text').data("selectPageObject").option.searchField[0]='title';
                    $('#c-quote_id_text').data("selectPageObject").option.showField='title';
                    $('#c-quote_id_text').data("selectPageObject").option.orderBy[0][0]='title';
                }else{
                    $('#c-quote_id_text').data("selectPageObject").option.searchField[0]='name';
                    $('#c-quote_id_text').data("selectPageObject").option.showField='name';
                    $('#c-quote_id_text').data("selectPageObject").option.orderBy[0][0]='name';
                }
            })

        },
        edit: function () {
            Controller.api.bindevent();
            if(Config.form==1){
                $("#quote_id").hide();
                $("#line").show();
                $("#content1").show();
                $("#title").show();
                $('#c-quote_id_text').val("无");
                $('#c-quote_id').val("0");
            }
            $("#c-form").on("change",function () {
                var form_id=$(this).val();
                if(form_id==1){
                    //引用id去掉,使用用户输入的;
                    $("#quote_id").hide();
                    $("#line").show();
                    $("#content1").show();
                    $("#title").show();
                    $('#c-quote_id_text').val("无");
                    $('#c-quote_id').val("0");
                }else{
                    $("#line").hide();
                    $("#content1").hide();
                    $("#title").hide();
                    $("#quote_id").show();
                }
            });
            $("#c-quote_style").on("change",function () {
                if(Config.form==1){
                    return;
                }
                $('#c-quote_id_text').val("");
                $('#c-quote_id').val("");
                var quote=$(this).val();
                $("#c-quote_id_text").data("selectPageObject").option.data=quote+"/index";
                if(quote!="pepole"){
                    $('#c-quote_id_text').data("selectPageObject").option.searchField[0]='title';
                    $('#c-quote_id_text').data("selectPageObject").option.showField='title';
                    $('#c-quote_id_text').data("selectPageObject").option.orderBy[0][0]='title';
                }else{
                    $('#c-quote_id_text').data("selectPageObject").option.searchField[0]='name';
                    $('#c-quote_id_text').data("selectPageObject").option.showField='name';
                    $('#c-quote_id_text').data("selectPageObject").option.orderBy[0][0]='name';
                }
            })

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});