let table, layer, form, laydate; let avgTasksChart = null; let equipmentUsageChart = null; let bidCode = parent.parent.$('#bidPro').val(); // 获取当天日期 function getTodayDate() { const now = new Date(); const year = now.getFullYear(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); return year + '-' + month + '-' + day; } // 获取当月第一天和最后一天(保留用于其他功能) function getCurrentMonthRange() { const now = new Date(); const year = now.getFullYear(); const month = now.getMonth(); // 当月第一天 const firstDay = new Date(year, month, 1); const startDate = year + '-' + String(month + 1).padStart(2, '0') + '-' + String(firstDay.getDate()).padStart(2, '0'); // 当月最后一天 const lastDay = new Date(year, month + 1, 0); const endDate = year + '-' + String(month + 1).padStart(2, '0') + '-' + String(lastDay.getDate()).padStart(2, '0'); return { startDate, endDate }; } const today = getTodayDate(); let queryParams = { projectId: bidCode, startTestDay: today, endTestDay: today, startTime: today, endTime: today, } layui.use(["layer", "table", "form", "laydate"], function () { layer = layui.layer; table = layui.table; form = layui.form; laydate = layui.laydate; // 响应成功后的拦截器 $.ajaxSetup({ beforeSend: function (xhr, options) { var originalSuccess = options.success; options.success = function (data, textStatus, jqXhr) { data = modifyResponseData(data); originalSuccess.apply(this, arguments); }; }, }); // 初始化页面 initPage(); // 初始化日期范围选择器 initDateRangePicker(); }); // 初始化页面 function initPage() { initPersonnelTables(); getTop5Personnel(); getBottom5Personnel(); getTradeProportionAndAvgTasks(); getEquipmentUsageAndFailureRank(); getEquipmentFailureRank(); initTradeProportion(); initAvgTasksChart(); initEquipmentUsageChart(); initEquipmentFailureList(); initWarningTable(); initMockData(); initFileUploadHandler(); } // 获取人员数据中的班组利用率排名前五名的 function getTop5Personnel() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/selectTopList' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateTop5PersonnelTable(data); }, aqEnnable); } // 获取后5名人员数据 function getBottom5Personnel() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/selectDownList' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateBottom5PersonnelTable(data); }, aqEnnable); } // 获取各工种任务占比和人均任务数 function getTradeProportionAndAvgTasks() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/getWorkTypeRate' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateTradeProportion(data); updateAvgTasksChart(data); }, aqEnnable); } // 获取设备使用率 function getEquipmentUsageAndFailureRank() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/getWeeksDevData' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateEquipmentUsageChart(data); }, aqEnnable); } // 获取设备故障排名 function getEquipmentFailureRank() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/getDevErrTop' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateEquipmentFailureList(data); }, aqEnnable); } // 获取工程进度 function getEngineeringProgress() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/getProProgress' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateEngineeringProgress(data); }, aqEnnable); } getEngineeringProgress() // 更新工程进度展示(取 data[0] 的 planProgress、progress) function updateEngineeringProgress(data) { if (!data || !Array.isArray(data) || data.length === 0) { return; } const item = data[0]; const planProgress = parseFloat(item.planProgress || 0); const progress = parseFloat(item.progress || 0); $('#plannedProgressText').text(planProgress.toFixed(1) + '%'); $('#actualProgressText').text(progress.toFixed(1) + '%'); // 进度条宽度归一化,两者之和为 100% const total = planProgress + progress; const planPercent = total > 0 ? (planProgress / total * 100) : 50; const actualPercent = total > 0 ? (progress / total * 100) : 50; $('#actualProgressFill').css('width', actualPercent + '%'); $('#plannedProgressFill').css('width', planPercent + '%'); } // 获取分析预警 function getAnalysisWarning() { const url = commonUrl + 'screen/largeScreen/sjNewOverall/getWarnList' + '?bidCode=' + (bidCode || '') + '&startTime=' + (queryParams.startTime || '') + '&endTime=' + (queryParams.endTime || ''); ajaxRequestGet(url, 'GET', true, function () { }, function (result) { let data = []; if (result && result.data && Array.isArray(result.data)) { data = result.data; } else if (result && Array.isArray(result)) { data = result; } else if (result && result.rows && Array.isArray(result.rows)) { data = result.rows; } updateAnalysisWarningTable(data); }, aqEnnable); } getAnalysisWarning() // 更新分析预警表格(data 直接渲染) function updateAnalysisWarningTable(data) { if (!table) return; table.reload('warningTable', { data: data || [] }); } // 防抖函数 function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // 初始化日期范围选择器 function initDateRangePicker() { // 设置初始显示值为当天范围 const initialValue = queryParams.startTestDay + ' ~ ' + queryParams.endTestDay; $('#dateRange').val(initialValue); // 使用范围选择器,单个输入框显示日期范围 laydate.render({ elem: '#dateRange', type: 'date', range: true, format: 'yyyy-MM-dd', theme: 'dark', value: queryParams.startTestDay + ' - ' + queryParams.endTestDay, done: function (value, date, endDate) { // 重置为当天日期的函数 const resetToToday = function () { const today = getTodayDate(); queryParams.startTestDay = today; queryParams.endTestDay = today; queryParams.startTime = today; queryParams.endTime = today; $('#dateRange').val(today + ' ~ ' + today); refreshAllModules(); }; if (value && value.trim() !== '') { const dates = value.split(' - '); if (dates.length === 2) { const startDate = dates[0].trim(); const endDateStr = dates[1].trim(); $('#dateRange').val(startDate + ' ~ ' + endDateStr); queryParams.startTestDay = startDate; queryParams.endTestDay = endDateStr; queryParams.startTime = startDate; queryParams.endTime = endDateStr; refreshAllModules(); } else { resetToToday(); } } else { resetToToday(); } } }); } // 刷新所有模块数据 function refreshAllModules() { getTop5Personnel(); getBottom5Personnel(); getTradeProportionAndAvgTasks(); getEquipmentUsageAndFailureRank(); getEquipmentFailureRank(); if (avgTasksChart) { initAvgTasksChart(); } if (equipmentUsageChart) { initEquipmentUsageChart(); } if (table) { table.reload('warningTable'); } } // 初始化人员数据表格(前5名和后5名) function initPersonnelTables() { // 前5名表格 table.render({ elem: '#top5PersonnelTable', id: 'top5PersonnelTable', data: [], skin: 'line', page: false, height: 'full', cols: [[ { type: 'numbers', title: '序号', width: '10%', align: 'center' }, { field: 'workType', title: '专业', width: '15%', align: 'center' }, { field: 'teamName', title: '班组', width: '20%', align: 'center' }, { field: 'teamLeader', title: '班组负责人', width: '18%', align: 'center' }, { field: 'teamPeople', title: '班组人数', width: '12%', align: 'center' }, { field: 'dutyPeople', title: '当日到岗', width: '12%', align: 'center' }, { field: 'userRate', title: '利用率', width: '13%', align: 'center', templet: function (d) { const rate = d.userRate || '0.00%'; return rate; } } ]] }); // 后5名表格 table.render({ elem: '#bottom5PersonnelTable', id: 'bottom5PersonnelTable', data: [], skin: 'line', page: false, height: 'full', cols: [[ { type: 'numbers', title: '序号', width: '10%', align: 'center' }, { field: 'workType', title: '专业', width: '15%', align: 'center' }, { field: 'teamName', title: '班组', width: '20%', align: 'center' }, { field: 'teamLeader', title: '班组负责人', width: '18%', align: 'center' }, { field: 'teamPeople', title: '班组人数', width: '12%', align: 'center' }, { field: 'dutyPeople', title: '当日到岗', width: '12%', align: 'center' }, { field: 'userRate', title: '利用率', width: '13%', align: 'center', templet: function (d) { const rate = d.userRate || '0.00%'; return rate; } } ]] }); } // 更新前5名人员表格数据 function updateTop5PersonnelTable(data) { if (!table || !data || !Array.isArray(data)) return; table.reload('top5PersonnelTable', { data: data }); } // 更新后5名人员表格数据 function updateBottom5PersonnelTable(data) { if (!table || !data || !Array.isArray(data)) return; table.reload('bottom5PersonnelTable', { data: data }); } // 初始化各工种任务占比(六边形卡片) function initTradeProportion() { // 初始化为空,等待接口数据 const container = document.getElementById('tradeProportionContainer'); if (!container) return; container.innerHTML = ''; } // 更新各工种任务占比(六边形卡片) function updateTradeProportion(data) { if (!data || !Array.isArray(data) || data.length === 0) { const container = document.getElementById('tradeProportionContainer'); if (container) { container.innerHTML = ''; } return; } // 计算总任务数 const totalTasks = data.reduce((sum, item) => { const taskNum = parseFloat(item.taskNum || 0); return sum + taskNum; }, 0); // 计算每个工种的占比 const proportionData = data.map(function (item) { const taskNum = parseFloat(item.taskNum || 0); const percentage = totalTasks > 0 ? (taskNum / totalTasks * 100).toFixed(2) : 0; return { value: parseFloat(percentage), label: item.workType || '' }; }); const container = document.getElementById('tradeProportionContainer'); if (!container) return; const html = proportionData.map(function (item) { return `