busequipmentmaintainnotice.js
20.9 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
let action = null;
let sendDataWhereTree = {
projectKeys: null,
projectName: null,
projectCode: null
},
ztreeProjectData = null;
layui.config({
base: "/js/",
version: 1
}).use(['system', 'ztree'], function () {
var form = layui.form,
$ = layui.jquery,
element = layui.element,
table = layui.table,
system = layui.system,
sysU = new system.u(),
sendDataWhere = null,
sendDataDescWhere = null,
areaName = "equipment",
controllerName = "BusEquipmentMaintainNotice",
app = null;
var toplayer = (top == undefined || top.layer === undefined) ? layer : top.layer; //顶层的LAYER
action = {
addOptions: function () {
var options = {
fromId: "#modifyForm form",
url: `/${areaName}/${controllerName}/Ins`,
//sendDataWhere: null,
//isAddWhereExtend: "arbitrarily",
//mainTable: app.data.tableIns,
submit: "submit(fromAdd)"
}
return options;
},
editOptionsDesc: function () {
var options = {
title: ",处理报警",
fromId: "#modifyFormDesc form",
url: `/${areaName}/${controllerName}/Upd`,
content: $("#modifyFormDesc"),
submit: "submit(fromUpdateDesc)"
}
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: true,
sendDataWhere: { ProjectCode: sendDataWhereTree.projectCode, projectName: sendDataWhereTree.projectName },
excelCols: {
head: app.data.cols,
body: app.data.colsDesc
},
ExcelExportFn: function (excelParm, result, toolbarId, callBackFn) {
debugger
result.Result.body.forEach(x => {
if (x.UserHandleTime == "0001-01-01 00:00:00") x.UserHandleTime = "";
x.errorduration = "".convertSecondsToTime(x.errorduration);
x.alarmMessage = x.alarmMessage + ";" + (x.remark == null ? "" : x.remark);
x.isHandled = x.isHandled ? "已处理" : "未处理";
x.isEnd = x.isEnd ? "已结束" : "未结束";
})
callBackFn(excelParm, result, toolbarId);
}
}
return options;
},
queryOptions: function () {
var options = {
resetFrom: "form[lay-filter=listForm]",
fromId: "listForm",
urlExport: `/${areaName}/${controllerName}/Export`,
urlQuery: `/${areaName}/${controllerName}/Load`,
sendDataWhere: { ProjectCode: sendDataWhereTree.projectCode },
mainTable: app.data.tableIns
}
return options;
},
queryOptionsDesc: function () {
var options = {
resetFrom: "form[lay-filter=listFormDesc]",
fromId: "listFormDesc",
urlQuery: `/${areaName}/${controllerName}/LoadDesc`,
sendDataWhere: { topKeys: sendDataDescWhere.keys },
mainTable: app.data.tableInsDesc,
}
return options;
},
//内部不支持异步
uploadBeforeDesc: function (checkStatus, parm) {
debugger
if (checkStatus.data.length === 0) {
layer.alert(`请选择一条数据后,再确认保养。当前选择的行数【${checkStatus.data.length}】条!`, { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
return false;
}
form.val(parm.content[0].id, checkStatus.data[0]);
return checkStatus.data[0] != undefined;
},
uploadOptionsDesc: function () {
var options = {
title: "保养确认 <span style=\"color:red;font-weight: bold;\">(上传附件时间可能比较久,请耐心等待...)</span>",
area: ["700px", "500px"],
url: `/${areaName}/${controllerName}/Import`,
fromFile: "#excelfile",
content: $("#ImportData")
}
return options;
},
uploadSaveBeforeDesc: function (dataObj, selectRow, callBack) {
debugger
var maintainTime = dataObj.formFile.get("maintainTime");
if (maintainTime == "") {
layer.close(dataObj.closeIndex);
layer.alert(`确认保养:保养时间不能为空!`, { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
return false
}
var maintainer = dataObj.formFile.get("maintainer");
if (maintainer == "") {
layer.close(dataObj.closeIndex);
layer.alert(`确认保养:保养人不能为空!`, { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
return false
}
if (callBack != null) callBack();
},
addBefore: function (callBack) {
//callBack是回调函数,如果editBefore有ajax 放在成功之后
if (callBack != null) callBack();
},
addSaveBefore: function (data, callBack) {
if (callBack != null) callBack();
},
editBeforeDesc: function (data, callBack) {
form.val("modifyFormDesc", data);
if (callBack != null) callBack();
},
editSaveBeforeDesc: 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);
}
},
rowClickOptions: function () {
var options = {
isDefault: true,
targetTableId: app.data.tableElem,
tabfilter: "tableTabBody",
tabId: 2,
customFn: app.methods.initTableDesc
}
return options;
},
//当前行表格双击事件处理
customTableRowClick: function (obj, tableId) {
if (tableId == app.data.tableElem) {
rowData = obj.data;
}
},
customTableCelClick: function (obj, tableId) {
console.log(obj, tableId)
},
btnMaintenance: function (sU, toolbarId, obj, $event) {
debugger
var checkStatus = table.checkStatus(toolbarId),
//选中的行数
selectRow = checkStatus.data.length;
if (selectRow !=1) {
layer.alert("请选择一条数据", { icon: sU.config.iconoError, shadeClose: true, title: "错误信息" });
return false;
}
var title = `设备${checkStatus.data[0].equipmentName}保养概述`;
var tabsEle = window.parent.document.querySelectorAll("#top_tabs cite");
for (var i = 0; i < tabsEle.length; i++) {
if (tabsEle[i].innerText == title) {
$(tabsEle[i]).next().click()
break;
}
}
var data = {
projectName: checkStatus.data[0].projectName,
equipmentCode: checkStatus.data[0].equipmentCode,
equipmentName: checkStatus.data[0].equipmentName,
}
localStorage.setItem("bus_maintenanceOverview", JSON.stringify(data));
var url = `/${areaName}/${controllerName}/MaintenanceOverview`;
var urlHtml = $(`<a title="${title}" data-url="${url}"><i class="layui-icon" data-icon=""></i><cite>${title}</cite></a>`)
window.top.tab.tabAdd(urlHtml);
},
//查看部件的保养历史记录
btnMaintainInfo: function () {
var checkStatus = table.checkStatus('mainListDesc'),
data = checkStatus.data;
if (data.length != 1) {
toplayer.msg("请选择要查看哪个部件的保养历史记录")
return;
}
toplayer.open({
type: 2,
area: ['1150px', '600px'],
title: "设备部件【" + data[0].equipmentName + "】保养历史记录",
content: `/${areaName}/BusEquipmentMaintainRecordDetail/Index?menuflag=-2&&projectkeys=${data[0].projectKeys}&&equipmentCode=${data[0].equipmentCode}&&partCode=${data[0].partCode}`,
success: function (layero, index) {
}
})
},
//所有动作成功之后
actionSuccess: (flag) => {
var sendData = { ProjectCode: sendDataWhereTree.projectCode }
if (flag.indexOf(sysU.config.descSuffix) > -1) {
sendData = { topKeys: sendDataDescWhere.keys }
}
sysU.refreshTable(app, sysU, sendData, flag);
},
closeAfter: function (callBack) {
if (callBack != null) callBack();
}
}
app = {
data: {
cols: [[
{ checkbox: true, fixed: true },
{ field: "id", width: 80, hide: true, title: "Id", noExel: true },
{ field: "keys", width: 80, hide: true, title: "keys", noExel: true },
{ field: "projectKeys", width: 80, hide: true, title: "projectKeys", noExel: true },
{ field: "projectName", width: 210, title: "项目" },
/* { field: "factoryName", width: 150, title: "厂房", noExel: true },*/
{ field: "equipmentCode", width: 240, title: "设备编号", hide: true },
{ field: "equipmentName", width: 220, title: "设备名称" },
{
field: "count", width: 150, title: "待保养部件数", templet: function (d) {
if (d.count > 0) {
return `<span style='color:red;'>${d.count}</span>`
}
return d.count;
}
},
]],
colsDesc: [[
{ checkbox: true, fixed: true },
{ field: "id", width: 80, hide: true, title: "Id", noExel: true },
{ field: "projectKeys", width: 80, hide: true, title: "projectKeys", noExel: true },
{ field: "topKeys", width: 80, hide: true, title: "topKeys", noExel: true },
{ field: "headKeys", width: 80, hide: true, title: "headKeys", noExel: true },
{ field: "equipmentCode", width: 200, title: "设备编号", hide: true },
{ field: "equipmentName", width: 200, title: "设备名称" },
{ field: "partCode", width: 100, title: "部件编码", hide: true },
{ field: "partName", width: 200, title: "部件名称" },
{ field: "lastMaintainTime", title: "上次保养时间", width: 180 },
{
field: "nextMaintainTime", title: "下次保养时间", width: 350, templet: function (d) {
const nextMaintenanceTime = moment(d.nextMaintainTime); // 下一次保养时间
const currentTime = moment();
const diffInDays = nextMaintenanceTime.diff(currentTime, 'days'); // 计算未来的时间差
const diffInHours = nextMaintenanceTime.diff(currentTime, 'hours');
if (diffInDays < 0) {
return `${d.nextMaintainTime}<span style='color:red;'>,逾期 ${Math.abs(diffInDays)} 天</span>`;
} else if (diffInDays === 0 && diffInHours > 0) {
// 如果是同一天但还有小时
return `${d.nextMaintainTime}<span style='color:red;'>,还有 1 天到下次保养</span>`;
} else if (diffInDays > 0 && diffInDays < 15) {
return `${d.nextMaintainTime}<span style='color:red;'>,还有 ${Math.ceil(diffInDays)} 天到下次保养</span>`;
} else if (diffInDays >= 15) {
return `${d.nextMaintainTime}<span style='color:green;'>,下次保养还有 ${Math.ceil(diffInDays)} 天</span>`;
}
return d.nextMaintainTime; // 默认情况下返回原始时间
}
},
{ field: "status", title: "保养状态", width: 100, templet: "#MaintainStatus" },
{
field: 'url', width: 300, title: '保养操作档案', templet: function (d) {
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
}
},
]],
tableIns: null,
tableElem: "mainList",
tableInsDesc: null,
tableElemDesc: "mainListDesc",
tree: $("#tree"),
treeObj: null,
setting: {
view: { selectedMulti: false },
async: {
enable: true,
url: `/${areaName}/${controllerName}/GetTreeList`,
type: "get"
},
data: {
simpleData: {
enable: true,
idKey: "keys",
pIdKey: "parentId",
rootPId: ""
}
},
callback: {
onClick: function (event, treeId, treeNode) {
sendDataWhereTree.projectKeys = treeNode.projectKeys;
sendDataWhereTree.projectCode = treeNode.keys;
sendDataWhereTree.projectName = treeNode.name;
app.methods.initTable(sendDataWhereTree);
element.tabChange(action.rowClickOptions().tabfilter, 1)
if (app.data.tableInsDesc != null) layui.table.reload(app.data.tableElemDesc, { url: '', data: [] })
//$("#eqMsgDetail").text(`设备部件列表`)
},
onAsyncSuccess: function (event, treeId, treeNode, msg) {
app.data.treeObj.expandAll(true);
$("#tree_2_a").click()
ztreeProjectData = JSON.parse(msg)
}
}
},
//下拉框配置
selectOption: {
selectFaultType: {
SelType: "FromDict",
SelFrom: `FaultType`,
SelLabel: "DictLabel",
SelValue: "DictValue",
Dom: [$("[name='FaultType']")]
},
selectHandling: {
SelType: "FromDict",
SelFrom: "Handling",
SelLabel: "DictLabel",
SelValue: "DictValue",
Dom: [$("[name='Handling']")]
},
selectReason: {
SelType: "FromDict",
SelFrom: "Reason",
SelLabel: "DictLabel",
SelValue: "DictValue",
Dom: [$("[name='Reason']")]
},
selectMaintainLevel: {
SelType: "FromDict",
SelFrom: "MaintainLevel",
SelLabel: "DictLabel",
SelValue: "DictValue",
Dom: [$("[name='MaintainLevel']")]
},
//返回的数据 用于后续操作
selectData: {
}
},
},
methods: {
initTable: function (opt) {
var config = {};
if (opt != undefined) $.extend(config, opt);
let options = {
elem: "#" + app.data.tableElem,
url: `/${areaName}/${controllerName}/Load`,
cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
toolbar: '#toolbarTable',
where: config,
height: "full-50",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
doneExtend: function (res, obj) {
setTimeout(() => {
app.data.tree.height($("div.layui-table-view").height() - 8);
}, 50);
}
}
app.data.tableIns = sysU.initTable(options);
},
initTableDesc: function (obj) {
//查询表单值
sendDataDescWhere = form.val("listFormDesc");
//主表附加设备值
sendDataDescWhere["topKeys"] = obj.data.keys;
sendDataDescWhere["equipmentCode"] = obj.data.equipmentCode;
let opt = {
cols: sysU.columnRecord(app.data.tableElemDesc, app.data.colsDesc),
elem: "#" + app.data.tableElemDesc,
url: `/${areaName}/${controllerName}/LoadDesc`,
height: 'full-50',
toolbar: '#toolbarTableDesc',
menuModule: controllerName,
areaMenus: 2,
where: sendDataDescWhere
}
app.data.tableInsDesc = sysU.initTable(opt);
$("#eqMsgDetail").text(`【${obj.data.equipmentName}】设备部件列表`)
},
initTree: function () {
app.data.treeObj = $.fn.zTree.init(app.data.tree, app.data.setting);
},
//树节点查询,目前树结构只有一级 所以不需要提供查询
filterNodes: function (list, searchText) {
var filterList = [];
list.forEach((ele) => {
if (ele.name.indexOf(searchText) > -1) {
filterList.push(ele);
}
});
return filterList;
},
//项目树搜索
queryProject(searchText) {
let setting = "".copyObj2(app.data.setting)
delete setting.async;
var data = app.methods.filterNodes(ztreeProjectData, searchText)
$.fn.zTree.init(app.data.tree, setting, data);
if (data.length > 0) {
app.data.treeObj.expandAll(true);
var ele = "tree_1_a";
if (data.length == ztreeProjectData.length) ele = "tree_2_a";
$("#" + ele).click()
}
},
initFrom() {
sysU.initSelect(app.data.selectOption);
sysU.tabClick("tableTabBody");
}
},
registerEvent: function () {
$("#queryProjectCode").bind('input propertychange', function () {
if (app.data.treeObj == null) return;
var searchText = $(this).val();
app.methods.queryProject(searchText);
})
},
init: function () {
//var sendDataWhere = form.val("listForm")
app.methods.initFrom();
app.methods.initTree();
app.registerEvent();
}
};
app.init();
});