BusEquipmenMaintenanOverview.js
11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
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();
});