EquipmentVisual.js 10.8 KB
let action = null;
layui.config({
    base: "/js/",
    version: 1
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        sendDataWhere = null,
        paramData = {
            eqCode: null,
            eqType: null,
            eqName:""
        },
        areaName = "equipment",
        controllerName = "BaseEquipment",
        app = null;

    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Ins`,
                submit: "submit(fromAdd)"
            }
            return options;
        },

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Upd`,
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/DelByIds`,
                keyId: "id"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${controllerName}/Export`,
                isDefault: false,
                sendDataWhere: {},
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${controllerName}/Export`,
                urlQuery: `/${areaName}/${controllerName}/Load`,
                sendDataWhere: {},
                mainTable: app.data.tableIns
            }
            return options;
        },
        /*rowClickOptions: function () {
            var options = {
                //是否主子表
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },*/

        uploadOptions: function () {
            var options = { 
                url: `/${areaName}/${controllerName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },
        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
            //data.enable = data.enable.toString();
            form.val("modifyForm", data);
            if (callBack != null) callBack();
        },
        editSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },

        checkboxMethod: function (obj) {
            var page = "".GetUrlParam("page"),
                xxx = "".GetUrlParam("xxx");
            if (page == "xxx") {
                var sendData = {

                };
                var ajaxConfig = {
                    data: sendData,
                    url: `${areaName}/${controllerName}/xxx`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return false;
                        layer.msg(result.Message);
                    }
                };
                sysU.ajax(ajaxConfig);
            }
        },

        tabVisualTabMethod: function (data) {
            if (data.index == 2 || data.index == 3) {
                app.methods.ininEqFileAndAlarmList()
            }
        },

        //所有动作成功之后
        actionSuccess: (flag) => {
            sysU.refreshTable(app, sysU, null, flag);
        },
        closeAfter: function (callBack) {
            if (callBack != null) callBack();
        }
    }

    app = {
        data: {
            colsFile: [[
                { field: "id", width: 100, title: "编码", hide: true },
                { field: "zizeng", width: 80, title: "序号", fixed: "left", type: "numbers" },
                { field: 'fileName', width: 300, title: '文档名称' },
                {
                    field: 'url', width: 300, title: '文件下载', templet: function (d) {
                        var target = "_blank";
                        if (d.suffix.indexOf("pdf") > -1 || d.suffix.indexOf("docx") > -1 || d.suffix.indexOf("doc") > -1 || d.suffix.indexOf("xlsx") > -1) {
                            target = "_self";
                        }
                        return `<a href="../../Document/${d.url}"  target='${target}' style="color:cornflowerblue;text-decoration: underline;cursor:pointer;">${d.fileName}</a>`;
                    }
                },
                { field: 'size', width: 100, title: '文档大小' },
                { field: 'targetId', title: '设备Code', hide: true },
                { field: 'targetTableName', width: 120, title: '适用的设备', hide: true },
                { field: 'suffix', width: 100, title: '文档类型' },
                { field: 'remark', width: 120, title: '备注' },

                { field: 'createTime', width: 150, title: '创建时间' },
                { field: 'createBy', width: 100, title: '创建人' }
            ]],
            tableColsFileObj: null,
            tableColsFileElem: "mainFile",

            colsAlarm: [[
                { field: "Id", width: 80, hide: true, title: "Id" },
                { field: "zizeng", width: 80, title: "序号", fixed: "left", type: "numbers" },
                { field: "EquipmentCode", width: 200, title: "设备编号", hide: true, },
                { field: "EquipmentName", width: 150, title: "设备名称" },
                { field: "AlarmMessage", width: 400, title: "报警信息" },
                {
                    field: "Errorduration", width: 150, title: "报警持续时间", templet: function (d) {
                        return app.methods.convertSecondsToTime(d.Errorduration)
                    }
                },
                { field: "CreateTime", width: 150, title: "创建时间" },
                { field: "Remark", width: 150, title: "备注" },
            ]],
            tableColsAlarmObj: null,
            tableColsAlarmElem: "mainAlarm",
            echartOpt: {
                eqDeviceStatusEle: document.getElementById("deviceStatus"),
            },

            //下拉框配置
            selectOption: {
                //station: {
                //    SelType: "FromUrl",
                //    SelFrom: `/${areaName}/${controllerName}/StationLineSelect`,
                //    SelLabel: "workStationName",
                //    SelValue: "workStationCode",
                //    OptGroup: true,
                //    Dom: [$("[name='stationCode']")]
                //},
                //返回的数据 用于后续操作
                selectData: {

                }
            },
        },
        methods: {
            //文件列表
            initFileTable: function (data) {
                let options = {
                    elem: "#" + app.data.tableColsFileElem,
                    cols: app.data.colsFile,
                    data: data,
                    page: false,
                    limit: Number.MAX_VALUE,
                    height: "full-90",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
                    doneExtend: function (res, obj) {

                    }
                }
                app.data.tableColsFileObj = sysU.initTable(options);
            },
            //报警列表
            initAlarmTable: function (data) {
                let options = {
                    elem: "#" + app.data.tableColsAlarmElem,
                    cols: app.data.colsAlarm,
                    data: data,
                    page: false,
                    limit: Number.MAX_VALUE,
                    height: "full-90",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
                    doneExtend: function (res, obj) {

                    }
                }
                app.data.tableColsAlarmObj = sysU.initTable(options);
            },
            initDeviceStatus() {
                let myChart = echarts.init(app.data.echartOpt.eqDeviceStatusEle)
                window.deviceStatus.series[0].data[0].value = 12
                myChart.clear()
                myChart.setOption(window.deviceStatus)
            },

            //文件、报警
           ininEqFileAndAlarmList() {
                var ajaxConfig = {
                    data: {  equipmentCode: paramData.eqCode, equipmentTypeCode: paramData.eqType },
                    url: `/${areaName}/${controllerName}/GetEquipmentFileList`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return false;
                        app.methods.initFileTable(result.Result.fileList);
                        app.methods.initAlarmTable(result.Result.alarmList);
                    }
                };
                sysU.ajax(ajaxConfig);
            },

            convertSecondsToTime: function (seconds) {
                if (typeof seconds !== 'number') return seconds;
                var hours = Math.floor(seconds / 3600);
                var minutes = Math.floor((seconds % 3600) / 60);
                var remainingSeconds = seconds % 60;

                var result = '';
                if (hours > 0) {
                    result += hours + '小时';
                }
                if (minutes > 0) {
                    result += minutes + '分';
                }
                result += remainingSeconds + '秒';
                return result;
            },
           initFrom() {
                //sysU.initSelect(app.data.selectOption);

                //sysU.initSelecteByEnum(app.data.selectOptionEnum);

                paramData.eqCode = "".GetUrlParam("eqCode");
                paramData.eqType = "".GetUrlParam("eqType");
                paramData.eqName = "".GetUrlParam("eqName");
                $("#bread-visual").text(`设备可视化【${paramData.eqName}】`)
            }
        },
        registerEvent: function () {

        },
        init: function () {
            //var sendDataWhere = form.val("listForm")
            //app.methods.initTable();

            app.methods.initDeviceStatus()
            app.methods.initFrom();
            app.registerEvent();
        }
    };
    app.init();
});