From b0eb5b2247867b09e0192b032f342bc3f2ec66eb Mon Sep 17 00:00:00 2001
From: y112102@qq.com <y112102@qq.com>
Date: Thu, 7 Nov 2024 17:17:27 +0800
Subject: [PATCH] -

---
 web/WebMvc/Views/Shared/_Layout.cshtml                                 |  10 +++++-----
 web/WebMvc/wwwroot/productjs/equipment/BusEquipmenMaintenanOverview.js | 259 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 264 insertions(+), 5 deletions(-)
 create mode 100644 web/WebMvc/wwwroot/productjs/equipment/BusEquipmenMaintenanOverview.js

diff --git a/web/WebMvc/Views/Shared/_Layout.cshtml b/web/WebMvc/Views/Shared/_Layout.cshtml
index 872dfe0..0b9b53c 100644
--- a/web/WebMvc/Views/Shared/_Layout.cshtml
+++ b/web/WebMvc/Views/Shared/_Layout.cshtml
@@ -59,13 +59,13 @@
             top.location.href = window.location.href;
         }
         if (window.top.IsDevelopment) {
-            /*全局Js错误监听 */
+            /*全局Js错误监听、正式环境 */
             window.onerror = function (msg, url, l) {
                 const txt = `本页中存在错误\n
-                                                        错误:${msg}\n
-                                                        地址:${url}\n
-                                                        行:${l}\n
-                                                        点击任意空白处继续或刷新浏览器,问题频繁出现请联系管理员。`;
+                             错误:${msg}\n
+                             地址:${url}\n
+                             行:${l}\n
+                             点击任意空白处继续或刷新浏览器,问题频繁出现请联系管理员。`;
                 alert(txt, { icon: 2, shadeClose: true, title: "系统错误" });
                 console.error(txt);
                 return true;
diff --git a/web/WebMvc/wwwroot/productjs/equipment/BusEquipmenMaintenanOverview.js b/web/WebMvc/wwwroot/productjs/equipment/BusEquipmenMaintenanOverview.js
new file mode 100644
index 0000000..b83cb42
--- /dev/null
+++ b/web/WebMvc/wwwroot/productjs/equipment/BusEquipmenMaintenanOverview.js
@@ -0,0 +1,259 @@
+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,
+            otherCoce: null,
+            eqImg: null,
+            eqName: "",
+            projectName: ""
+        },
+
+        areaName = "equipment",
+        controllerName = "BaseEquipment",
+        app = null;
+
+
+    action = {
+        //表格行点击事件
+        customTableCelClick: function (obj, tableId) {
+            if (tableId == app.data.tableColsEqPartElem) {
+                app.methods.initEqPartMaintainDataList(obj.data.PartCode);
+            }
+        },
+    }
+
+    app = {
+        data: {
+            //部件列表
+            colsEqPart: [[
+                { field: "id", width: 80, hide: true, title: "Id", noExel: true },
+                { field: "TopKeys", width: 80, hide: true, title: "topKeys", noExel: true },
+                { field: "HeadKeys", width: 80, hide: true, title: "headKeys", noExel: true },
+                { field: "PartCode", width: 100, title: "部件编码", hide: true },
+                { field: "PartName", width: 250, title: "部件名称" },
+                { field: "LastMaintainTime", title: "上次保养时间", width: 200 },
+                {
+                    field: "NextMaintainTime", title: "下次保养时间", width: 350, templet: function (d) {
+                        const nextMaintenanceTime = moment(d.NextMaintainTime); // 下一次保养时间
+                        const currentTime = moment();
+                        const diffInDays = nextMaintenanceTime.diff(currentTime, 'days'); // 计算未来的时间差
+
+                        if (diffInDays >= 5) {
+                            return `${d.NextMaintainTime}<span style='color:red;'>,还有 ${diffInDays} 天到下次保养</span>`;
+                        } else if (diffInDays < 0) {
+                            return `${d.NextMaintainTime}<span style='color:red;'>,逾期 ${Math.abs(diffInDays)} 天</span>`;
+                        }
+                        return d.NextMaintainTime;
+                    }
+                }
+            ]],
+
+             //保养列表
+            colsEqMaintainRecord: [[
+                { field: "EquipmentCode", width: 80, hide: true, title: "设备编码" },
+                { field: "EquipmentTypeCode", width: 150, title: "设备类型编码", hide: true },
+                { field: "PartCode", width: 80, hide: true, title: "部件编码" },
+
+                { field: "PartName", width: 150, title: "设备部件" },
+                {
+                    field: "NextMaintainTime", title: "下次保养时间", width: 250, templet: function (d) {
+                        const nextMaintenanceTime = moment(d.NextMaintainTime); // 下一次保养时间
+                        const currentTime = moment();
+                        const diffInDays = nextMaintenanceTime.diff(currentTime, 'days'); // 计算未来的时间差
+
+                        if (diffInDays >= 5) {
+                            return `${d.NextMaintainTime}<span style='color:red;'>,还有 ${diffInDays} 天到下次保养</span>`;
+                        } else if (diffInDays < 0) {
+                            return `${d.NextMaintainTime}<span style='color:red;'>,逾期 ${Math.abs(diffInDays)} 天</span>`;
+                        }
+                        return d.NextMaintainTime;
+                    }
+                },
+                { field: "LastMaintainTime", width: 150, title: "上次保养时间" },
+                { field: "MaintainTime", width: 150, title: "本次保养时间" },
+                { field: "Maintainer", width: 150, title: "保养人员" },
+                { field: "MaintainContent", width: 150, title: "保养结果" },
+                {
+                    field: "PushStatus", width: 130, title: "推送状态", templet: function (d) {
+                        return "".GetState(sysU.sysEnumData.EnumMaintainPushStatus, d.PushStatus);
+                    }
+                },
+                {
+                    field: 'url', width: 300, title: '保养附件', templet: function (d) {
+                        debugger
+                        if (d.url == null) return "";
+                        let urlData = d.url.split(","),
+                            target = "_blank";
+                        const fileExtensions = ["pdf", "docx", "doc", "xlsx"];
+                        let aContents = urlData.map((item, index) => {
+                            if (fileExtensions.some(ext => item.includes(ext))) {
+                                target = "_self";
+                            }
+                            let fileName = item.split("_")[0];
+                            return `<a href="../../Document/${item}" target="${target}" style="color:cornflowerblue; text-decoration:underline; cursor:pointer;">${fileName}</a>`;
+                        }).join(",");
+
+                        if (aContents) aContents = aContents.slice(0, -1); // 移除最后一个字符
+                        return aContents
+                    }
+                },
+                { field: "Remark", width: 150, title: "保养备注" }
+            ]],
+
+            tableColsEqPartElem: "equipmentPartDt",
+            tableColsEqMaintainedElem: "maintainedDt",
+            tableColsEqUnMaintainElem: "unMaintainDt",
+
+
+            //下拉框配置
+            selectOption: {
+                //返回的数据 用于后续操作
+                selectData: {
+
+                }
+            },
+        },
+        methods: {
+
+            //读取设备概述、设备部件保养数据 请求数据接口
+            initEqMaintainDataList() {
+                debugger
+                var ajaxConfig = {
+                    data: { equipmentCode: paramData.eqCode, equipmentTypeCode: paramData.eqType },
+                    url: `/${areaName}/${controllerName}/GetEquipmentMaintainList`,
+                    success: function (result) {
+                        if (sysU.successBefore(result)) return false;
+                        app.methods.initEqPartTable(result.Result);
+                    }
+                };
+                sysU.ajax(ajaxConfig);
+            },
+
+            //设备概述、设备部件列表 表单显示
+            initEqPartTable: function (val) {
+                var { MaintainNumber, ToBeMaintainedNumber, lastMaintainTime, sumAmount, status, seconds, ip, imgSrc } = val.main[0];
+                const { text: statusText, bg } = app.methods.getStatusDetails(status, seconds);
+                const statusHTML = `ip:<span style="display: inline-block;">${ip}</span>
+                                       <span class="${bg}" style="left: 7px;"></span>
+                                       <span style="padding-left: 8px;">${statusText}</span>`;
+                $('#eqStatusIP').html(statusHTML);
+
+                app.methods.setText('#maintainNumber', MaintainNumber, "0");
+                app.methods.setText('#toBeMaintainNumber', ToBeMaintainedNumber, "0");
+                app.methods.setText('#lastMaintainTime', lastMaintainTime, "无");
+                app.methods.setText('#sumAmount', sumAmount, "0");
+                app.methods.setText('#eqCode', paramData.eqCode, ""); // 设备编码
+
+                $('#projectInfo').text("项目: " + paramData.projectName);    // 项目名称
+                if (imgSrc != "null") $(".eqImg").attr('src', `/images/equipment/${imgSrc}`)
+
+                //设备部件表格
+                let options = {
+                    elem: "#" + app.data.tableColsEqPartElem,
+                    cols: app.data.colsEqPart,
+                    data: val.eqmaintainHeadList,
+                    page: true,
+                    height: "full-428",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示。数字越小,高度越高
+                    doneExtend: function (res, obj) {
+                        //设备保养、未保养
+                        app.methods.initEqPartMaintainDataList();
+                    }
+                }
+                sysU.initTable(options);
+            },
+
+            //设备部件保养、未保养数据 请求数据接口
+            initEqPartMaintainDataList(obj) {
+                var ajaxConfig = {
+                    data: { eqCode: paramData.eqCode, partCode: obj },
+                    url: `/${areaName}/${controllerName}/GetEquipmentMaintainRecordList`,
+                    success: function (result) {
+                        if (sysU.successBefore(result)) return false;
+                        //加载设备部件保养、未保养 表格
+                        app.methods.initEqMaintainedTable(result.Result.maintainList);
+                        app.methods.initEqUnMaintainTable(result.Result.tobemaintainList);
+                    }
+                };
+                sysU.ajax(ajaxConfig);
+            },
+
+            //设备保养页签-已保养
+            initEqMaintainedTable: function (data) {
+                //设备部件表格
+                let options = {
+                    elem: "#" + app.data.tableColsEqMaintainedElem,
+                    cols: app.data.colsEqMaintainRecord,
+                    data: data,
+                    page: true,
+                    height: "full-380",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
+                    doneExtend: function (res, obj) {
+
+                    }
+                }
+                 sysU.initTable(options);
+            },
+
+            //设备保养页签-未保养
+            initEqUnMaintainTable: function (data) {
+                //设备部件表格
+                let options = {
+                    elem: "#" + app.data.tableColsEqUnMaintainElem,
+                    cols: app.data.colsEqMaintainRecord,
+                    data: data,
+                    page: true,
+                    height: "full-380",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
+                    doneExtend: function (res, obj) {
+
+                    }
+                }
+                sysU.initTable(options);
+            },
+
+            getStatusDetails: function (status, seconds) {
+                if (status === "Failure" || status === "Error") {
+                    return { text: "故障", bg: "layui-badge-dot layui-bg-red" };
+                }
+                if (seconds > 300 || seconds === -1) {
+                    return { text: "离线", bg: "layui-badge-dot layui-bg-gray" };
+                }
+                return { text: "在线", bg: "layui-badge-dot layui-bg-green" };
+            },
+            setText: function (selector, value, defaultValue) {
+                $(selector).text(value || defaultValue);
+            },
+            //初始化表单
+            initFrom() {
+                debugger
+                var cacheData = localStorage.getItem("bus_maintenanceOverview");
+                var tempParamData = null;
+                if (cacheData == null) {
+                    layer.alert("请选择一条数据", { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
+                    return;
+                }
+                tempParamData = JSON.parse(cacheData);
+                paramData.eqCode = tempParamData.equipmentCode;
+                paramData.eqName = tempParamData.equipmentName;
+                paramData.projectName = tempParamData.projectName;            }
+        },
+        registerEvent: function () {
+
+        },
+        init: function () {
+            app.methods.initFrom();
+            app.registerEvent();
+            app.methods.initEqMaintainDataList();
+        }
+    };
+    app.init();
+});
\ No newline at end of file
--
libgit2 0.22.2