修复库存分布问题
This commit is contained in:
@@ -99,6 +99,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listStoppage } from '@/api/pocket/plantState'
|
||||
|
||||
// 2. 独立工具函数(避免data初始化时调用this.methods的问题)
|
||||
/**
|
||||
* 获取默认日期(根据视图类型)
|
||||
@@ -353,11 +355,14 @@ export default {
|
||||
const defaultDate = getDefaultDate();
|
||||
this.startDate = defaultDate;
|
||||
this.endDate = tab === "day" ? defaultDate : getDefaultDate(tab);
|
||||
// 切换视图时重新加载数据
|
||||
this.loadStoppageData();
|
||||
},
|
||||
// 日模式:日期选择器变更
|
||||
handleDateChange(e) {
|
||||
this.startDate = e.detail.value;
|
||||
this.endDate = e.detail.value; // 日模式首尾日期一致
|
||||
this.loadStoppageData();
|
||||
},
|
||||
// 月模式:开始月份变更
|
||||
handleStartMonthChange(e) {
|
||||
@@ -369,19 +374,105 @@ export default {
|
||||
if (new Date(this.endDate) > maxEndDate) {
|
||||
this.endDate = maxEndStr;
|
||||
}
|
||||
this.loadStoppageData();
|
||||
},
|
||||
// 月模式:结束月份变更
|
||||
handleEndMonthChange(e) {
|
||||
this.endDate = e.detail.value;
|
||||
this.loadStoppageData();
|
||||
},
|
||||
// 年模式:开始年份变更
|
||||
handleStartYearChange(e) {
|
||||
this.startDate = e.detail.value;
|
||||
this.loadStoppageData();
|
||||
},
|
||||
// 年模式:结束年份变更
|
||||
handleEndYearChange(e) {
|
||||
this.endDate = e.detail.value;
|
||||
this.loadStoppageData();
|
||||
},
|
||||
// 加载停机数据
|
||||
loadStoppageData() {
|
||||
uni.showLoading({ title: '加载中' })
|
||||
|
||||
const queryParams = {
|
||||
pageNum: 1,
|
||||
pageSize: 100,
|
||||
startDate: this.startDate,
|
||||
endDate: this.endDate
|
||||
}
|
||||
|
||||
listStoppage(queryParams).then(response => {
|
||||
uni.hideLoading()
|
||||
|
||||
if (response.code === 200 && response.rows && response.rows.length > 0) {
|
||||
// 处理停机数据
|
||||
console.log('停机数据:', response.rows)
|
||||
|
||||
// 更新表格数据(日视图)
|
||||
this.tableData = response.rows.map(item => ({
|
||||
time: this.formatDateTime(item.startDate) + ' - ' + this.formatDateTime(item.endDate),
|
||||
duration: item.duration + 'min',
|
||||
remark: item.remark || '-',
|
||||
machine: item.unit || '-'
|
||||
}))
|
||||
|
||||
// 计算汇总数据
|
||||
const totalDuration = response.rows.reduce((sum, item) => sum + (item.duration || 0), 0)
|
||||
const totalCount = response.rows.length
|
||||
|
||||
this.summaryData = [
|
||||
{ label: '停机时间', value: totalDuration, unit: 'min' },
|
||||
{ label: '停机次数', value: totalCount },
|
||||
{ label: '作业率', value: this.calculateWorkRate(totalDuration), unit: '%' }
|
||||
]
|
||||
|
||||
// 更新饼图数据(按班组统计)
|
||||
const crewMap = {}
|
||||
response.rows.forEach(item => {
|
||||
const crew = item.crew || '未知班组'
|
||||
crewMap[crew] = (crewMap[crew] || 0) + (item.duration || 0)
|
||||
})
|
||||
|
||||
this.pieChartData = {
|
||||
series: [{
|
||||
data: Object.keys(crewMap).map(crew => ({
|
||||
name: crew,
|
||||
value: crewMap[crew]
|
||||
}))
|
||||
}]
|
||||
}
|
||||
} else {
|
||||
// 没有数据时使用默认值
|
||||
console.log('暂无停机数据')
|
||||
}
|
||||
}).catch(error => {
|
||||
uni.hideLoading()
|
||||
console.error('加载停机数据失败:', error)
|
||||
})
|
||||
},
|
||||
// 格式化日期时间
|
||||
formatDateTime(dateStr) {
|
||||
if (!dateStr) return '-'
|
||||
const date = new Date(dateStr)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`
|
||||
},
|
||||
// 计算作业率
|
||||
calculateWorkRate(stopDuration) {
|
||||
// 假设一天工作24小时,1440分钟
|
||||
const totalMinutes = 1440
|
||||
const workRate = ((totalMinutes - stopDuration) / totalMinutes) * 100
|
||||
return Math.max(0, Math.min(100, workRate)).toFixed(2)
|
||||
}
|
||||
},
|
||||
// 生命周期钩子
|
||||
mounted() {
|
||||
this.loadStoppageData()
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user