factory_web/src/views/statistics/total_statistics.vue

461 lines
12 KiB
Vue

<template>
<el-container>
<el-main>
<el-container>
<el-header style="height: 40%">
<el-container>
<el-header>
<h2>棒数据</h2>
<div>
<el-date-picker
v-model="query.date"
type="date"
placeholder="查询日期"
value-format="YYYY-MM-DD"
style="width: 150px; margin-right: 10px"
>
</el-date-picker>
<el-button
type="primary"
icon="el-icon-search"
@click="handleQuery"
></el-button>
</div>
</el-header>
<el-main id="bangTable">
<el-table
id="hourBaseTable"
:data="tableData11"
style="width: 1200px"
:height="bangHeight"
border
>
<el-table-column label="版型" prop="版型">
</el-table-column>
<el-table-column label="7号">
<el-table-column
label="合格数"
prop="合格数"
>
</el-table-column>
</el-table-column>
<el-table-column label="8号">
<el-table-column
label="仓库库存"
prop="仓库库存"
>
</el-table-column>
</el-table-column>
<el-table-column label="6号">
<el-table-column label="库存" prop="库存">
</el-table-column>
<el-table-column label="平头" prop="平头">
</el-table-column>
<el-table-column label="粘头" prop="粘头">
</el-table-column>
<el-table-column
label="粗中细"
prop="粗中细"
>
</el-table-column>
<el-table-column label="抛光" prop="抛光">
</el-table-column>
<el-table-column label="开槽" prop="开槽">
</el-table-column>
<el-table-column label="配管" prop="配管">
</el-table-column>
</el-table-column>
<el-table-column label="合计" prop="合计">
</el-table-column>
<el-table-column
label="检验合格数"
prop="检验合格数"
>
</el-table-column>
</el-table>
</el-main>
</el-container>
</el-header>
<el-main style="padding: 8px 0 0 0">
<el-container>
<el-header> <h2>管数据</h2> </el-header>
<el-main id="guanTable" style="background: #ffffff">
<el-table
:data="tableData22"
style="width: 1200px"
border
id="hourBaseTable"
:height="guanHeight"
>
<el-table-column label="版型" prop="版型">
</el-table-column>
<el-table-column label="规格" prop="规格">
</el-table-column>
<el-table-column label="10号">
<el-table-column
label="合格数"
prop="合格数"
>
</el-table-column>
</el-table-column>
<el-table-column label="8号">
<!-- 仓库库存加车间未退火数 -->
<el-table-column
label="库存"
prop="仓库库存"
>
</el-table-column>
<el-table-column label="退火" prop="退火">
</el-table-column>
</el-table-column>
<el-table-column label="6号">
<el-table-column label="库存" prop="库存">
</el-table-column>
<el-table-column label="开槽" prop="开槽">
</el-table-column>
<el-table-column label="倒角" prop="倒角">
</el-table-column>
<el-table-column label="配棒" prop="配棒">
</el-table-column>
</el-table-column>
<el-table-column label="合计" prop="合计">
</el-table-column>
<el-table-column
label="检验合格数"
prop="检验合格数"
>
</el-table-column>
</el-table>
</el-main>
</el-container>
</el-main>
</el-container>
</el-main>
</el-container>
</template>
<script>
// import mockData from "./mock.json";
export default {
name: "total_statistics",
data() {
return {
// mockData: mockData,
tableData11: [],
tableData22: [],
bangHeight: 300,
guanHeight: 500,
query: {
date: "",
},
currentDate: "",
};
},
mounted() {
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
this.year = year;
this.month = month;
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
this.day = day;
this.query.date = this.currentDate = `${year}-${month}-${day}`;
this.getSourceData();
this.bangHeight =
document.getElementById("bangTable").offsetHeight - 20;
this.guanHeight =
document.getElementById("guanTable").offsetHeight - 20;
},
created() {},
methods: {
getCountOk() {
let that = this;
let params = {
query: {
start_date: that.query.date,
end_date: that.query.date,
// start_date: "2024-01-16",
// end_date: "2024-01-16",
},
};
that.$API.bi.dataset.exec
.req("count_ok_day", params)
.then((res) => {
let datas = res.data2.ds0;
if(datas.length>0){
datas.forEach((item) => {
let bang_model = "",
guan_model = "";
if (item.型号.indexOf("+") > -1) {
bang_model = item.型号.split("+")[0];
guan_model = item.型号.split("+")[1];
} else {
bang_model = guan_model = item.型号;
}
that.tableData11.forEach((item1) => {
if (item1.版型 == bang_model) {
item1.检验合格数 += item.合格数;
}
});
that.tableData22.forEach((item2) => {
if (item2.版型 == guan_model) {
item2.检验合格数 += item.合格数;
}
});
});
}
});
},
//获取表格原始数据
getSourceData() {
let that = this;
let obj = {};
obj.timex__year = that.year;
obj.timex__month = that.month;
obj.timex__day = that.day;
obj.page = 0;
that.$API.bi.dataset.record.req(obj).then((res) => {
// let res = that.mockData;
let datas = res[0].result.data2;
let data_b = [...datas.ds0, ...datas.ds2];
let data_g = [...datas.ds1, ...datas.ds3];
that.data_b = data_b;
that.data_g = data_g;
that.getDataB(data_b);
that.getDataG(data_g);
that.getCountOk();
});
},
//棒数据
getDataB(data) {
let that = this;
let models = [],
dataArr = [];
//按版型(型号)分组
data.forEach((item) => {
let index = 0;
if (item.型号.indexOf("+") > -1) {
let model = item.型号.split("+")[0];
index = models.indexOf(model);
item.型号 = model;
} else {
index = models.indexOf(item.型号);
}
if (index > -1) {
dataArr[index].push(item);
} else {
models.push(item.型号);
let arr = [];
arr.push(item);
dataArr.push(arr);
}
});
//将数组组成table要用的格式
dataArr.forEach((itemArr, index) => {
//itemArr 是型号相通数据的一个对象数组
let obj = {
版型: "",
合格数: 0,
仓库库存: 0,
库存: 0,
平头: 0,
粘头: 0,
粗中细: 0,
抛光: 0,
开槽: 0,
配管: 0,
合计: 0,
检验合格数: 0,
};
itemArr.forEach((item1) => {
obj.版型 = item1.型号;
let key = "";
if (item1.车间 == "7车间" && item1.工序 == "棒料成型") {
key = "合格数";
} else if (!item1.车间 && item1.工序 == "棒料成型") {
key = "仓库库存";
} else if (
item1.车间 == "6车间" &&
item1.工序 == "棒料成型"
) {
key = "库存";
} else if (item1.车间 == "6车间" && item1.工序 == "平头") {
key = "平头";
} else if (item1.车间 == "6车间" && item1.工序 == "粘头") {
key = "粘头";
} else if (
item1.车间 == "6车间" &&
item1.工序 == "粗中细磨"
) {
key = "粗中细";
} else if (item1.车间 == "6车间" && item1.工序 == "抛光") {
key = "抛光";
} else if (item1.车间 == "6车间" && item1.工序 == "开槽") {
key = "开槽";
} else if (item1.工序 == "配管") {
key = "配管";
}
obj[key] = item1.数量;
});
obj.合计 =
obj.合格数 +
obj.仓库库存 +
obj.库存 +
obj.平头 +
obj.粘头 +
obj.粗中细 +
obj.抛光 +
obj.开槽 +
obj.配管;
that.tableData11[index] = obj;
});
},
//管数据
getDataG(data) {
let that = this;
let models = [],
modelArr = [];
//modelArr按型号分组
data.forEach((item) => {
let index = 0;
if (item.型号.indexOf("+") > -1) {
let model = item.型号.split("+")[1];
index = models.indexOf(model);
item.型号 = model;
} else {
index = models.indexOf(item.型号);
}
if (index > -1) {
modelArr[index].push(item);
} else {
models.push(item.型号);
let arr = [];
arr.push(item);
modelArr.push(arr);
}
});
//specArr按规格的分组
let specArr = [];
modelArr.forEach((itemArr, index0) => {
specArr[index0] = [];
let specifica = []; //规格数组
let ind = 0;
//itemArr是同一规格的对象数组[{},{}]
itemArr.forEach((item1, index1) => {
//item1==>对象{}
if (item1.规格.indexOf("+") > -1) {
let spec = item1.规格.split("+")[1];
ind = specifica.indexOf(spec);
} else {
ind = specifica.indexOf(item1.规格);
}
if (ind > -1) {
specArr[index0][ind].push(item1);
} else {
specifica.push(item1.规格);
let arr = [];
arr.push(item1);
specArr[index0].push(arr);
}
});
});
//specArr已将同型号的数组中按规格分组
specArr.forEach((item3, index3) => {
item3.forEach((item4) => {
let obj = {
版型: "",
规格: "",
合格数: 0,
仓库库存: 0,
退火: 0,
库存: 0,
开槽: 0,
倒角: 0,
配棒: 0,
合计: 0,
检验合格数: 0,
};
item4.forEach((item5) => {
let key = "";
obj.版型 = item5.型号;
obj.规格 = item5.规格;
if (
item5.车间 == "10车间" &&
item5.工序 == "管料成型"
) {
key = "合格数";
} else if (!item5.车间 && item5.工序 == "管料成型") {
key = "仓库库存";
} else if (
item5.车间 == "8车间" &&
item5.工序 == "管料成型"
) {
key = "仓库库存";
} else if (
item5.车间 == "8车间" &&
item5.工序 == "管料退火"
) {
key = "退火";
} else if (
item5.车间 == "6车间" &&
item5.工序 == "管料成型"
) {
key = "库存";
} else if (
item5.车间 == "6车间" &&
item5.工序 == "开槽"
) {
key = "开槽";
} else if (
item5.车间 == "6车间" &&
item5.工序 == "倒角"
) {
key = "倒角";
} else if (
item5.车间 == "6车间" &&
item5.工序 == "配棒"
) {
key = "配棒";
}
obj[key] = obj[key] + item5.数量;
});
obj.合计 =
obj.合格数 +
obj.仓库库存 +
obj.退火 +
obj.库存 +
obj.开槽 +
obj.倒角 +
obj.配棒;
that.tableData22.push(obj);
});
});
},
handleQuery() {
let that = this;
if (that.query.date !== null && that.query.date !== "") {
if (that.query.date !== "") {
that.year = that.query.date.split("-")[0];
that.month = that.query.date.split("-")[1];
that.day = that.query.date.split("-")[2];
} else {
that.year = new Date().getFullYear();
that.month = new Date().getMonth() + 1;
that.day = new Date().getDate();
that.query.date = that.currentDate;
}
}
that.getSourceData();
},
},
};
</script>
<style scoped></style>