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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'is_top desc,top_time desc,weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'job_name', title: __('Job_name'), operate: 'LIKE'},
                        {field: 'cover', title: __('Cover'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'video', title: __('Video'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'factory_price', title: __('Factory_price'), operate:'BETWEEN'},
                        {field: 'subsidy_price', title: __('Subsidy_price'), operate:'BETWEEN'},
                        {field: 'factory_price_total', title: __('Factory_price_total'), operate:'BETWEEN'},
                        {field: 'salary', title: __('Salary'), operate: 'LIKE'},
                        {field: 'people_num', title: __('People_num')},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
						{field: 'weigh', title: __('Weigh')},
                        //操作栏,默认有编辑、删除或排序按钮,可自定义配置buttons来扩展按钮
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'top',
                                    text: '置顶',
                                    title: '置顶',
                                    classname: 'btn btn-xs btn-primary btn-ajax',
                                    icon: 'fa fa-long-arrow-up',
                                    url: 'job/top?job_id={id}&is_top=1',
                                    visible: function (row) {
                                        if(row.is_top == '0'){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                },
                                {
                                    name: 'top',
                                    text: '取消置顶',
                                    title: '取消置顶',
                                    classname: 'btn btn-xs btn-danger btn-ajax',
                                    icon: 'fa fa-long-arrow-down',
                                    url: 'job/top?job_id={id}&is_top=0',
                                    visible: function (row) {
                                        if(row.is_top == '1'){
                                            return true;
                                        }
                                    },
                                    success: function (data) {
                                        table.bootstrapTable('refresh');
                                    }
                                }
                            ],
                            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]"));
                //监听文本框改变事件
                $(document).on('change keyup', "#c-factory_price,#c-subsidy_price", function () {
                    var A = parseFloat($("#c-factory_price").val()) + parseFloat($("#c-subsidy_price").val());
                    $("#c-factory_price_total").val(A);
                });
            }
        }
    };
    return Controller;
});