feat(报表): 添加月视图折线图并优化分条线显示逻辑
添加月视图日数据趋势折线图展示产出和消耗数据 优化分条信息统计组件仅在分条线时显示 在日视图中添加昨日数据对比显示 重构日期选择逻辑支持多种视图模式
This commit is contained in:
@@ -97,8 +97,20 @@
|
||||
}}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<!-- 月视图日数据折线图 -->
|
||||
<div style="margin-top: 20px; height: 400px;">
|
||||
<el-card>
|
||||
<template slot="header">
|
||||
<div class="clearfix">
|
||||
<span>日数据趋势</span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="monthChart" style="width: 100%; height: 350px;"></div>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
<!-- 分条信息统计 -->
|
||||
<split-summary :origin-outputlist="list" :origin-loss-list="lossList" :common-coil-ids="commonCoilIds"></split-summary>
|
||||
<split-summary v-if="productionLine == '分条线'" :origin-outputlist="list" :origin-loss-list="lossList" :common-coil-ids="commonCoilIds"></split-summary>
|
||||
|
||||
<el-descriptions title="明细信息" :column="3" border>
|
||||
</el-descriptions>
|
||||
@@ -138,6 +150,7 @@ import CoilTable from "@/views/wms/report/components/coilTable/index.vue";
|
||||
import SplitSummary from "@/views/wms/report/components/summary/splitSummary.vue";
|
||||
import { fetchLossList, fetchOutputList } from "@/views/wms/report/js/fetch";
|
||||
import { saveReportFile } from "@/views/wms/report/js/reportFile";
|
||||
import * as echarts from 'echarts';
|
||||
|
||||
export default {
|
||||
name: 'MonthTemplate',
|
||||
@@ -260,6 +273,8 @@ export default {
|
||||
outputColumns: [],
|
||||
|
||||
actionIds: '',
|
||||
// 折线图实例
|
||||
monthChart: null,
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -400,9 +415,134 @@ export default {
|
||||
]).then(([lossList, outputList]) => {
|
||||
this.lossList = lossList
|
||||
this.list = outputList
|
||||
this.initMonthChart()
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
// 初始化月视图折线图
|
||||
initMonthChart() {
|
||||
if (!this.$refs.monthChart) return
|
||||
|
||||
// 销毁旧的图表实例
|
||||
if (this.monthChart) {
|
||||
this.monthChart.dispose()
|
||||
}
|
||||
|
||||
// 创建新的图表实例
|
||||
this.monthChart = echarts.init(this.$refs.monthChart)
|
||||
|
||||
// 处理数据,按日期分组
|
||||
const dailyData = {}
|
||||
this.list.forEach(item => {
|
||||
const date = item.createTime.split(' ')[0]
|
||||
if (!dailyData[date]) {
|
||||
dailyData[date] = {
|
||||
outCount: 0,
|
||||
outTotalWeight: 0,
|
||||
lossCount: 0,
|
||||
lossTotalWeight: 0,
|
||||
}
|
||||
}
|
||||
dailyData[date].outCount++
|
||||
dailyData[date].outTotalWeight += parseFloat(item.netWeight) || 0
|
||||
})
|
||||
|
||||
this.lossList.forEach(item => {
|
||||
const date = item.actionCompleteTime?.split(' ')[0]
|
||||
if (!dailyData[date]) {
|
||||
dailyData[date] = {
|
||||
outCount: 0,
|
||||
outTotalWeight: 0,
|
||||
lossCount: 0,
|
||||
lossTotalWeight: 0,
|
||||
}
|
||||
}
|
||||
dailyData[date].lossCount++
|
||||
dailyData[date].lossTotalWeight += parseFloat(item.netWeight) || 0
|
||||
})
|
||||
|
||||
// 生成日期数组和数据数组
|
||||
const dates = Object.keys(dailyData).sort()
|
||||
const outCountData = dates.map(date => dailyData[date].outCount)
|
||||
const outTotalWeightData = dates.map(date => dailyData[date].outTotalWeight.toFixed(2))
|
||||
const lossCountData = dates.map(date => dailyData[date].lossCount)
|
||||
const lossTotalWeightData = dates.map(date => dailyData[date].lossTotalWeight.toFixed(2))
|
||||
|
||||
// 配置项
|
||||
const option = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
axisPointer: {
|
||||
type: 'cross',
|
||||
label: {
|
||||
backgroundColor: '#6a7985'
|
||||
}
|
||||
}
|
||||
},
|
||||
legend: {
|
||||
data: ['产出数量', '产出总重', '消耗数量', '消耗总重']
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '3%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: [
|
||||
{
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: dates
|
||||
}
|
||||
],
|
||||
yAxis: [
|
||||
{
|
||||
type: 'value',
|
||||
name: '数量',
|
||||
position: 'left',
|
||||
},
|
||||
{
|
||||
type: 'value',
|
||||
name: '重量(t)',
|
||||
position: 'right',
|
||||
}
|
||||
],
|
||||
series: [
|
||||
{
|
||||
name: '产出数量',
|
||||
type: 'line',
|
||||
data: outCountData,
|
||||
yAxisIndex: 0,
|
||||
},
|
||||
{
|
||||
name: '产出总重',
|
||||
type: 'line',
|
||||
data: outTotalWeightData,
|
||||
yAxisIndex: 1,
|
||||
},
|
||||
{
|
||||
name: '消耗数量',
|
||||
type: 'line',
|
||||
data: lossCountData,
|
||||
yAxisIndex: 0,
|
||||
},
|
||||
{
|
||||
name: '消耗总重',
|
||||
type: 'line',
|
||||
data: lossTotalWeightData,
|
||||
yAxisIndex: 1,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// 应用配置项
|
||||
this.monthChart.setOption(option)
|
||||
|
||||
// 监听窗口大小变化
|
||||
window.addEventListener('resize', () => {
|
||||
this.monthChart.resize()
|
||||
})
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.loadColumns()
|
||||
|
||||
Reference in New Issue
Block a user