project.js 4.9 KB
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'farm.name', title: __('Farm.name'), operate:false},
                        {field: 'project_name', title: __('Project_name'), operate:false},
                        {field: 'address', title: __('Address'), operate:false},
                        {field: 'image', title: __('Image'), 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: 'name', title: __('Name'), operate:false},
                        {field: 'status', title: __('Status'),formatter: Table.api.formatter.label,searchList:{'0': '培育中', '1': '将收获','2':'已收获'}},
                        {field: 'estimate', title: __('Estimate'), operate:false},
                        {field: 'estimate_time', title: __('Estimate_time'), operate:false},
                        {field: 'look_num', title: __('Look_num'), operate:false},
                        {field: 'good_num', title: __('Good_num'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'id', title: __('按钮组'), table: table, events: Table.api.events.operate, buttons:
                            [
                                {
                                    text: '项目详情',
                                    title: '项目详情',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'project/detail',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                },
                                {
                                    name: 'name1',
                                    text: '评论列表',
                                    title: '评论列表',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'pinglun/index1',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                    callback:function(data){
                                    }
                                },
                                {
                                    name: 'name2',
                                    text: '溯源记录',
                                    title: '溯源记录',
                                    icon: 'fa fa-list',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'suyuan/index1',
                                    extend: 'data-area=\'["80%","80%"]\'',
                                    callback:function(data){
                                    }
                                },
                            ], operate:false, formatter: Table.api.formatter.buttons
                        },
                        {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;
});