ah_jjzhgd_webscreen/js/pages/newDataAnalysis/proQualityAnalysis.js

401 lines
14 KiB
JavaScript
Raw Normal View History

2025-07-23 16:27:32 +08:00
let table, layer, form;
2025-07-23 23:06:00 +08:00
let myChart = null,
myChart2 = null;
layui.use(["layer", "table", "form"], function () {
2025-07-23 16:27:32 +08:00
layer = layui.layer;
table = layui.table;
form = layui.form;
// 响应成功后的拦截器
$.ajaxSetup({
beforeSend: function (xhr, options) {
2025-07-23 23:06:00 +08:00
var originalSuccess = options.success;
2025-07-23 16:27:32 +08:00
options.success = function (data, textStatus, jqXhr) {
data = modifyResponseData(data);
// success(data,textStatus, jqXhr);
2025-07-23 23:06:00 +08:00
originalSuccess.apply(this, arguments);
};
},
});
initTable(1, parent.$("#bidPro").val());
2025-07-23 16:27:32 +08:00
});
/* 切换数据 */
function changeData(that, type) {
2025-07-23 23:06:00 +08:00
const bidCode = parent.$("#bidPro").val();
2025-07-23 16:27:32 +08:00
$(".ul-box li").each(function () {
if ($(this).hasClass("check")) {
$(this).removeClass("check").addClass("nocheck");
}
});
2025-07-23 23:06:00 +08:00
var tableElem = $("#demo2").parents(".layui-table-view");
2025-07-23 16:27:32 +08:00
tableElem.remove();
$(that).removeClass("nocheck").addClass("check");
if (type === 1 || type === 2 || type === 3 || type === 6 || type === 12) {
initTable(type, bidCode);
2025-07-23 23:06:00 +08:00
$("#right-table-box").removeAttr("style");
$("#no-data-box").css({ display: "none" });
$("#right-box").css({ display: "none" });
2025-07-23 16:27:32 +08:00
}
}
function initTable(type, bidCode) {
2025-07-23 23:06:00 +08:00
const url =
commonUrl + "screen/largeScreen/dataAnalysis/getEngqualityAnalysis";
2025-07-23 16:27:32 +08:00
table.render({
2025-07-23 23:06:00 +08:00
elem: "#demo2",
2025-07-23 16:27:32 +08:00
url: url,
2025-07-23 23:06:00 +08:00
skin: "line",
2025-07-23 16:27:32 +08:00
page: true,
2025-07-23 23:06:00 +08:00
height: "full-100",
2025-07-23 16:27:32 +08:00
headers: {
2025-07-23 23:06:00 +08:00
decrypt: "decrypt",
Authorization: token,
2025-07-23 16:27:32 +08:00
},
where: {
bidCode: bidCode,
2025-07-23 23:06:00 +08:00
type: type,
2025-07-23 16:27:32 +08:00
},
cols: [setCols(type)],
initComplete: function () {
// 在表格渲染完成后,重新渲染序号列
var that = this.elem.next();
2025-07-23 23:06:00 +08:00
var tool = that
.children(".layui-table-box")
.children(".layui-table-fixed")
.children(".layui-table-body")
.children(".layui-table");
2025-07-23 16:27:32 +08:00
tool.find("tr").each(function (index, item) {
2025-07-23 23:06:00 +08:00
$(this)
.find('td[data-field="LAY_TABLE_INDEX"]')
.text(index + 1);
2025-07-23 16:27:32 +08:00
});
},
done: function (res, curr, count, origin) {
2025-07-23 22:31:39 +08:00
if (res.data && res.data.length > 0) {
initEcharts(res.data);
}
2025-07-23 23:06:00 +08:00
// $(".layui-table-body table.layui-table tbody tr").on(
// "click",
// function () {
// // 获取当前行的数据
// var index = $(this).index();
// var rowData = res.data[index]; // 获取对应行的数据
// const passRate = rowData.passRate || 0;
// const noPassRate = rowData.noPassRate || 0;
// // initEchartsOne(passRate, noPassRate);
// // 增加一个 400 * 400 的弹框把饼图放进去 并修改弹框背景样式为透明
// layer.open({
// type: 1,
// title: "合格率对比",
// content: "<div id='oneEcharts'></div>",
// area: ["600px", "600px"],
// });
// initEchartsOne(passRate, noPassRate);
// }
// );
$(".layui-table-body table.layui-table tbody tr").on(
"click",
function () {
// 获取当前行的数据
var index = $(this).index();
var rowData = res.data[index]; // 获取对应行的数据
const passRate = rowData.passRate || 0;
const noPassRate = rowData.noPassRate || 0;
// 弹框配置
layer.open({
type: 1,
title: "合格率对比",
content:
"<div id='oneEcharts' style='width:100%;height:100%;'></div>",
area: ["600px", "600px"],
shade: 0.3, // 遮罩透明度
skin: "custom-layer-style", // 自定义皮肤
success: function (layero, index) {
// 修改弹框背景颜色
$(layero).css(
"background",
"rgba(13, 34, 37, 0.9)"
); // 半透明黑色背景
$(layero).find(".layui-layer-title").css({
color: "#fff", // 标题文字颜色
background: "transparent", // 标题背景透明
"border-bottom":
"1px solid rgba(255, 255, 255, 0.2)", // 标题底部边框
});
$(layero).find(".layui-layer-content").css({
background: "transparent", // 内容区域透明
});
$(layero)
.find(".layui-layer-setwin .layui-layer-close")
.css({
color: "#fff", // 文字颜色
"border-color": "#fff", // 边框颜色(如果按钮有边框)
});
// 重新渲染 ECharts因为 DOM 刚被创建)
setTimeout(() => {
initEchartsOne(passRate, noPassRate);
}, 100);
},
});
}
);
},
});
2025-07-23 16:27:32 +08:00
function setCols(type) {
2025-07-23 23:06:00 +08:00
if (type === 1) {
// 工程质量分析
2025-07-23 16:27:32 +08:00
return [
2025-07-23 23:06:00 +08:00
{ type: "numbers", title: "序号", width: "10%" }, // 添加序号列
{ field: "projectName", title: "工程名称", align: "center" },
2025-07-23 22:31:39 +08:00
// { field: 'projectNumber', title: '工程编号', align: 'center'},
// { field: 'projectAddress', title: '项目地址', align: 'center'},
// { field: 'contractorName', title: '承包商名称', align: 'center',},
// { field: 'qualityLevel', title: '质量等级', align: 'center'},
2025-07-23 23:06:00 +08:00
{ field: "projectManager", title: "项目经理", align: "center" },
2025-07-24 13:34:17 +08:00
{ field: "team", title: "施工队伍", align: "center" },
2025-07-23 23:06:00 +08:00
{ field: "startTime", title: "开始时间", align: "center" },
{ field: "checkNum", title: "检查数量", align: "center" },
{ field: "passNum", title: "合格数量", align: "center" },
{ field: "passRate", title: "合格率", align: "center" },
{ field: "score", title: "得分", align: "center" },
{
field: "unqualifiedItems",
title: "不合格原因",
align: "center",
},
2025-07-24 13:34:17 +08:00
/* {
2025-07-23 23:06:00 +08:00
title: "操作",
align: "center",
templet: function (row) {
2025-07-23 22:31:39 +08:00
// 注意Layui 的 templet 函数参数是 row即当前行数据
return `
<button class="layui-btn layui-btn-xs" onclick="handleUpload('${row.projectNumber}')">
上传
</button>
`;
2025-07-23 23:06:00 +08:00
},
2025-07-24 13:34:17 +08:00
},*/
2025-07-23 16:27:32 +08:00
];
}
}
2025-07-23 22:31:39 +08:00
}
// 初始化 echarts
function initEcharts(data) {
if (myChart && myChart2) {
myChart.dispose();
myChart2.dispose();
}
2025-07-23 23:06:00 +08:00
myChart2 = echarts.init(document.getElementById("rightLineBox"));
2025-07-23 22:31:39 +08:00
initEchartsTwo(data);
}
2025-07-24 13:34:17 +08:00
layui.use('upload', function () {
var upload = layui.upload;
// 执行上传
upload.render({
elem: '#uploadBtn', // 绑定元素
url: commonUrl + "screen/largeScreen/dataAnalysis/uploadProQuality",
accept: 'file', // 允许上传任意文件
exts: 'docx', // 允许的文件类型
size: 1024 * 10, // 限制文件大小,单位 KB10MB
headers: {
decrypt: "decrypt",
Authorization: token,
},
before: function (obj) {
// 上传前回调
layer.msg('上传中...', { icon: 16, time: 0 });
},
done: function (res) {
// 上传完成后回调(成功)
layer.closeAll('loading');
layer.msg('上传成功');
console.log('服务器返回:', res);
// 显示文件名或路径
document.getElementById('fileName').innerText = '已上传文件:' + res.fileName;
},
error: function () {
// 上传失败回调
layer.msg('上传失败', { icon: 5 });
}
});
});
2025-07-23 22:31:39 +08:00
2025-07-23 23:06:00 +08:00
function initEchartsOne(passRate, noPassRate) {
2025-07-23 22:31:39 +08:00
// 从传入的数据中提取 passRate 和 noPassRate并转为数字
2025-07-23 23:06:00 +08:00
// const passRate = parseFloat(pieData.passRate);
// const noPassRate = parseFloat(pieData.noPassRate);
myChart = echarts.init(document.getElementById("oneEcharts"));
console.log(passRate, noPassRate, "passRate, noPassRate");
2025-07-23 22:31:39 +08:00
const option = {
grid: {
top: 0,
bottom: 0,
left: 0,
right: 0,
},
title: {
x: "center",
2025-07-23 23:06:00 +08:00
textStyle: {
color: "#fff",
},
2025-07-23 22:31:39 +08:00
},
tooltip: {
trigger: "item",
2025-07-23 23:06:00 +08:00
formatter: "{b}: {c}%",
2025-07-23 22:31:39 +08:00
},
legend: {
show: true,
2025-07-23 23:06:00 +08:00
data: ["合格率", "不合格率"],
bottom: 10,
textStyle: {
color: "#fff",
},
2025-07-23 22:31:39 +08:00
},
series: [
{
name: "合格率分析",
type: "pie",
2025-07-23 23:06:00 +08:00
radius: "50%",
2025-07-23 22:31:39 +08:00
center: ["50%", "50%"],
label: {
show: true,
2025-07-23 23:06:00 +08:00
formatter: "{b}: {c}%",
2025-07-23 22:31:39 +08:00
},
data: [
2025-07-23 23:06:00 +08:00
{ value: parseFloat(passRate), name: "合格率" },
{ value: parseFloat(noPassRate), name: "不合格率" },
2025-07-23 22:31:39 +08:00
],
itemStyle: {
borderRadius: 5,
2025-07-23 23:06:00 +08:00
borderColor: "#fff",
borderWidth: 2,
},
},
],
2025-07-23 22:31:39 +08:00
};
// 设置图表(假设你已定义 myChart2
myChart.setOption(option, true);
window.addEventListener("resize", function () {
myChart.resize();
});
}
function initEchartsTwo(data) {
2025-07-23 23:06:00 +08:00
const teams = data.map((item) => item.team);
const scores = data.map((item) => item.score);
2025-07-23 22:31:39 +08:00
const option = {
title: {
2025-07-23 23:06:00 +08:00
text: "队伍得分柱状图",
left: "center",
2025-07-23 22:31:39 +08:00
textStyle: {
2025-07-23 23:06:00 +08:00
color: "#fff",
},
2025-07-23 22:31:39 +08:00
},
tooltip: {
2025-07-23 23:06:00 +08:00
trigger: "axis",
2025-07-23 22:31:39 +08:00
axisPointer: {
2025-07-23 23:06:00 +08:00
type: "none", // 移除鼠标悬停时的阴影效果
2025-07-23 22:31:39 +08:00
},
2025-07-23 23:06:00 +08:00
formatter: function (params) {
2025-07-23 22:31:39 +08:00
// 自定义tooltip显示内容移除了百分号
2025-07-23 23:06:00 +08:00
return (
params[0].name +
"<br/>" +
params[0].seriesName +
": " +
params[0].value
);
},
2025-07-23 22:31:39 +08:00
},
grid: {
2025-07-23 23:06:00 +08:00
left: "10%",
right: "10%",
bottom: "20%",
top: "20%",
containLabel: true,
2025-07-23 22:31:39 +08:00
},
xAxis: {
2025-07-23 23:06:00 +08:00
type: "category",
2025-07-23 22:31:39 +08:00
data: teams,
axisLabel: {
2025-07-23 23:06:00 +08:00
color: "#fff",
2025-07-23 22:31:39 +08:00
interval: 0,
2025-07-23 23:06:00 +08:00
formatter: function (value) {
2025-07-23 22:31:39 +08:00
// 每4个字符换行
2025-07-23 23:06:00 +08:00
return value.match(/.{1,4}/g).join("\n");
},
2025-07-23 22:31:39 +08:00
},
axisLine: {
lineStyle: {
2025-07-23 23:06:00 +08:00
color: "#fff",
},
},
2025-07-23 22:31:39 +08:00
},
yAxis: {
2025-07-23 23:06:00 +08:00
type: "value",
name: "得分",
2025-07-23 22:31:39 +08:00
min: 0,
max: 100,
interval: 10,
axisLabel: {
2025-07-23 23:06:00 +08:00
color: "#fff",
formatter: function (value) {
2025-07-23 23:10:52 +08:00
return value;
2025-07-23 23:06:00 +08:00
},
2025-07-23 22:31:39 +08:00
},
axisLine: {
lineStyle: {
2025-07-23 23:06:00 +08:00
color: "#fff",
},
2025-07-23 22:31:39 +08:00
},
splitLine: {
lineStyle: {
2025-07-23 23:06:00 +08:00
color: "rgba(255,255,255,0.1)",
},
},
2025-07-23 22:31:39 +08:00
},
2025-07-23 23:06:00 +08:00
series: [
{
name: "得分",
type: "bar",
data: scores,
barWidth: "30%",
label: {
show: true,
position: "top",
color: "#fff",
formatter: function (params) {
return params.value;
},
},
itemStyle: {
color: "#409EFF",
},
2025-07-23 22:31:39 +08:00
},
2025-07-23 23:06:00 +08:00
],
2025-07-23 22:31:39 +08:00
};
// 初始化 ECharts 图表(假设你已定义 myChart
myChart2.setOption(option);
2025-07-23 23:06:00 +08:00
window.addEventListener("resize", function () {
2025-07-23 22:31:39 +08:00
myChart2.resize();
});
}