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

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

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'inspectionarea.area_name', title: __('Inspectionarea.area_name'), operate: 'LIKE'},
                        {field: 'areasite.site_name', title: __('巡检点'), operate: 'LIKE'},
                        {field: 'areaitem.item_name', title: __('检查项'), operate: 'LIKE'},
                        {field: 'categoryp.name', title: __('父级类型'), operate: 'LIKE'},
                        {field: 'category.name', title: __('隐患类型'), operate: 'LIKE'},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'message', title: __('Message'), operate: 'LIKE',events:{
                                // click事件 绑定到test1类上,e 事件对象, value 当前这个表格格子的值,row 当前行数据,index当前行索引值
                                'click .open-message':function (e,value,row,index) {
                                    layer.open({
                                        title:'预警信息',
                                        type:1,
                                        content:`<div style="padding: 10px 15px;">${value}</div>`,
                                        area:['30%', '50%'],
                                    });
                                }
                            },formatter: function (value, row, index) {
                                return `<div class="open-message" style="width:160px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
                                            <a href="javascript:void(0);">${value}</a>
                                        </div>`
                            }
                        },
                        {field: 'cover_images', title: __('图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'inspectionstaff.staff_name', title: __('Inspectionstaff.staff_name'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"-1":__('Status -1'),"1":__('Status 1'),"2":__('Status 2')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons:[

                                {
                                    name: 'reply',
                                    text:"隐患回复",
                                    title: __('隐患回复'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'inspection/warning/reply?pid={id}',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                },


                            ],
                            formatter: Table.api.formatter.operate
                        } ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        reply: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                $("#c-category_pid").on('change',function () {
                    let categoryId = $("#c-category_id");
                    //动态修改SelectPage选中项
                    categoryId.selectPageClear();
                    categoryId.selectPageRefresh();
                });
                $("#c-category_id").data("params", function (obj) {
                    //obj为SelectPage对象
                    return {custom: {pid: $("#c-category_pid").val()}};
                });
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});