2023-04-28 12:22:26 +08:00

303 lines
12 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//****************************设备管理和机器管理共用*****************************************/
function getDevicePairingLogsByDevice() {
$('#div_attlarge').empty();
if (deviceid) {
var cid = $('#sel_contractor').val();
devicerequest('GetDevicePairingLogsByDevice', JSON.stringify([cid, deviceid, ""]), function (data) {
if (data && typeof data != "string") {
showDevicePairingLogs(data, 0);
}
});
}
}
function getDevicePairingLogsByAsset() {
$('#div_attlarge').empty();
if (machineid) {
devicerequest('GetDevicePairingLogsByAsset', JSON.stringify([contractorid, machineid, ""]), function (data) {
if (data && typeof data != "string") {
showDevicePairingLogs(data, 1);
}
});
}
}
function OnExpendParingInfo(e) {
var t = $(e);
var tid = t.attr("target");
if (t.hasClass("iconchevrondown")) {
t.removeClass("iconchevrondown").addClass("iconchevronright");
$("#" + tid).hide();
}
else {
t.removeClass("iconchevronright").addClass("iconchevrondown");
$("#" + tid).show();
if (!t.data("loaded")) {
getPairingAttachments(t);
}
}
}
function showDevicePairingLogs(logs, type) {//0.device,1.asset
$('#div_attlarge').empty();
if (logs && logs.length > 0) {
for (var i = 0; i < logs.length; i++) {
var log = logs[i];
var trid = "paringinfo_tr" + log.Id;
var tab = $('<table class="main_table maintenance"></table>');
$('#div_attlarge').append(tab);
var tr = $('<tr style="line-height: 35px;"></tr>');
tab.append(tr);
var td = $('<td class="subtitle"></td>');
tr.append(td);
var spanexpend = $('<span class="sbutton iconchevronright woattafoldicon" target="' + trid + '" onclick="OnExpendParingInfo(this)" style="margin-left: 0; padding-right: 5px;"></span>').data('log', log).data('type', type);
td.append(spanexpend);
var spantitle = $('<span></span>').text(("Paired to {0} on {1} by {2}").replace('{0}', type === 0 ? log.AssetName : (log.SourceName + " " + log.SerialNumber)).replace('{1}', log.InstallTime_LocalStr).replace('{2}', log.InstallerName));
td.append(spantitle);
tr = $('<tr id="' + trid + '" class="tr_intervals woattafoldtr"></tr>').hide();
tab.append(tr);
td = $('<td id="paringinfo_td' + log.Id + '"></td>');
tr.append(td);
}
}
}
function getPairingAttachments(t) {
var cid = $('#sel_contractor').val();
var pairinglog = $(t).data('log');
var type = $(t).data('type');
devicerequest('GetPairingAttachments', JSON.stringify([cid, pairinglog.Id]), function (data) {
if (data && typeof data != "string") {
$(t).data('loaded', true);
showPairingAttachments(pairinglog, data, type);
}
});
}
function arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
function getPairingSignature(pairinglogid, logtab) {
devicerequest('GetPairingSignature', JSON.stringify(pairinglogid), function (data) {
if (data && data != null && data.length > 0) {
var logtr = $('<tr></tr>');
logtab.append(logtr);
var logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Signature: '));
logtr.append(logtd);
logtd = $('<td colspan="3"></td>');
logtr.append(logtd);
var jpeg = data;
if (typeof (data) !== "string") {
jpeg = arrayBufferToBase64(data);
}
var imgsig = $('<img style="height: 110px;" />').attr('src', 'data:image/png;base64,' + jpeg);
$(logtd).append(imgsig);
}
});
}
function getPairingAttachmentCategory(key) {
switch (key) {
case "Odometer":
return GetTextByKey("P_XXXX", "Odometer");
case "Engine Hours":
return GetTextByKey("P_XXXX", "Engine Hours");
case "Mounting Location":
return GetTextByKey("P_XXXX", "Mounting Location");
case "Power Connection":
return GetTextByKey("P_XXXX", "Power Connection");
case "Ground Connection":
return GetTextByKey("P_XXXX", "Ground Connection");
case "Ignition Connection":
return GetTextByKey("P_XXXX", "Ignition Connection");
case "Asset Number":
return GetTextByKey("P_XXXX", "Asset Number");
case "Left Front of Asset":
return GetTextByKey("P_XXXX", "Left Front of Asset");
case "Right Rear of Asset":
return GetTextByKey("P_XXXX", "Right Rear of Asset");
case "VIN":
return GetTextByKey("P_XXXX", "VIN");
case "ESN of GPS Device":
return GetTextByKey("P_XXXX", "ESN of GPS Device");
default:
break;
}
return key;
}
var imgTypes = [".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"];
var printTypes = ['.pdf', ".jfif", ".jpg", ".jpeg", ".bmp", ".png", ".tiff", ".gif"];//types to be loaded to print
function showPairingAttachments(pairinglog, attas, type) {//0.device,1.asset
var ptd = $('#paringinfo_td' + pairinglog.Id);
ptd.empty();
var log = pairinglog;
//Mountion LocationEngineHoursOdometer
var divinfo = $('<div class="edit-content"></div>');
var logtab = $('<table class="tab_deviceparing"></table>');
divinfo.append(logtab);
var logtr = $('<tr></tr>');
logtab.append(logtr);
var logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Date Time:'));
logtr.append(logtd);
logtd = $('<td style="width:300px;"></td>').text(log.InstallTime_LocalStr);
logtr.append(logtd);
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Installer:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.InstallerName);
logtr.append(logtd);
logtr = $('<tr></tr>');
logtab.append(logtr);
if (type == 0) {
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'VIN:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.AssetVIN);
logtr.append(logtd);
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Asset Name:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.AssetName);
logtr.append(logtd);
}
else {
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Device SN:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.SerialNumber);
logtr.append(logtd);
logtd = $('<td class="label" style="width:130px;"></td>').text(GetTextByKey('P_XXXX', 'Source:'));
logtr.append(logtd);
logtd = $('<td></td>').text(log.SourceName);
logtr.append(logtd);
}
logtr = $('<tr></tr>');
logtab.append(logtr);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Engine Hours: '));
logtr.append(logtd);
logtd = $('<td></td>').text(log.EngineHours < 0 ? '' : log.EngineHours.toLocaleString());
logtr.append(logtd);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Odometer: '));
logtr.append(logtd);
logtd = $('<td></td>').text(log.Odometer < 0 ? '' : (log.Odometer.toLocaleString() + " " + log.OdometerUnit));
logtr.append(logtd);
logtr = $('<tr></tr>');
logtab.append(logtr);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Mounting Location:'));
logtr.append(logtd);
logtd = $('<td colspan="3"></td>').text(log.MountionLocation);
logtr.append(logtd);
logtr = $('<tr></tr>');
logtab.append(logtr);
logtd = $('<td class="label"></td>').text(GetTextByKey('P_XXXX', 'Notes: '));
logtr.append(logtd);
logtd = $('<td colspan="3"></td>').text(log.Notes);
logtr.append(logtd);
getPairingSignature(log.Id, logtab);
ptd.append(divinfo);
if (attas && attas.length > 0) {
for (var i = 0; i < attas.length; i++) {
var att = attas[i];
var category_str = att.Category.replace(/\s+/g, '').toLowerCase();
var div_atts = $('#divatt_' + pairinglog.Id + "_" + category_str);
if (div_atts.length == 0) {
div_atts = $('<div id="divatt_' + pairinglog.Id + "_" + category_str + '" style="min-height: 80px; overflow: auto; padding-left: 20px;"></div>');
ptd.append(div_atts);
var div1 = $('<div style=" margin-top: 15px;margin-bottom:5px;"></div>');
var ext_span = $('<span style="font-weight:500;font-size:16px;"></span>').text(getPairingAttachmentCategory(att.Category));
div1.append(ext_span);
div_atts.append(div1);
}
}
for (var i = 0; i < attas.length; i++) {
var att = attas[i];
var category_str = att.Category.replace(/\s+/g, '').toLowerCase();
var div_atts = $('#divatt_' + pairinglog.Id + "_" + category_str);
var pdiv = $('<div class="divattp"></div>');
var div = createAttaDiv(att, true);
var div1 = $('<div style=" margin-top: 15px;"></div>');
var sdownload = $('<span class="attadownload"></span>').attr('title', GetTextByKey("P_WO_DOWNLOAD", 'Download')).click(att, function (e) {
openDownloadFrame(e.data.FullSizeUrl + "&d=1");
});
div.append(sdownload);
pdiv.append(div);
var caption = att.FileName;
var div3 = $('<div style="text-align:center;clear:both;"></div>');
var iptcaption = $('<input type="text" style="width: 196px;height:24px;border:1px solid #fff;" class="inp_name" maxlength="200"/>').attr('data-ori', caption).val(caption);
iptcaption.data('attdata', att);
div3.append(iptcaption);
pdiv.append(div3);
div_atts.append(pdiv);
}
}
}
function createAttaDiv(att) {
var div = $('<div class="divatt"></div>').attr('title', att.FileName).attr('title', att.Notes === "" ? att.FileName : att.Notes)
if (!att.FileType || att.FileType == "") att.FileType = ".jpg";
if (imgTypes.indexOf(att.FileType.toLowerCase()) >= 0) {
var pic = $('<img class="picture"></img>').attr('src', att.ThumbnailUrl);
pic.click(att, function (e) {
window.open(e.data.FullSizeUrl, "_blank")
});
div.append(pic);
}
else {
var sdown = $('<img class="picture" />').click(att, function (e) {
window.open(e.data.FullSizeUrl);
});
setAttachemntIcon(att.FileType, sdown);
div.append(sdown);
}
return div
}
function openPrintFrame(attatype, id) {
var frame = $("<iframe style='display:none;'></iframe>");
$(document.body).after(frame);
//frame.attr("src", url);
frame.attr("src", _network.root + "Print.aspx?pt=3&at=" + attatype + "&id=" + id);
frame.on('load', function () {
setTimeout(function () {
frame.contents().find("body").css("text-align", "center");
//frame.contents().find("img").css("max-height", window.screen.availHeight).css("max-width", window.screen.availWidth);
frame.contents().find("img").css("max-height", "98%").css("max-width", "98%");
frame[0].contentWindow.print();
});
setTimeout(function () {
frame.remove();
}, 60000);
});
}
function openDownloadFrame(url) {
var frame = $("<iframe style='display:none;'></iframe>");
$(document.body).after(frame);
frame.attr("src", url);
var timer = setInterval(function () {
if (frame[0].contentDocument && (frame[0].contentDocument.readyState == "complete" || frame[0].contentDocument.readyState == 4)) {
frame.remove();
clearInterval(timer);
}
}, 5000);
}