fix:光芯合格数统计

This commit is contained in:
shijing 2024-08-28 14:02:07 +08:00
parent 2a0bcc4692
commit 14e2fe211d
1 changed files with 55 additions and 28 deletions

View File

@ -13,7 +13,7 @@
</el-option> </el-option>
</el-select> </el-select>
<el-date-picker <el-date-picker
v-model="query.start_date" v-model="queryDate"
type="date" type="date"
placeholder="查询日期" placeholder="查询日期"
value-format="YYYY-MM-DD" value-format="YYYY-MM-DD"
@ -97,6 +97,7 @@ import scEcharts from "@/components/scEcharts";
function deepCopy(obj) { function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
const ondDayTime = 86400000;
export default { export default {
name: "chart", name: "chart",
components: { components: {
@ -112,6 +113,7 @@ export default {
order_bys_material: "", order_bys_material: "",
select_cols_material: "" select_cols_material: ""
}, },
queryDate:'',
currentYear: "", currentYear: "",
currentMonth: "", currentMonth: "",
xAxisData: [], xAxisData: [],
@ -128,7 +130,7 @@ export default {
}, },
xAxis: { xAxis: {
type: "category", type: "category",
data: [], data: ["周一","周二","周三","周四","周五","周六","周日"],
}, },
yAxis: { yAxis: {
type: "value", type: "value",
@ -149,25 +151,37 @@ export default {
}, },
mounted() { mounted() {
let that = this; let that = this;
let date = new Date(); let nowDate = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
that.currentYear = year;
that.currentMonth = month;
month = month < 10 ? "0" + month : month;
day = day < 10 ? "0" + day : day;
that.query.start_date = that.query.end_date = year + "-" + month + "-" + day;
let days = new Date(year, month, 0).getDate();
for (let i = 0; i < that.days; i++) {
let day = i + 1;
let text = day + "日";
}
that.getMgroup(); that.getMgroup();
// that.getData(); that.getWeekDate(nowDate);
}, },
methods: { methods: {
getWeekDate(dates){
let that = this;
dates = new Date(dates);
let week =dates.getDay(); //week
let weekFirst = 0, weekLast = 0;
if (week == 0) {
weekFirst = 6;
weekLast = 0; //
} else {
weekFirst = week - 1;
weekLast = 7 - week;
}
let first = new Date(dates.getTime() - weekFirst * ondDayTime); //
let last = new Date(new Date(dates.getTime() + weekLast * ondDayTime)); //
let dateArr = [];
for (let i = 0; i < 7; i++) {
let itemDate = new Date(first.getTime() + i * ondDayTime);
let item = itemDate.getDate();
dateArr.push(item);
}
that.weekDateList = dateArr;
console.log('dateArr',dateArr);
that.query.start_date =first.getFullYear() +"-" +(first.getMonth() + 1) +"-" +first.getDate();
that.query.end_date =last.getFullYear() +"-" +(last.getMonth() + 1) +"-" +last.getDate();
that.getData();
},
setChart(name, option = null) { setChart(name, option = null) {
// name , optionoption // name , optionoption
var myChart = echarts.getInstanceByDom( var myChart = echarts.getInstanceByDom(
@ -205,21 +219,36 @@ export default {
let tableData = res.data2.ds0 ? res.data2.ds0 : []; let tableData = res.data2.ds0 ? res.data2.ds0 : [];
that.tableData = tableData; that.tableData = tableData;
if (tableData.length > 0) { if (tableData.length > 0) {
let seriesData = [], let dataList = [],
nameList = []; nameList = [],
datas = [];
tableData.forEach((ite) => { tableData.forEach((ite) => {
if (nameList.indexOf(ite.物料名) > -1) { if (nameList.indexOf(ite.物料名) > -1) {} else {
} else {
nameList.push(ite.物料名); nameList.push(ite.物料名);
seriesData.push(0); datas.push([0,0,0,0,0,0,0]);
} }
}); });
that.xAxisData = nameList;
tableData.forEach((item) => { tableData.forEach((item) => {
let indexX = nameList.indexOf(item.物料名); let indexX = nameList.indexOf(item.物料名);
seriesData[indexX] += item.合格数; dataList[indexX].push(item);
}); });
for(let i = 0;i<dataList.length;i++){
for(let j = 0;j<dataList[i].length;j++){
let index = that.weekDateList.indexOf(dataList[i][j].);
datas[i][index].push(dataList[i][j].合格数); //datas
}
}
ption.xAxis.data = nameList; ption.xAxis.data = nameList;
ption.series[0].data = serisData; nameList.forEach((index,item) => {
let obj = {
data: datas[index],
stack: "Ad",
type: "bar",
barWidth: "15px",
};
ption.series[index].data = serisData;
});
that.setChart("bachart1", option); that.setChart("bachart1", option);
} else { } else {
that.setChart("bachart1", option); that.setChart("bachart1", option);
@ -227,9 +256,7 @@ export default {
}); });
}, },
handleQuery() { handleQuery() {
let that = this; this.getWeekDate(this.queryDate);
that.query.end_date = that.query.start_date ;
that.getData();
}, },
handleExport(val) { handleExport(val) {
this.exportLoading = true; this.exportLoading = true;