Files

507 lines
18 KiB
JavaScript
Raw Permalink Normal View History

2025-11-20 13:11:05 +08:00
/// 主体下拉框更改事件
$("#title_selected").bind().change(function () {
Getselectcontent();
});
//条形图对象
var mixedChart = null;
//产能统计时用户点击的 产能分类划分值
var partitioncriterionval = 0;
//保存日期
var preservetime = 0;
//获取主体内容
function Getselectcontent() {
let selval = $("#title_selected").val();
let resdata = {
typeid: selval
};
if (Checkselected(selval)) {
return;
}
$.ajax({
url: "/app/Dataanalysis/selected",
async: true,
type: "post",
data: resdata,
success: function (data) {
if (data.indexOf("selected" + selval) >= 0) {
$("#selectcontent").append(data);
} else {
$.toastr.error('查询失败,请稍后再试。', {
time: 3000,
position: 'top-center'
});
}
}, error: function (xhr, textStatus, errorThrown) {
$.toastr.error('网络异常,请稍后再试。', {
time: 3000,
position: 'top-center'
});
}
});
}
//请求参数 暂未用到
function getdata(selval) {
let data = [];
switch (selval) {
case 0:
data.push(0);
break;
case 1:
break;
case 2:
break;
}
}
// 历史选择
var TodayProductions_old_select = null;
//加载使用产能统计
let select_oy_Capacitydata = localStorage.getItem("select_oy_Capacitydata") || null;
if (select_oy_Capacitydata != null) {
select_oy_Capacitydata = JSON.parse(select_oy_Capacitydata);
}
if (TodayProductions_old_select == null && select_oy_Capacitydata != null) {
TodayProductions_old_select = select_oy_Capacitydata;
partitioncriterionval = TodayProductions_old_select.typeid;
}
Getselectcontent();
// 获取机型订单
function GetOrderList() {
var projectID = $("#projectList").val();
let resdata = { "projectID": projectID };
$.ajax({
url: "/app/Home/GetOrderList",
async: true,
type: "post",
data: resdata,
success: function (data) {
$("#OrderList").html(data);
if (TodayProductions_old_select != null && TodayProductions_old_select.OrderInternalID != null) {
$("#OrderList").val(TodayProductions_old_select.OrderInternalID);
if (TodayProductions_old_select.Station == null) {
TodayProductions_old_select = null;
} else {
TodayProductions_old_select.OrderInternalID = null;
}
}
}, error: function (xhr, textStatus, errorThrown) {
$.toastr.error('网络异常,请稍后再试。', {
time: 3000,
position: 'top-center'
});
}
});
}
// 工艺站
function GetstationList() {
var projectID = $("#projectList").val();
$("#checkbox").html("");
//$("#checkbox").html(`<option value="0">选择站位</option>`);
if (projectID != 0) {
$.ajax({
type: "POST",
url: "/APP/TestLog/GetStation",
cache: false,
data: { "productID": projectID },
success: function (data) {
if (data.Status == 200) {
for (var i = 0; i < data.Data.length; i++) {
$("#checkbox").append(` <option value="` + data.Data[i].ID + `">` + data.Data[i].StationName + `</option>`);
}
}
if (TodayProductions_old_select != null && TodayProductions_old_select.Station != null) {
preservetime = localStorage.getItem("select_oy_num");
//读取历史记录改变查询日期颜色
partitioncriterion(preservetime, null);
//保存去重历史记录
$("#checkboxtool input").get(0).checked = TodayProductions_old_select.tool[0];
$("#checkbox").val(TodayProductions_old_select.Station.Station);
if (TodayProductions_old_select != null) {
GoData();
}
if (TodayProductions_old_select.OrderInternalID == null) {
TodayProductions_old_select = null;
} else {
TodayProductions_old_select.Station = null;
}
}
}
});
}
};
//选择机型
function projectListchange() {
// 更改订单选择下拉框
GetOrderList();
// 更改站位
GetstationList();
};
// 查询点击事件
function GoData() {
let startTime = $("#startTime").val();
let finish = $("#finish").val();
let EndTime = $("#EndTime").val();
let star = $("#start").val();
let tool = new Array();
// 选择的划分类型
let typeid = partitioncriterionval;
// 判断是否去重
tool.push($("#checkboxtool input").get(0).checked);
// 合并站位 暂未使用
tool.push(true);
//判断是否为已天为单位
if (star == finish) {
typeid = 0
}
// 获取选择中的时间
let datatime = $("#start").bind().val();
//给详细信息添加日期单位
if (typeid == 0) {
$('#dateselect').html("时间 日");
}
else if (typeid == 1) {
$('#dateselect').html("时间 周");
}
else if (typeid == 2) {
$('#dateselect').html("时间 月");
}
// 订单id
let OrderInternalID = Number($("#OrderList").val());
// 产品
let projectID = Number($("#projectList").val());
if (projectID <= 0) {
$.toastr.error('请选择产品!', {
time: 3000,
position: 'top-center'
});
return;
}
let Station = Number($("#checkbox").val());
$('#cesid').html("详细数据");
if (Station <= 0) {
$.toastr.error('请选择站位!', {
time: 3000,
position: 'top-center'
});
return;
}
console.log(Station);
// 默认日产能查询范围 0 -23
var resdata = {
"typeid": typeid, "datatime": datatime, "jsTime": finish, "productID": projectID, "startTime": startTime, "EndTime": EndTime, "OrderInternalID": OrderInternalID, "Station":Station , "tool": tool, "OrderInternalID": OrderInternalID
};
//保存历史记录
localStorage.setItem("select_oy_Capacitydata", JSON.stringify(resdata));
$.ajax({
url: "/App/Dataanalysis/SelectData2",
type: "post",
async: false,
data: resdata,
success: function (data) {
try {
data = JSON.parse(data);
} catch (e) {
$.toastr.error('查询失败~', {
time: 3000,
position: 'top-center'
});
}
let DATASTR = JSON.parse(JSON.stringify(data));
//异常信息
if (typeid == 2) {
//月查询
GetError(DATASTR, datatime.substr(5, 2));
} else {
GetError(DATASTR,0);
}
let DATA = {
labels: [],
datasets: []
};
DATA.datasets.push({
label: 'PASS',
data: [],
backgroundColor: "#9bbefd",
borderColor: [
'rgba(55,99,12,1)',
'rgba(5, 16, 235, 1)',
'rgba(55, 26, 86, 1)',
'rgba(7, 19, 192, 1)',
'rgba(13, 12, 255, 1)',
'rgba(25, 19, 64, 1)'
],
});
DATA.datasets.push({
label: 'FALL',
data: [],
backgroundColor: "red",
borderColor: [],
});
$('#cesid').append(" Total" + data.ruleList["ztall"] + "<span style='color: #00B400'>Pass" + data.ruleList["tureall"] + " (" + GetPercent(data.ruleList["tureall"], data.ruleList["ztall"]) + ")" + "</span> / " + "<span style='color: red'> Fall" + data.ruleList["faultall"] + " (" + GetPercent(data.ruleList["faultall"], data.ruleList["ztall"]) + ")");
for (var key in data.ok) {
DATA.labels.push(key);
DATA.datasets[0].data.push(data.ok[key]);
DATA.datasets[1].data.push(data.bad[key]);
}
GetstackedBarChart(DATA);
}, error: function (xhr, textStatus, errorThrown) {
$.toastr.error('网络异常,请稍后再试。', {
time: 3000,
position: 'top-center'
});
}
});
}
//生成条形图
function GetstackedBarChart(data) {
var ctx = $('#stackedBarChart').get(0).getContext('2d');
if (mixedChart != null) {
mixedChart.destroy();
}
mixedChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
title: {
display: true,
text: "Custom Chart Title",
fontColor: "#f00",
},
scales: {
xAxes:
{
stacked: true
}
,
yAxes:
{
stacked: true
}
}
}
});
}
//判断是否存在 selected
function Checkselected(selval) {
$(".selected0").hide();
$(".selected1").hide();
$(".selected2").hide();
$(".selected" + selval).show();
return $(".selected" + selval).length > 0;
}
// 产能统计时用户点击的 产能分类
function partitioncriterion(type, that) {
let num = type;
localStorage.setItem("select_oy_num", num);
if (type != 0) {
num = num- 1;
}
if (type == 3) {
type = 2
}
else if (type == 7) {
type = 2
}
else if (type == 30)
{
type = 2
}
partitioncriterionval = type;
$('.partitioncriterion').removeClass("btn-primary");
$('.partitioncriterion_' + num).addClass("btn-primary");
if (that != null) {
// 范围选择器初始化
initTime();
}
$("#start").val(formatDate(new Date(new Date().setDate(new Date().getDate() - num))));
$("#finish").val(formatDate(new Date(new Date().setDate(new Date().getDate()))));
GoData();
}
function bian(tupe) {
}
// 生成错误信息列表
function GetError(data,date) {
let content = `<div class="col-xs-4 col-sm-4" style="padding:0 5px;">
<label class="form-control input-sm " style="border:none;">{{tump}}</label>
</div>`;
//加按钮
let content2 = `<div class="col-xs-4 col-sm-4" style="padding:0 5px;">
<label class="form-control input-sm " style="border:none;" onclick="Showinfo()">{{tump}}</label>
</div>`;
// 移除第3个之后的所有元素
$($("#errinfo").children().get(2)).nextAll().remove();
let error = data.err;
let keylist = new Array();
for (let key in error) {
keylist.push(key);
}
//倒叙
keylist.sort(function (a, b) { return Number(b) - Number(a) });
var oklist = 0;
// 错误总数
var errlistall = 0;
for (let key = 0; key < keylist.length; key++) {
oklist = oklist + Number(data.ok[keylist[key]]);
errlistall += Number(data.bad[keylist[key]]);
}
$("#errinfo").append(content.replace("{{tump}}","总计"));
$("#errinfo").append(content.replace("{{tump}}", oklist));
$("#errinfo").append(content2.replace("{{tump}}", errlistall));
$("#errinfo").append(`<div id="ShowAll"; style=" display:none;";></div>`);
let errallkey = [];
let errallval = [];
let errInfo = [];
for (let key = 0; key < keylist.length; key++) {
// 失败和成功数量 为 0 不显示
if (data.bad[keylist[key]] > 0 || data.ok[keylist[key]] > 0) {
// 添加时间
if (date != 0) {
//月查询在前面加上月份
$("#errinfo").append(content.replace("{{tump}}",keylist[key]));
} else {
$("#errinfo").append(content.replace("{{tump}}", keylist[key]));
}
// 添加成功数量
$("#errinfo").append(content.replace("{{tump}}", data.ok[keylist[key]]));
//// 添加失败数量
$("#errinfo").append(`<div onclick="ShwoErr('err_` + keylist[key].replace(/ /g,'') + `')" class="col-xs-4 col-sm-4" style="padding:0 5px;">
<label class="form-control input-sm " style="border:none;">{{tump}}</label>
</div>`.replace("{{tump}}", data.bad[keylist[key]]));
let errlist = new Array();
for (let errkey in data.err[keylist[key]]) {
errlist.push({ key: errkey, data: data.err[keylist[key]][errkey] })
}
// 取出异常信息后排序 Item2 是数量 Item1 是错误信息 key 是错误码
errlist.sort(function (a, b) { return b.data.Item2 - a.data.Item2 });
// 其他异常
let othereror = 0;
var ErrorAll = [];
for (var i = 0; i < errlist.length; i++) {
// 错误码 数量 大于 50 就显示为 其他错误
if (i <= 50) {
$("#errinfo").append(`<div class="col-xs-12 hide col-sm-12 err_` + keylist[key].replace(/ /g, '') + `" style="padding:0 5px; color:#FF0000;">` + errlist[i].data.Item2 + `<span style="color:#d3d7d4;">:</span> <span style="color:#0080FF;">` + GetPercent(errlist[i].data.Item2,data.bad[keylist[key]]) + `</span>` + ` <span style="color:#d3d7d4;">:</span><span style="color:#FF0000;">` + errlist[i].key + `-</span> <span style="color:#d3d7d4;">` + errlist[i].data.Item1 + "</span></div>");
}
else {
othereror += errlist[i].data.Item2;
}
ErrorAll.push(errlist[i]);
}
//添加总数失败
for (var j = 0; j < ErrorAll.length; j++) {
let index = errallkey.indexOf(ErrorAll[j].key);
if (index >= 0) {
errallval[index] = Number(errallval[index]) + Number(ErrorAll[j].data.Item2);
} else {
errallkey.push(ErrorAll[j].key);
errallval.push(Number(ErrorAll[j].data.Item2));
errInfo.push(ErrorAll[j].data.Item1);
}
}
// 添加 其他错误
if (othereror > 0) {
$("#errinfo").append(`<div class="col-xs-12 hide col-sm-12 err_` + keylist[key].replace(/ /g, '') + `" style="padding:0 5px; color:#FF0000;">` + othereror + `<span style="color:#d3d7d4;">:</span> <span style="color:#0080FF;">` + GetPercent(othereror, data.bad[keylist[key]]) + `</span>` + ` <span style="color:#d3d7d4;">:</span><span style="color:#FF0000;">其他 -</span> <span style="color:#d3d7d4;">其他错误`+ "</span></div>");
$("#errinfo").append(`<div class="col-xs-4 hide col-sm-4" style="padding:0 5px;">` + "其他 : " + othereror + "</div>");
}
// 起到换行作用
$("#errinfo").append(`<div class="hide col-xs-12 hide col-sm-12 err_` + keylist[key].replace(/ /g, '') + `"></div>`);
}
}
//判断是否大于5 0
let sun = 0;
if (errallval.length >= 50){
sun = 50;
} else {
sun = errallval.length;
}
// 错误码 数量 大于 5 就显示为 其他错误
for (var i = 0; i < sun; i++) {
let index = errallval.indexOf( Math.max.apply(null, errallval));
$("#ShowAll").append(`<div class="col-xs-12 col-sm-12" style="padding:0 5px; color:#FF0000;">` + errallval[index] + `<span style="color:#d3d7d4;">:</span> <span style="color:#0080FF;">` + GetPercent(errallval[index], errlistall) + `</span>` + ` <span style="color:#d3d7d4;">:</span><span style="color:#FF0000;">` + errallkey[index] + `-</span> <span style="color:#d3d7d4;">` + errInfo[index] + "</span></div>");
errallval[index] = -1;
}
let allerrsum = 0;
for (var i = 0; i < errallval.length; i++) {
if (errallval[i] >= 0) {
allerrsum += errallval[i];
}
}
//判断是否大于5 没有则不显示
//if (sun >= 5) {
// $("#ShowAll").append(`<div class="col-xs-12 col-sm-12" style="padding:0 5px; color:#FF0000;">` + allerrsum + `<span style="color:#d3d7d4;">:</span> <span style="color:#0080FF;">` + GetPercent(allerrsum, errlistall) + `</span><span style="color:#d3d7d4;">:</span><span style="color:#FF0000;">其他 -</span> <span style="color:#d3d7d4;">其他错误</span></div>`);
//}
}
// 显示错误信息
function ShwoErr(classname) {
if ($('.' + classname).attr("class").indexOf('hide') >= 0) {
$('.' + classname).removeClass('hide');
} else {
$('.' + classname).addClass('hide');
}
}
function Showinfo() {
$("#ShowAll").toggle();
}
//多余的字用省略号代替(......
function subStrFormat(data, max) {
if (data != null && data != undefined && data.length > max) {
return data.substr(0, max) + ` ...`;
} else {
return data;
}
}
/// <summary>
/// 求百分比
/// </summary>
/// <param name="num">当前数</param>
/// <param name="total">总数</param>
function GetPercent(num, total) {
num = parseFloat(num);
total = parseFloat(total);
if (isNaN(num) || isNaN(total)) {
return "-";
}
return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.0).toFixed(1) + "%";
}