layui.use(['table','laydate', 'form'], function(){
|
var $ = layui.jquery;
|
var layer = layui.layer;
|
var form = layui.form;
|
var locMapRefreshTimer = null;
|
var locMapDocVisible = !document.hidden;
|
var locMapFrameVisible = true;
|
|
function locMapIframeUsable() {
|
try {
|
var fe = window.frameElement;
|
if (!fe) {
|
return true;
|
}
|
var doc = fe.ownerDocument;
|
var win = doc.defaultView || window.parent;
|
var el = fe;
|
while (el) {
|
var st = win.getComputedStyle(el);
|
if (st.display === 'none' || st.visibility === 'hidden' || Number(st.opacity) === 0) {
|
return false;
|
}
|
el = el.parentElement;
|
}
|
var r = fe.getBoundingClientRect();
|
return r.width >= 1 && r.height >= 1;
|
} catch (e) {
|
return true;
|
}
|
}
|
|
function locMapHeatmapPageActive() {
|
return locMapDocVisible && locMapFrameVisible && locMapIframeUsable();
|
}
|
|
function clearLocMapRefresh() {
|
if (locMapRefreshTimer) {
|
clearInterval(locMapRefreshTimer);
|
locMapRefreshTimer = null;
|
}
|
}
|
|
function updateLocMapRefreshTimer() {
|
clearLocMapRefresh();
|
var ms = parseInt($('#locMapRefreshSelect').val(), 10) || 0;
|
if (ms <= 0 || !locMapHeatmapPageActive()) {
|
return;
|
}
|
locMapRefreshTimer = setInterval(function () {
|
if (!locMapHeatmapPageActive()) {
|
return;
|
}
|
var row = $('#rowSelect').val();
|
if (row) {
|
getLocTable(row);
|
}
|
}, ms);
|
}
|
|
function resumeLocMapAutoRefresh() {
|
var ms = parseInt($('#locMapRefreshSelect').val(), 10) || 0;
|
var row = $('#rowSelect').val();
|
if (ms > 0 && row && locMapHeatmapPageActive()) {
|
getLocTable(row, true);
|
}
|
updateLocMapRefreshTimer();
|
}
|
|
getLocMapRows();
|
getLocTable(1, true);
|
updateLocMapRefreshTimer();
|
|
if (typeof IntersectionObserver !== 'undefined') {
|
var locMapIo = new IntersectionObserver(function (entries) {
|
var e = entries[0];
|
var next = !!(e && e.isIntersecting && e.intersectionRatio > 0);
|
if (next === locMapFrameVisible) {
|
return;
|
}
|
locMapFrameVisible = next;
|
if (locMapFrameVisible) {
|
resumeLocMapAutoRefresh();
|
} else {
|
updateLocMapRefreshTimer();
|
}
|
}, { threshold: [0, 0.01, 1] });
|
var locMapHold = document.getElementById('locMapContain');
|
if (locMapHold) {
|
locMapIo.observe(locMapHold);
|
}
|
}
|
|
function getLocMapRows() {
|
$.ajax({
|
url: baseUrl+"/report/viewLocMapList/rows.action",
|
headers: {'token': localStorage.getItem('token')},
|
method: 'POST',
|
async: false,
|
success: function (res) {
|
if (res.code === 200) {
|
var tpl = $("#locMastRowTemplate").html();
|
var template = Handlebars.compile(tpl);
|
var html = template(res);
|
$('#rowSelect').append(html);
|
form.render('select');
|
} else if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
});
|
}
|
|
function getLocTable(row, force) {
|
if (!force && !locMapHeatmapPageActive()) {
|
return;
|
}
|
$.ajax({
|
url: baseUrl+"/report/viewLocMapList.action",
|
headers: {'token': localStorage.getItem('token')},
|
data: {row: row},
|
method: 'POST',
|
success: function (res) {
|
if (res.code === 200) {
|
var tpl = $("#locMapTemplate").html();
|
var template = Handlebars.compile(tpl);
|
var html = template(res.data);
|
$('#locMap').html(html);
|
} else if (res.code === 403) {
|
top.location.href = baseUrl+"/";
|
} else {
|
layer.msg(res.msg)
|
}
|
}
|
});
|
}
|
|
form.on('select(row)', function (data) {
|
getLocTable(data.value, true);
|
});
|
|
form.on('select(locMapRefresh)', function () {
|
updateLocMapRefreshTimer();
|
});
|
|
$(window).on('beforeunload', function () {
|
clearLocMapRefresh();
|
});
|
|
document.addEventListener('visibilitychange', function () {
|
locMapDocVisible = !document.hidden;
|
if (locMapDocVisible) {
|
resumeLocMapAutoRefresh();
|
} else {
|
updateLocMapRefreshTimer();
|
}
|
});
|
|
function copyLocMapText(text) {
|
if (!text) {
|
return;
|
}
|
if (navigator.clipboard && navigator.clipboard.writeText) {
|
navigator.clipboard.writeText(text).then(function () {
|
layer.msg('已复制');
|
}, function () {
|
copyLocMapTextLegacy(text);
|
});
|
} else {
|
copyLocMapTextLegacy(text);
|
}
|
}
|
|
function copyLocMapTextLegacy(text) {
|
var ta = document.createElement('textarea');
|
ta.value = text;
|
ta.style.position = 'fixed';
|
ta.style.left = '-9999px';
|
document.body.appendChild(ta);
|
ta.select();
|
try {
|
document.execCommand('copy');
|
layer.msg('已复制');
|
} catch (e) {
|
layer.msg('复制失败');
|
}
|
document.body.removeChild(ta);
|
}
|
|
$(document).on('click', '#locMapContain .loc-map-locno-badge', function (e) {
|
e.stopPropagation();
|
e.preventDefault();
|
copyLocMapText($(this).attr('data-copy-loc'));
|
});
|
$(document).on('click', '#locMapContain .loc-map-bar', function (e) {
|
e.stopPropagation();
|
e.preventDefault();
|
copyLocMapText($(this).attr('data-copy-bar'));
|
});
|
$(document).on('click', '#locMapContain .loc-map-maktx', function (e) {
|
e.stopPropagation();
|
e.preventDefault();
|
var $td = $(this).closest('td.a-loc');
|
var no = ($(this).attr('data-loc-no') || $td.attr('title') || '').trim();
|
var sts = ($td.attr('data-loc-sts') || '').trim();
|
locDetlOpen(no, sts);
|
});
|
});
|
|
var locNo = '';
|
|
function locDetlOpen(value, sts) {
|
if (value === null || value === undefined || String(value).trim() === ''
|
|| sts === 'S' || sts === 'D' || sts === 'O' || sts === 'Z') {
|
return;
|
}
|
layer.open({
|
type: 2,
|
title: '库位物料',
|
maxmin: true,
|
area: [top.detailWidth, top.detailHeight],
|
shadeClose: true,
|
content: 'locDetl.html',
|
success: function (layero, index) {
|
locNo = value;
|
}
|
});
|
}
|
|
function locDetl(el) {
|
locDetlOpen($(el).attr('title'), ($(el).attr('data-loc-sts') || '').trim());
|
}
|