feat: 车间生产合格数返回更多字段

This commit is contained in:
caoqianming 2024-03-19 14:06:24 +08:00
parent 789f8da088
commit 2f122360c1
1 changed files with 350 additions and 349 deletions

View File

@ -3,30 +3,14 @@
<el-header> <el-header>
<div class="right-panel"> <div class="right-panel">
<el-select v-model="queryType" @change="queryTypeChange"> <el-select v-model="queryType" @change="queryTypeChange">
<el-option v-for="item in typeOptions" <el-option v-for="item in typeOptions" :key="item" :label="item" :value="item">
:key="item"
:label="item"
:value="item"
>
</el-option> </el-option>
</el-select> </el-select>
<el-date-picker <el-date-picker v-if="queryType == ''" v-model="queryDate" type="month" placeholder="查询月期"
v-if="queryType=='月'" value-format="YYYY-MM" style="width:100%">
v-model="queryDate"
type="month"
placeholder="查询月期"
value-format="YYYY-MM"
style="width:100%"
>
</el-date-picker> </el-date-picker>
<el-date-picker <el-date-picker v-if="queryType == ''" v-model="queryDate" type="year" placeholder="查询年份"
v-if="queryType=='年'" value-format="YYYY" style="width:100%">
v-model="queryDate"
type="year"
placeholder="查询年份"
value-format="YYYY"
style="width:100%"
>
</el-date-picker> </el-date-picker>
<el-button type="primary" icon="el-icon-search" @click="handleQuery"></el-button> <el-button type="primary" icon="el-icon-search" @click="handleQuery"></el-button>
</div> </div>
@ -46,7 +30,7 @@
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column label="物料名" prop="物料名"> <el-table-column label="物料名" prop="物料名">
</el-table-column> </el-table-column>
<el-table-column label="月份" prop="月" v-if="queryType=='年'"> <el-table-column label="月份" prop="月" v-if="queryType == '年'">
</el-table-column> </el-table-column>
<el-table-column label="周" prop="周" v-else> <el-table-column label="周" prop="周" v-else>
</el-table-column> </el-table-column>
@ -54,8 +38,14 @@
</el-table-column> </el-table-column>
<el-table-column label="型号" prop="型号"> <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 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-table>
</el-card> </el-card>
</el-col> </el-col>
@ -75,7 +65,7 @@
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column label="物料名" prop="物料名"> <el-table-column label="物料名" prop="物料名">
</el-table-column> </el-table-column>
<el-table-column label="月份" prop="月" v-if="queryType=='年'"> <el-table-column label="月份" prop="月" v-if="queryType == '年'">
</el-table-column> </el-table-column>
<el-table-column label="周" prop="周" v-else> <el-table-column label="周" prop="周" v-else>
</el-table-column> </el-table-column>
@ -83,8 +73,14 @@
</el-table-column> </el-table-column>
<el-table-column label="型号" prop="型号"> <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 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-table>
</el-card> </el-card>
</el-col> </el-col>
@ -104,7 +100,7 @@
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column label="物料名" prop="物料名"> <el-table-column label="物料名" prop="物料名">
</el-table-column> </el-table-column>
<el-table-column label="月份" prop="月" v-if="queryType=='年'"> <el-table-column label="月份" prop="月" v-if="queryType == '年'">
</el-table-column> </el-table-column>
<el-table-column label="周" prop="周" v-else> <el-table-column label="周" prop="周" v-else>
</el-table-column> </el-table-column>
@ -112,8 +108,14 @@
</el-table-column> </el-table-column>
<el-table-column label="型号" prop="型号"> <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 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-table>
</el-card> </el-card>
</el-col> </el-col>
@ -133,7 +135,7 @@
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column label="物料名" prop="物料名"> <el-table-column label="物料名" prop="物料名">
</el-table-column> </el-table-column>
<el-table-column label="月份" prop="月" v-if="queryType=='年'"> <el-table-column label="月份" prop="月" v-if="queryType == '年'">
</el-table-column> </el-table-column>
<el-table-column label="周" prop="周" v-else> <el-table-column label="周" prop="周" v-else>
</el-table-column> </el-table-column>
@ -148,29 +150,29 @@
</el-container> </el-container>
</template> </template>
<script> <script>
import * as echarts from "echarts"; import * as echarts from "echarts";
import T from '@/components/scEcharts/echarts-theme-T.js'; import T from '@/components/scEcharts/echarts-theme-T.js';
echarts.registerTheme('T', T); echarts.registerTheme('T', T);
import scEcharts from '@/components/scEcharts'; import scEcharts from '@/components/scEcharts';
function deepCopy(obj) { function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
export default { export default {
name: 'chart', name: 'chart',
components: { components: {
scEcharts scEcharts
}, },
data() { data() {
return { return {
queryType:'月', queryType: '月',
queryDate:'', queryDate: '',
start_date:'', start_date: '',
end_date:'', end_date: '',
currentYear:'', currentYear: '',
currentMonth:'', currentMonth: '',
xAxisOrigin:[], xAxisOrigin: [],
xAxisData:[], xAxisData: [],
typeOptions:['月','年'], typeOptions: ['月', '年'],
basicOption: { basicOption: {
backgroundColor: 'transparent', backgroundColor: 'transparent',
title: { title: {
@ -189,7 +191,7 @@
yAxis: { yAxis: {
type: 'value' type: 'value'
}, },
lenged:[], lenged: [],
series: [{ series: [{
data: [0, 0, 0, 0, 0, 0, 0], data: [0, 0, 0, 0, 0, 0, 0],
stack: 'Ad', stack: 'Ad',
@ -197,33 +199,33 @@
barWidth: '15px', barWidth: '15px',
}] }]
}, },
tableData6:[], tableData6: [],
tableData7:[], tableData7: [],
tableData10:[], tableData10: [],
tableDataAVG:[], tableDataAVG: [],
firstWeekNum:1, firstWeekNum: 1,
endWeekNum:4, endWeekNum: 4,
monthList:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'] monthList: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月']
} }
}, },
mounted(){ mounted() {
let that =this; let that = this;
let date = new Date(); let date = new Date();
let year = date.getFullYear(); let year = date.getFullYear();
let month = date.getMonth()+1; let month = date.getMonth() + 1;
let days = new Date(year, month, 0).getDate(); let days = new Date(year, month, 0).getDate();
that.currentYear = year; that.currentYear = year;
that.currentMonth = month; that.currentMonth = month;
that.start_date =year+'-'+month+'-01'; that.start_date = year + '-' + month + '-01';
that.end_date = year+'-'+month+'-'+new Date(year, month, 0).getDate(); that.end_date = year + '-' + month + '-' + new Date(year, month, 0).getDate();
let month1=month; let month1 = month;
if(month1<10){month1='0'+month1} if (month1 < 10) { month1 = '0' + month1 }
that.queryDate = year+'-'+month1; that.queryDate = year + '-' + month1;
that.firstWeekNum = that.getWeekOfYear(new Date(that.start_date)); that.firstWeekNum = that.getWeekOfYear(new Date(that.start_date));
that.endWeekNum = that.getWeekOfYear(new Date(that.end_date)); that.endWeekNum = that.getWeekOfYear(new Date(that.end_date));
let duration = that.endWeekNum - that.firstWeekNum + 1; let duration = that.endWeekNum - that.firstWeekNum + 1;
for(let i =1;i<=duration;i++ ){ for (let i = 1; i <= duration; i++) {
that.xAxisOrigin.push('第'+i+'周'); that.xAxisOrigin.push('第' + i + '周');
} }
that.xAxisData = that.xAxisOrigin; that.xAxisData = that.xAxisOrigin;
that.getData6(); that.getData6();
@ -231,7 +233,7 @@
that.getData10(); that.getData10();
that.getDataDAVG(); that.getDataDAVG();
}, },
methods:{ methods: {
setChart(name, option = null) { setChart(name, option = null) {
// name , optionoption // name , optionoption
var myChart = echarts.getInstanceByDom(document.getElementById(name)); var myChart = echarts.getInstanceByDom(document.getElementById(name));
@ -247,71 +249,71 @@
} catch (error) { } } catch (error) { }
}, 500) }, 500)
}, },
queryTypeChange(value){ queryTypeChange(value) {
console.log(value) console.log(value)
this.queryDate = ''; this.queryDate = '';
}, },
getWeekOfYear(date) { getWeekOfYear(date) {
var target = new Date(date.getFullYear(), date.getMonth(), date.getDate()); // var target = new Date(date.getFullYear(), date.getMonth(), date.getDate()); //
var firstDayOfYear = new Date(target.getFullYear(), 0, 1); // var firstDayOfYear = new Date(target.getFullYear(), 0, 1); //
if(target.getTime()==firstDayOfYear.getTime()){ if (target.getTime() == firstDayOfYear.getTime()) {
return 1; return 1;
}else{ } else {
return Math.ceil((target - firstDayOfYear + 8 * (firstDayOfYear.getTimezoneOffset() / 480)) / 604800000); return Math.ceil((target - firstDayOfYear + 8 * (firstDayOfYear.getTimezoneOffset() / 480)) / 604800000);
} }
// //
}, },
getData6(){ getData6() {
let that = this; let that = this;
let option = deepCopy(that.basicOption); let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData; option.xAxis.data = that.xAxisData;
option.title.text = '6车间'; option.title.text = '6车间';
let exec = that.queryType=='月'?'productStatisticWeek':'productStatisticYear'; let exec = that.queryType == '月' ? 'lineWeek' : 'lineMonth';
let obj = { let obj = {
query: { start_date: that.start_date, end_date: that.end_date, dept_name: "6车间" }, query: { start_date: that.start_date, end_date: that.end_date, dept_name: "6车间" },
}; };
that.$API.bi.dataset.exec.req(exec, obj).then((res) => { that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
// console.log('6:',res); // console.log('6:',res);
let tableData6 = res.data2.ds0?res.data2.ds0:[]; let tableData6 = res.data2.ds0 ? res.data2.ds0 : [];
that.tableData6 = tableData6; that.tableData6 = tableData6;
if(tableData6.length>0){ if (tableData6.length > 0) {
option.series = []; option.series = [];
let seriesData = [],nameList = []; let seriesData = [], nameList = [];
tableData6.forEach(ite=>{ tableData6.forEach(ite => {
if(nameList.indexOf(ite.物料名)>-1){}else{ if (nameList.indexOf(ite.物料名) > -1) { } else {
nameList.push(ite.物料名); nameList.push(ite.物料名);
seriesData.push([]) seriesData.push([])
} }
}) })
if(that.queryType=='月'){ if (that.queryType == '月') {
tableData6.forEach(item => { tableData6.forEach(item => {
let indexX = nameList.indexOf(item.物料名); let indexX = nameList.indexOf(item.物料名);
let indexY = item.-that.firstWeekNum; let indexY = item. - that.firstWeekNum;
seriesData[indexX][indexY]=item.合格数; seriesData[indexX][indexY] = item.合格数;
}); });
}else{ } else {
tableData6.forEach(item => { tableData6.forEach(item => {
let indexX = nameList.indexOf(item.物料名); let indexX = nameList.indexOf(item.物料名);
let indexY = item.month-1; let indexY = item.month - 1;
seriesData[indexX][indexY]=item.合格数; seriesData[indexX][indexY] = item.合格数;
}); });
} }
for(let n=0;n<seriesData.length;n++){ for (let n = 0; n < seriesData.length; n++) {
let obj = {}; let obj = {};
obj.name= nameList[n]; obj.name = nameList[n];
obj.stack= 'Ad'; obj.stack = 'Ad';
obj.type= 'bar'; obj.type = 'bar';
obj.barWidth= '15px'; obj.barWidth = '15px';
obj.data= seriesData[n]; obj.data = seriesData[n];
option.series.push(obj) option.series.push(obj)
} }
that.setChart("bachart3", option); that.setChart("bachart3", option);
}else{ } else {
that.setChart("bachart3", option); that.setChart("bachart3", option);
} }
}); });
}, },
getData7(){ getData7() {
let that = this; let that = this;
let obj = { let obj = {
query: { start_date: that.start_date, end_date: that.end_date, dept_name: "7车间" }, query: { start_date: that.start_date, end_date: that.end_date, dept_name: "7车间" },
@ -319,49 +321,49 @@
let option = deepCopy(that.basicOption); let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData; option.xAxis.data = that.xAxisData;
option.title.text = '预制棒7车间'; option.title.text = '预制棒7车间';
let exec = that.queryType=='月'?'lineWeek':'lineMonth'; let exec = that.queryType == '月' ? 'lineWeek' : 'lineMonth';
that.$API.bi.dataset.exec.req(exec, obj).then((res) => { that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
console.log('7生产车间统计:',res); console.log('7生产车间统计:', res);
let tableData7 = res.data2.ds0?res.data2.ds0:[]; let tableData7 = res.data2.ds0 ? res.data2.ds0 : [];
that.tableData7 = tableData7; that.tableData7 = tableData7;
debugger; debugger;
if(tableData7.length>0){ if (tableData7.length > 0) {
debugger; debugger;
option.series = []; option.series = [];
let seriesData = [],nameList = []; let seriesData = [], nameList = [];
tableData7.forEach(ite=>{ tableData7.forEach(ite => {
if(nameList.indexOf(ite.物料名)>-1){}else{ if (nameList.indexOf(ite.物料名) > -1) { } else {
nameList.push(ite.物料名); nameList.push(ite.物料名);
seriesData.push([]) seriesData.push([])
} }
}) })
tableData7.forEach(item => { tableData7.forEach(item => {
let indexX=0,indexY=0; let indexX = 0, indexY = 0;
if(that.queryType=='月'){ if (that.queryType == '月') {
indexX = nameList.indexOf(item.物料名); indexX = nameList.indexOf(item.物料名);
indexY = item.-that.firstWeekNum; indexY = item. - that.firstWeekNum;
}else{ } else {
indexX = nameList.indexOf(item.物料名); indexX = nameList.indexOf(item.物料名);
indexY = item.-1; indexY = item. - 1;
} }
seriesData[indexX][indexY]=item.合格数; seriesData[indexX][indexY] = item.合格数;
}); });
for(let n=0;n<seriesData.length;n++){ for (let n = 0; n < seriesData.length; n++) {
let obj = {}; let obj = {};
obj.name= nameList[n]; obj.name = nameList[n];
obj.stack= 'Ad'; obj.stack = 'Ad';
obj.type= 'bar'; obj.type = 'bar';
obj.barWidth= '15px'; obj.barWidth = '15px';
obj.data= seriesData[n]; obj.data = seriesData[n];
option.series.push(obj) option.series.push(obj)
} }
that.setChart("bachart1", option); that.setChart("bachart1", option);
}else{ } else {
that.setChart("bachart1", option); that.setChart("bachart1", option);
} }
}); });
}, },
getData10(){ getData10() {
let that = this; let that = this;
let option = deepCopy(that.basicOption); let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData; option.xAxis.data = that.xAxisData;
@ -369,110 +371,110 @@
let obj = { let obj = {
query: { start_date: that.start_date, end_date: that.end_date, dept_name: "10车间" }, query: { start_date: that.start_date, end_date: that.end_date, dept_name: "10车间" },
}; };
let exec = that.queryType=='月'?'lineWeek':'lineMonth'; let exec = that.queryType == '月' ? 'lineWeek' : 'lineMonth';
that.$API.bi.dataset.exec.req(exec, obj).then((res) => { that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
// console.log('10:',res); // console.log('10:',res);
let tableData10 = res.data2.ds0?res.data2.ds0:[]; let tableData10 = res.data2.ds0 ? res.data2.ds0 : [];
that.tableData10 = tableData10; that.tableData10 = tableData10;
if(tableData10.length>0){ if (tableData10.length > 0) {
option.series = []; option.series = [];
let seriesData = [],nameList = []; let seriesData = [], nameList = [];
tableData10.forEach(ite=>{ tableData10.forEach(ite => {
if(nameList.indexOf(ite.物料名)>-1){}else{ if (nameList.indexOf(ite.物料名) > -1) { } else {
nameList.push(ite.物料名); nameList.push(ite.物料名);
seriesData.push([]) seriesData.push([])
} }
}) })
tableData10.forEach(item => { tableData10.forEach(item => {
let indexX=0,indexY=0; let indexX = 0, indexY = 0;
if(that.queryType=='月'){ if (that.queryType == '月') {
indexX = nameList.indexOf(item.物料名); indexX = nameList.indexOf(item.物料名);
indexY = item.-that.firstWeekNum; indexY = item. - that.firstWeekNum;
}else{ } else {
indexX = nameList.indexOf(item.物料名); indexX = nameList.indexOf(item.物料名);
indexY = item.-1; indexY = item. - 1;
} }
seriesData[indexX][indexY]=item.合格数; seriesData[indexX][indexY] = item.合格数;
}); });
for(let n=0;n<seriesData.length;n++){ for (let n = 0; n < seriesData.length; n++) {
let obj = {}; let obj = {};
obj.name= nameList[n]; obj.name = nameList[n];
obj.stack= 'Ad'; obj.stack = 'Ad';
obj.type= 'bar'; obj.type = 'bar';
obj.barWidth= '15px'; obj.barWidth = '15px';
obj.data= seriesData[n]; obj.data = seriesData[n];
option.series.push(obj) option.series.push(obj)
} }
that.setChart("bachart2", option); that.setChart("bachart2", option);
}else{ } else {
that.setChart("bachart2", option); that.setChart("bachart2", option);
} }
}); });
}, },
getDataDAVG(){ getDataDAVG() {
let that = this; let that = this;
let option = deepCopy(that.basicOption); let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData; option.xAxis.data = that.xAxisData;
option.title.text = 'AVG'; option.title.text = 'AVG';
let obj = { let obj = {
query: { start_date: that.start_date, end_date: that.end_date}, query: { start_date: that.start_date, end_date: that.end_date },
}; };
let exec = that.queryType=='月'?'AVGWeek':'AVGMonth'; let exec = that.queryType == '月' ? 'AVGWeek' : 'AVGMonth';
that.$API.bi.dataset.exec.req(exec, obj).then((res) => { that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
// console.log('AVG:',res); // console.log('AVG:',res);
let tableDataAVG = res.data2.ds0?res.data2.ds0:[]; let tableDataAVG = res.data2.ds0 ? res.data2.ds0 : [];
let seriesData = []; let seriesData = [];
if(tableDataAVG.length>0){ if (tableDataAVG.length > 0) {
tableDataAVG.forEach(item => { tableDataAVG.forEach(item => {
let index=0; let index = 0;
if(that.queryType=='月'){ if (that.queryType == '月') {
index = item.month-1; index = item.month - 1;
}else{ } else {
index = item.-that.firstWeekNum; index = item. - that.firstWeekNum;
} }
seriesData[index]=item.合格数; seriesData[index] = item.合格数;
}); });
let obj = {}; let obj = {};
obj.name= 'AVG'; obj.name = 'AVG';
obj.type= 'bar'; obj.type = 'bar';
obj.barWidth= '15px'; obj.barWidth = '15px';
obj.data= seriesData; obj.data = seriesData;
option.series.push(obj) option.series.push(obj)
that.setChart("bachart4", option); that.setChart("bachart4", option);
}else{ } else {
that.setChart("bachart4", option); that.setChart("bachart4", option);
} }
}); });
}, },
handleQuery(){ handleQuery() {
let that = this; let that = this;
if(this.queryType=='月'){ if (this.queryType == '月') {
if(this.queryDate!==''&&this.queryDate!==null){ if (this.queryDate !== '' && this.queryDate !== null) {
this.start_date =this.queryDate+'-01'; this.start_date = this.queryDate + '-01';
let arr = this.queryDate.split('-'); let arr = this.queryDate.split('-');
this.end_date = this.queryDate+'-'+new Date(arr[0], arr[1], 0).getDate(); this.end_date = this.queryDate + '-' + new Date(arr[0], arr[1], 0).getDate();
this.firstWeekNum = this.getWeekOfYear(new Date(this.start_date)); this.firstWeekNum = this.getWeekOfYear(new Date(this.start_date));
this.endWeekNum = this.getWeekOfYear(new Date(this.end_date)); this.endWeekNum = this.getWeekOfYear(new Date(this.end_date));
let duration = this.endWeekNum - this.firstWeekNum + 1; let duration = this.endWeekNum - this.firstWeekNum + 1;
let xAxisData = []; let xAxisData = [];
for(let i =1;i<=duration;i++ ){ for (let i = 1; i <= duration; i++) {
xAxisData.push('第'+i+'周'); xAxisData.push('第' + i + '周');
} }
that.xAxisData = xAxisData; that.xAxisData = xAxisData;
}else{ } else {
this.start_date =this.currentYear+'-'+this.currentMonth+'-01'; this.start_date = this.currentYear + '-' + this.currentMonth + '-01';
this.end_date = this.currentYear+'-'+this.currentMonth+'-'+new Date(this.currentYear, this.currentMonth, 0).getDate(); this.end_date = this.currentYear + '-' + this.currentMonth + '-' + new Date(this.currentYear, this.currentMonth, 0).getDate();
let date = new Date(this.start_date); let date = new Date(this.start_date);
this.firstWeekNum = this.getWeekOfYear(date); this.firstWeekNum = this.getWeekOfYear(date);
this.xAxisData = this.xAxisOrigin; this.xAxisData = this.xAxisOrigin;
} }
}else{ } else {
if(this.queryDate!==''&&this.queryDate!==null){ if (this.queryDate !== '' && this.queryDate !== null) {
this.start_date = this.queryDate+'-01-01'; this.start_date = this.queryDate + '-01-01';
this.end_date = this.queryDate+'-12-31'; this.end_date = this.queryDate + '-12-31';
}else{ } else {
this.start_date = this.currentYear+'-01-01'; this.start_date = this.currentYear + '-01-01';
this.end_date = this.currentYear+'-12-31'; this.end_date = this.currentYear + '-12-31';
} }
that.xAxisData = that.monthList; that.xAxisData = that.monthList;
} }
@ -482,8 +484,7 @@
this.getDataDAVG(); this.getDataDAVG();
}, },
}, },
} }
</script> </script>
<style> <style></style>
</style>