Files
l2-g30/src/views/l2/pdo/components/PdoSummary.vue
砂糖 d15660c731 init
2025-12-26 09:18:12 +08:00

113 lines
3.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- src/views/PdoManagement/components/PdoSummary.vue -->
<template>
<el-descriptions
class="summary-content"
:column="1"
:style="{ width: '100%' }"
size="mini"
>
<!-- 循环渲染汇总项从计算属性获取数据 -->
<el-descriptions-item
v-for="(item, index) in summaryResult"
:key="index"
:label="item.label"
label-class="summary-label"
>
<!-- 根据类型格式化显示重量/百分比/数量 -->
<span :class="item.type === 'rate' ? 'summary-rate' : ''">
{{ item.value }}
{{ item.unit }}
</span>
</el-descriptions-item>
</el-descriptions>
</template>
<script>
export default {
name: 'PdoSummary',
props: {
// 接收表格原始数据(父组件传递)
tableData: {
type: Array,
required: true,
default: () => [] // 默认空数组,避免无数据时报错
}
},
computed: {
// 核心根据tableData计算汇总结果
summaryResult() {
// 1. 基础数值汇总处理字符串转数字避免NaN
const totalEntryWeight = this.tableData.reduce((sum, item) => {
return sum + (Number(item.entryWeight) || 0)
}, 0) // 原料总重(来料重量求和)
const totalExitWeight = this.tableData.reduce((sum, item) => {
return sum + (Number(item.exitNetWeight) || 0)
}, 0) // 产品总重(成品带涂料重量求和)
const totalZincRemoved = totalEntryWeight - totalExitWeight // 去锌总理重(原料总重 - 产品总重)
// 2. 成材率计算避免除数为0
const yieldRate = totalEntryWeight > 0
? ((totalExitWeight / totalEntryWeight) * 100).toFixed(2)
: '0.00'
// 3. 卷数统计(原料/成品卷数默认按表格行数可根据实际业务调整如去重entryMatId
const totalEntryCoils = this.tableData.length // 原料总卷数
const totalExitCoils = this.tableData.length // 成品总卷数
// 4. 返回格式化后的汇总项
return [
{ label: '原料总重', value: totalEntryWeight.toFixed(1), unit: 't', type: 'weight' },
{ label: '去锌总理重', value: totalZincRemoved.toFixed(1), unit: 't', type: 'weight' },
{ label: '产品总重', value: totalExitWeight.toFixed(1), unit: 't', type: 'weight' },
{ label: '成材率', value: yieldRate, unit: '%', type: 'rate' },
{ label: '原料总卷数', value: totalEntryCoils, unit: '卷', type: 'count' },
{ label: '成品总卷数', value: totalExitCoils, unit: '卷', type: 'count' }
]
}
}
}
</script>
<style lang="scss" scoped>
.summary-content {
padding: 10px;
flex: 1;
&::-webkit-scrollbar {
width: 4px;
}
&::-webkit-scrollbar-thumb {
background: #c0c0c0;
border-radius: 2px;
}
&::-webkit-scrollbar-track {
background: #f0f0f0;
}
::v-deep .el-descriptions__label {
font-weight: 500;
color: #666;
font-size: 12px;
}
::v-deep .el-descriptions__content {
color: #333;
font-size: 13px;
font-weight: 500;
}
}
.summary-label {
font-weight: 500;
color: #666;
}
.summary-rate {
color: #333;
font-weight: 600;
}
</style>