fix(wms): 修正仓库ID格式和计算逻辑,优化团队报表功能

修复仓库ID格式错误,统一为正确格式
修改calcSummary计算逻辑,使用lossList计算损耗数据
重构团队报表页面,增加班组统计功能
优化日期选择器,支持月份范围选择
调整钢卷标签显示为"投入钢卷"
This commit is contained in:
砂糖
2026-02-27 13:05:36 +08:00
parent af97afcbcb
commit 48273d49b5
11 changed files with 251 additions and 154 deletions

View File

@@ -1,12 +1,12 @@
const calcSummary = (list) => { const calcSummary = (list, lossList) => {
// 总钢卷数量、总重、均重 // 总钢卷数量、总重、均重
const outCount = list.length const outCount = list.length
const outTotalWeight = list.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错 const outTotalWeight = list.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错
const outAvgWeight = outCount > 0 ? (outTotalWeight / outCount)?.toFixed(2) : 0 const outAvgWeight = outCount > 0 ? (outTotalWeight / outCount)?.toFixed(2) : 0
// 损失钢卷数量、总重、均重 // 损失钢卷数量、总重、均重
const lossCount = list.length const lossCount = lossList.length
const lossTotalWeight = list.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错 const lossTotalWeight = lossList.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错
const lossAvgWeight = lossCount > 0 ? (lossTotalWeight / lossCount)?.toFixed(2) : 0 const lossAvgWeight = lossCount > 0 ? (lossTotalWeight / lossCount)?.toFixed(2) : 0
// 合计数量、总重、均重 // 合计数量、总重、均重
const totalCount = outCount + lossCount const totalCount = outCount + lossCount
@@ -14,7 +14,7 @@ const calcSummary = (list) => {
const totalAvgWeight = totalCount > 0 ? (totalWeight / totalCount)?.toFixed(2) : 0 const totalAvgWeight = totalCount > 0 ? (totalWeight / totalCount)?.toFixed(2) : 0
// 成品比率 // 成品比率
const passRate = outCount > 0 ? (outCount / lossCount) : 0 const passRate = outCount > 0 ? (outTotalWeight / lossTotalWeight) : 0
// 损失比率 // 损失比率
const lossRate = totalCount > 0 ? (1 - passRate) : 0 const lossRate = totalCount > 0 ? (1 - passRate) : 0
// 异常率,成品在warehouseId在'2019583656787259393', // 异常率,成品在warehouseId在'2019583656787259393',
@@ -93,7 +93,25 @@ const calcAbSummary = (list) => {
] ]
} }
const calcTeamSummary = (list) => {
// 按照班组汇总信息
const teamSummary = {}
for (let i = 0; i < list.length; i++) {
const coil = list[i];
if (!teamSummary[coil.team]) {
teamSummary[coil.team] = {
count: 0,
weight: 0,
}
}
teamSummary[coil.team].count = teamSummary[coil.team].count + 1
teamSummary[coil.team].weight = teamSummary[coil.team].weight + parseFloat(coil.netWeight) || 0
}
return teamSummary
}
export { export {
calcSummary, calcSummary,
calcAbSummary, calcAbSummary,
calcTeamSummary,
} }

View File

@@ -197,10 +197,10 @@ export default {
createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '2019583656787259393' warehouseId: '2019583656787259393'
}, },
'20195833325311414274': { '2019583325311414274': {
selectType: 'product', selectType: 'product',
createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '20195833325311414274' warehouseId: '2019583325311414274'
}, },
'2019583429955104769': { '2019583429955104769': {
selectType: 'product', selectType: 'product',

View File

@@ -71,7 +71,7 @@
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -186,7 +186,7 @@ export default {
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 9999, pageSize: 9999,
date: currentDate, // 绑定日期选择器的默认值(当天) // date: currentDate, // 绑定日期选择器的默认值(当天)
byCreateTimeStart: start, // 默认当天0点 byCreateTimeStart: start, // 默认当天0点
byCreateTimeEnd: end, // 默认当天23:59:59 byCreateTimeEnd: end, // 默认当天23:59:59
selectType: 'product', selectType: 'product',
@@ -266,7 +266,7 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
return calcSummary(this.list) return calcSummary(this.list, this.lossList)
}, },
abSummary() { abSummary() {
return calcAbSummary(this.list) return calcAbSummary(this.list)

View File

@@ -66,7 +66,7 @@
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -291,7 +291,7 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
return calcSummary(this.list) return calcSummary(this.list, this.lossList)
} }
}, },
methods: { methods: {

View File

@@ -2,9 +2,13 @@
<div class="app-container" v-loading="loading"> <div class="app-container" v-loading="loading">
<el-row> <el-row>
<el-form label-width="80px" inline> <el-form label-width="80px" inline>
<el-form-item label="日期" prop="date"> <el-form-item label="开始日期" prop="date">
<el-date-picker style="width: 200px;" v-model="queryParams.date" type="date" value-format="yyyy-MM-dd" <el-date-picker style="width: 200px;" v-model="queryParams.byCreateTimeStart" type="date"
placeholder="选择日期" @change="handleDateChange"></el-date-picker> value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
</el-form-item>
<el-form-item label="结束日期" prop="date">
<el-date-picker style="width: 200px;" v-model="queryParams.byCreateTimeEnd" type="date"
value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="班组" prop="team"> <el-form-item label="班组" prop="team">
<el-select v-model="queryParams.team" placeholder="请选择班组" style="width: 200px;"> <el-select v-model="queryParams.team" placeholder="请选择班组" style="width: 200px;">
@@ -54,25 +58,36 @@
<el-descriptions-item label="产出总重">{{ summary.outTotalWeight }}t</el-descriptions-item> <el-descriptions-item label="产出总重">{{ summary.outTotalWeight }}t</el-descriptions-item>
<el-descriptions-item label="产出均重">{{ summary.outAvgWeight }}t</el-descriptions-item> <el-descriptions-item label="产出均重">{{ summary.outAvgWeight }}t</el-descriptions-item>
<el-descriptions-item label="消耗数量">{{ summary.lossCount }}</el-descriptions-item> <!-- <el-descriptions-item label="消耗数量">{{ summary.lossCount }}</el-descriptions-item>
<el-descriptions-item label="消耗总重">{{ summary.lossTotalWeight }}t</el-descriptions-item> <el-descriptions-item label="消耗总重">{{ summary.lossTotalWeight }}t</el-descriptions-item>
<el-descriptions-item label="消耗均重">{{ summary.lossAvgWeight }}t</el-descriptions-item> <el-descriptions-item label="消耗均重">{{ summary.lossAvgWeight }}t</el-descriptions-item>
<el-descriptions-item label="合计数量">{{ summary.totalCount }}</el-descriptions-item> <el-descriptions-item label="合计数量">{{ summary.totalCount }}</el-descriptions-item>
<el-descriptions-item label="合计总重">{{ summary.totalWeight }}t</el-descriptions-item> <el-descriptions-item label="合计总重">{{ summary.totalWeight }}t</el-descriptions-item>
<el-descriptions-item label="合计均重">{{ summary.totalAvgWeight }}t</el-descriptions-item> <el-descriptions-item label="合计均重">{{ summary.totalAvgWeight }}t</el-descriptions-item> -->
<!-- 成品率 --> <!-- 成品率 -->
<el-descriptions-item label="成品率">{{ summary.passRate }}</el-descriptions-item> <!-- <el-descriptions-item label="成品率">{{ summary.passRate }}</el-descriptions-item> -->
<el-descriptions-item label="损耗率">{{ summary.lossRate }}</el-descriptions-item> <!-- <el-descriptions-item label="损耗率">{{ summary.lossRate }}</el-descriptions-item> -->
<!-- 异常率 --> <!-- 异常率 -->
<el-descriptions-item label="异常率">{{ summary.abRate }}</el-descriptions-item> <!-- <el-descriptions-item label="异常率">{{ summary.abRate }}</el-descriptions-item> -->
</el-descriptions> </el-descriptions>
<el-descriptions title="班组统计信息" :column="3" border>
</el-descriptions>
<el-table :data="teamSummary" border>
<el-table-column label="班组" align="center" prop="team" />
<el-table-column label="产出数量" align="center" prop="outCount" />
<el-table-column label="产出总重" align="center" prop="outWeight" />
<!-- <el-table-column label="消耗数量" align="center" prop="lossCount" />
<el-table-column label="消耗总重" align="center" prop="lossWeight" />
<el-table-column label="成品率" align="center" prop="passRate" /> -->
</el-table>
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <!-- <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -86,7 +101,6 @@
</el-table-column> </el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" /> <el-table-column label="创建时间" align="center" prop="createTime" />
<el-table-column label="逻辑库位" align="center" prop="warehouseName" /> <el-table-column label="逻辑库位" align="center" prop="warehouseName" />
<!-- <el-table-column label="实际库区" align="center" prop="actualWarehouseName" /> -->
<el-table-column label="产品类型" align="center" width="250"> <el-table-column label="产品类型" align="center" width="250">
<template slot-scope="scope"> <template slot-scope="scope">
<ProductInfo v-if="scope.row.itemType == 'product'" :product="scope.row.product" /> <ProductInfo v-if="scope.row.itemType == 'product'" :product="scope.row.product" />
@@ -99,8 +113,8 @@
<el-table-column label="更新人" align="center" prop="updateByName" /> <el-table-column label="更新人" align="center" prop="updateByName" />
<el-table-column label="更新时间" align="center" prop="updateTime" /> <el-table-column label="更新时间" align="center" prop="updateTime" />
</el-table> </el-table>
</el-tab-pane> </el-tab-pane> -->
<el-tab-pane label="产出钢卷" name="output"> <!-- <el-tab-pane label="产出钢卷" name="output"> -->
<el-table :data="list" border height="calc(100vh - 320px)"> <el-table :data="list" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -134,8 +148,8 @@
<el-table-column label="更新人" align="center" prop="updateByName" /> <el-table-column label="更新人" align="center" prop="updateByName" />
<el-table-column label="更新时间" align="center" prop="updateTime" /> <el-table-column label="更新时间" align="center" prop="updateTime" />
</el-table> </el-table>
</el-tab-pane> <!-- </el-tab-pane> -->
</el-tabs> <!-- </el-tabs> -->
</div> </div>
</template> </template>
@@ -151,6 +165,7 @@ import CoilNo from "@/components/KLPService/Renderer/CoilNo.vue";
import MemoInput from "@/components/MemoInput"; import MemoInput from "@/components/MemoInput";
import MutiSelect from "@/components/MutiSelect"; import MutiSelect from "@/components/MutiSelect";
import WarehouseSelect from "@/components/KLPService/WarehouseSelect"; import WarehouseSelect from "@/components/KLPService/WarehouseSelect";
import { calcSummary, calcAbSummary, calcTeamSummary } from "@/views/wms/report/js/calc";
export default { export default {
components: { components: {
@@ -168,15 +183,45 @@ export default {
// 获取当前日期(默认选中当天) // 获取当前日期(默认选中当天)
const now = new Date() const now = new Date()
const currentDate = `${now.getFullYear()}-${addZero(now.getMonth() + 1)}-${addZero(now.getDate())}` const currentDate = `${now.getFullYear()}-${addZero(now.getMonth() + 1)}`
// 生成指定日期的 00:00:00 和 23:59:59 时间字符串 /**
* 生成指定日期/月份的时间范围字符串
* @param {string} dateStr - 支持格式yyyy-MM月份 或 yyyy-MM-dd具体日期
* @returns {object} 包含start开始时间和end结束时间的对象
*/
const getDayTimeRange = (dateStr) => { const getDayTimeRange = (dateStr) => {
return { // 先校验输入格式是否合法
start: `${dateStr} 00:00:00`, const monthPattern = /^\d{4}-\d{2}$/; // yyyy-MM 正则
end: `${dateStr} 23:59:59` const dayPattern = /^\d{4}-\d{2}-\d{2}$/; // yyyy-MM-dd 正则
if (!monthPattern.test(dateStr) && !dayPattern.test(dateStr)) {
throw new Error('输入格式错误,请传入 yyyy-MM 或 yyyy-MM-dd 格式的字符串');
} }
}
let startDate, endDate;
if (monthPattern.test(dateStr)) {
// 处理 yyyy-MM 格式:获取本月第一天和最后一天
const [year, month] = dateStr.split('-').map(Number);
// 月份是0基的0=1月1=2月...所以要减1
// 第一天yyyy-MM-01
startDate = `${dateStr}-01`;
// 最后一天:通过 new Date(year, month, 0) 计算month是原始月份比如2代表2月传2则取3月0日=2月最后一天
const lastDayOfMonth = new Date(year, month, 0).getDate();
endDate = `${dateStr}-${lastDayOfMonth.toString().padStart(2, '0')}`;
} else {
// 处理 yyyy-MM-dd 格式:直接使用传入的日期
startDate = dateStr;
endDate = dateStr;
}
// 拼接时间部分
return {
start: `${startDate} 00:00:00`,
end: `${endDate} 23:59:59`
};
};
const { start, end } = getDayTimeRange(currentDate) const { start, end } = getDayTimeRange(currentDate)
@@ -267,47 +312,41 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
// 总钢卷数量、总重、均重 return calcSummary(this.list, this.lossList)
const outCount = this.list.length },
const outTotalWeight = this.list.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错 // 合并两个汇总结果并转换为目标数组的方法
const outAvgWeight = outCount > 0 ? (outTotalWeight / outCount)?.toFixed(2) : 0 teamSummary() {
const teamOutSummary = calcTeamSummary(this.list);
// const teamLossSummary = calcTeamSummary(this.lossList);
// 损失钢卷数量、总重、均重 const allTeams = [...new Set([
const lossCount = this.lossList.length ...Object.keys(teamOutSummary),
const lossTotalWeight = this.lossList.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错 // ...Object.keys(teamLossSummary)
const lossAvgWeight = lossCount > 0 ? (lossTotalWeight / lossCount)?.toFixed(2) : 0 ])];
// 合计数量、总重、均重
const totalCount = outCount + lossCount
const totalWeight = parseFloat((outTotalWeight + lossTotalWeight).toFixed(2))
const totalAvgWeight = totalCount > 0 ? (totalWeight / totalCount)?.toFixed(2) : 0
// 成品比率 const result = allTeams.map(team => {
const passRate = outCount > 0 ? (outCount / lossCount) : 0 const outData = teamOutSummary[team] || { count: 0, weight: 0 };
// 损失比率 // const lossData = teamLossSummary[team] || { count: 0, weight: 0 };
const lossRate = 1 - passRate
// 异常率,成品在warehouseId在'2019583656787259393',
// '2019583325311414274',
// '2019583429955104769',
// '2019583137616310273',这四个库中的占比
const abRate = this.list.filter(item => {
return item.warehouseId == '2019583656787259393' || item.warehouseId == '2019583325311414274' || item.warehouseId == '2019583429955104769' || item.warehouseId == '2019583137616310273'
}).length / totalCount
// 核心修复:先确保是有效数字,再保留两位小数
const formatWeight = (weight) => {
// 步骤1转数字非数字则置为0步骤2保留两位小数
return Number(weight || 0).toFixed(2);
// 如果需要返回数字类型(而非字符串),用这行:
// return Number(Number(weight || 0).toFixed(2));
};
return { return {
outCount, team: team,
outTotalWeight: outTotalWeight.toFixed(2), outCount: outData.count,
outAvgWeight, outWeight: formatWeight(outData.weight), // 格式化出库重量
lossCount, // lossCount: lossData.count,
lossTotalWeight: lossTotalWeight.toFixed(2), // lossWeight: formatWeight(lossData.weight), // 格式化损耗重量
lossAvgWeight, // passRate: (outData.weight / lossData.weight * 100).toFixed(2) + '%' , // 计算成品率
totalCount, };
totalWeight: totalWeight.toFixed(2), });
totalAvgWeight,
passRate: passRate?.toFixed(2) * 100 + '%', return result;
lossRate: lossRate?.toFixed(2) * 100 + '%',
abRate: (abRate?.toFixed(2) * 100) || 0 + '%',
}
} }
}, },
methods: { methods: {
@@ -344,7 +383,7 @@ export default {
(a, b) => new Date(b.createTime) - new Date(a.createTime) (a, b) => new Date(b.createTime) - new Date(a.createTime)
) )
this.loading = false this.loading = false
this.getLossList() // this.getLossList()
}).catch(err => { // 增加错误处理 }).catch(err => { // 增加错误处理
console.error('查询失败:', err) console.error('查询失败:', err)
this.loading = false this.loading = false

View File

@@ -66,7 +66,7 @@
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -275,7 +275,7 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
return calcSummary(this.list) return calcSummary(this.list, this.lossList)
} }
}, },
methods: { methods: {

View File

@@ -183,10 +183,10 @@ export default {
// createBy: 'suanzhakuguan', // createBy: 'suanzhakuguan',
warehouseId: '2019583656787259393' warehouseId: '2019583656787259393'
}, },
'20195833325311414274': { '2019583325311414274': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', // createBy: 'suanzhakuguan',
warehouseId: '20195833325311414274' warehouseId: '2019583325311414274'
}, },
'2019583429955104769': { '2019583429955104769': {
selectType: 'product', selectType: 'product',

View File

@@ -71,7 +71,7 @@
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -186,7 +186,7 @@ export default {
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 9999, pageSize: 9999,
date: currentDate, // 绑定日期选择器的默认值(当天) // date: currentDate, // 绑定日期选择器的默认值(当天)
byCreateTimeStart: start, // 默认当天0点 byCreateTimeStart: start, // 默认当天0点
byCreateTimeEnd: end, // 默认当天23:59:59 byCreateTimeEnd: end, // 默认当天23:59:59
selectType: 'product', selectType: 'product',
@@ -218,32 +218,32 @@ export default {
warehouseQueryMap: { warehouseQueryMap: {
'1988150323162836993': { '1988150323162836993': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '1988150323162836993' warehouseId: '1988150323162836993'
}, },
'1988150487185289217': { '1988150487185289217': {
selectType: 'raw_material', selectType: 'raw_material',
// createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '1988150487185289217' warehouseId: '1988150487185289217'
}, },
'2019583656787259393': { '2019583656787259393': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '2019583656787259393' warehouseId: '2019583656787259393'
}, },
'20195833325311414274': { '2019583325311414274': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '20195833325311414274' warehouseId: '2019583325311414274'
}, },
'2019583429955104769': { '2019583429955104769': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '2019583429955104769' warehouseId: '2019583429955104769'
}, },
'2019583137616310273': { '2019583137616310273': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '2019583137616310273' warehouseId: '2019583137616310273'
}, },
}, },
@@ -252,7 +252,7 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
return calcSummary(this.list) return calcSummary(this.list, this.lossList)
}, },
abSummary() { abSummary() {
return calcAbSummary(this.list) return calcAbSummary(this.list)

View File

@@ -66,7 +66,7 @@
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -256,10 +256,10 @@ export default {
// createBy: 'suanzhakuguan', // createBy: 'suanzhakuguan',
warehouseId: '2019583656787259393' warehouseId: '2019583656787259393'
}, },
'20195833325311414274': { '2019583325311414274': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', // createBy: 'suanzhakuguan',
warehouseId: '20195833325311414274' warehouseId: '2019583325311414274'
}, },
'2019583429955104769': { '2019583429955104769': {
selectType: 'product', selectType: 'product',
@@ -277,7 +277,7 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
return calcSummary(this.list) return calcSummary(this.list, this.lossList)
} }
}, },
methods: { methods: {

View File

@@ -2,9 +2,13 @@
<div class="app-container" v-loading="loading"> <div class="app-container" v-loading="loading">
<el-row> <el-row>
<el-form label-width="80px" inline> <el-form label-width="80px" inline>
<el-form-item label="日期" prop="date"> <el-form-item label="开始日期" prop="date">
<el-date-picker style="width: 200px;" v-model="queryParams.date" type="date" value-format="yyyy-MM-dd" <el-date-picker style="width: 200px;" v-model="queryParams.byCreateTimeStart" type="date"
placeholder="选择日期" @change="handleDateChange"></el-date-picker> value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
</el-form-item>
<el-form-item label="结束日期" prop="date">
<el-date-picker style="width: 200px;" v-model="queryParams.byCreateTimeEnd" type="date"
value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
</el-form-item> </el-form-item>
<el-form-item label="入场钢卷号" prop="enterCoilNo"> <el-form-item label="入场钢卷号" prop="enterCoilNo">
<el-input style="width: 200px; display: inline-block;" v-model="queryParams.enterCoilNo" <el-input style="width: 200px; display: inline-block;" v-model="queryParams.enterCoilNo"
@@ -54,25 +58,37 @@
<el-descriptions-item label="产出总重">{{ summary.outTotalWeight }}t</el-descriptions-item> <el-descriptions-item label="产出总重">{{ summary.outTotalWeight }}t</el-descriptions-item>
<el-descriptions-item label="产出均重">{{ summary.outAvgWeight }}t</el-descriptions-item> <el-descriptions-item label="产出均重">{{ summary.outAvgWeight }}t</el-descriptions-item>
<el-descriptions-item label="消耗数量">{{ summary.lossCount }}</el-descriptions-item> <!-- <el-descriptions-item label="消耗数量">{{ summary.lossCount }}</el-descriptions-item>
<el-descriptions-item label="消耗总重">{{ summary.lossTotalWeight }}t</el-descriptions-item> <el-descriptions-item label="消耗总重">{{ summary.lossTotalWeight }}t</el-descriptions-item>
<el-descriptions-item label="消耗均重">{{ summary.lossAvgWeight }}t</el-descriptions-item> <el-descriptions-item label="消耗均重">{{ summary.lossAvgWeight }}t</el-descriptions-item>
<el-descriptions-item label="合计数量">{{ summary.totalCount }}</el-descriptions-item> <el-descriptions-item label="合计数量">{{ summary.totalCount }}</el-descriptions-item>
<el-descriptions-item label="合计总重">{{ summary.totalWeight }}t</el-descriptions-item> <el-descriptions-item label="合计总重">{{ summary.totalWeight }}t</el-descriptions-item>
<el-descriptions-item label="合计均重">{{ summary.totalAvgWeight }}t</el-descriptions-item> <el-descriptions-item label="合计均重">{{ summary.totalAvgWeight }}t</el-descriptions-item> -->
<!-- 成品率 --> <!-- 成品率 -->
<el-descriptions-item label="成品率">{{ summary.passRate }}</el-descriptions-item> <!-- <el-descriptions-item label="成品率">{{ summary.passRate }}</el-descriptions-item>
<el-descriptions-item label="损耗率">{{ summary.lossRate }}</el-descriptions-item> <el-descriptions-item label="损耗率">{{ summary.lossRate }}</el-descriptions-item> -->
<!-- 异常率 --> <!-- 异常率 -->
<el-descriptions-item label="异常率">{{ summary.abRate }}</el-descriptions-item> <!-- <el-descriptions-item label="异常率">{{ summary.abRate }}</el-descriptions-item> -->
</el-descriptions> </el-descriptions>
<el-descriptions title="班组统计信息" :column="3" border>
</el-descriptions>
<el-table :data="teamSummary" border>
<el-table-column label="班组" align="center" prop="team" />
<el-table-column label="产出数量" align="center" prop="outCount" />
<el-table-column label="产出总重" align="center" prop="outWeight" />
<!-- <el-table-column label="消耗数量" align="center" prop="lossCount" />
<el-table-column label="消耗总重" align="center" prop="lossWeight" />
<el-table-column label="成品率" align="center" prop="passRate" /> -->
</el-table>
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <!-- <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -86,7 +102,6 @@
</el-table-column> </el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" /> <el-table-column label="创建时间" align="center" prop="createTime" />
<el-table-column label="逻辑库位" align="center" prop="warehouseName" /> <el-table-column label="逻辑库位" align="center" prop="warehouseName" />
<!-- <el-table-column label="实际库区" align="center" prop="actualWarehouseName" /> -->
<el-table-column label="产品类型" align="center" width="250"> <el-table-column label="产品类型" align="center" width="250">
<template slot-scope="scope"> <template slot-scope="scope">
<ProductInfo v-if="scope.row.itemType == 'product'" :product="scope.row.product" /> <ProductInfo v-if="scope.row.itemType == 'product'" :product="scope.row.product" />
@@ -99,8 +114,8 @@
<el-table-column label="更新人" align="center" prop="updateByName" /> <el-table-column label="更新人" align="center" prop="updateByName" />
<el-table-column label="更新时间" align="center" prop="updateTime" /> <el-table-column label="更新时间" align="center" prop="updateTime" />
</el-table> </el-table>
</el-tab-pane> </el-tab-pane> -->
<el-tab-pane label="产出钢卷" name="output"> <!-- <el-tab-pane label="产出钢卷" name="output"> -->
<el-table :data="list" border height="calc(100vh - 320px)"> <el-table :data="list" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -134,8 +149,8 @@
<el-table-column label="更新人" align="center" prop="updateByName" /> <el-table-column label="更新人" align="center" prop="updateByName" />
<el-table-column label="更新时间" align="center" prop="updateTime" /> <el-table-column label="更新时间" align="center" prop="updateTime" />
</el-table> </el-table>
</el-tab-pane> <!-- </el-tab-pane> -->
</el-tabs> <!-- </el-tabs> -->
</div> </div>
</template> </template>
@@ -151,6 +166,7 @@ import CoilNo from "@/components/KLPService/Renderer/CoilNo.vue";
import MemoInput from "@/components/MemoInput"; import MemoInput from "@/components/MemoInput";
import MutiSelect from "@/components/MutiSelect"; import MutiSelect from "@/components/MutiSelect";
import WarehouseSelect from "@/components/KLPService/WarehouseSelect"; import WarehouseSelect from "@/components/KLPService/WarehouseSelect";
import { calcSummary, calcAbSummary, calcTeamSummary } from "@/views/wms/report/js/calc.js";
export default { export default {
components: { components: {
@@ -168,15 +184,45 @@ export default {
// 获取当前日期(默认选中当天) // 获取当前日期(默认选中当天)
const now = new Date() const now = new Date()
const currentDate = `${now.getFullYear()}-${addZero(now.getMonth() + 1)}-${addZero(now.getDate())}` const currentDate = `${now.getFullYear()}-${addZero(now.getMonth() + 1)}`
// 生成指定日期的 00:00:00 和 23:59:59 时间字符串 /**
* 生成指定日期/月份的时间范围字符串
* @param {string} dateStr - 支持格式yyyy-MM月份 或 yyyy-MM-dd具体日期
* @returns {object} 包含start开始时间和end结束时间的对象
*/
const getDayTimeRange = (dateStr) => { const getDayTimeRange = (dateStr) => {
return { // 先校验输入格式是否合法
start: `${dateStr} 00:00:00`, const monthPattern = /^\d{4}-\d{2}$/; // yyyy-MM 正则
end: `${dateStr} 23:59:59` const dayPattern = /^\d{4}-\d{2}-\d{2}$/; // yyyy-MM-dd 正则
if (!monthPattern.test(dateStr) && !dayPattern.test(dateStr)) {
throw new Error('输入格式错误,请传入 yyyy-MM 或 yyyy-MM-dd 格式的字符串');
} }
}
let startDate, endDate;
if (monthPattern.test(dateStr)) {
// 处理 yyyy-MM 格式:获取本月第一天和最后一天
const [year, month] = dateStr.split('-').map(Number);
// 月份是0基的0=1月1=2月...所以要减1
// 第一天yyyy-MM-01
startDate = `${dateStr}-01`;
// 最后一天:通过 new Date(year, month, 0) 计算month是原始月份比如2代表2月传2则取3月0日=2月最后一天
const lastDayOfMonth = new Date(year, month, 0).getDate();
endDate = `${dateStr}-${lastDayOfMonth.toString().padStart(2, '0')}`;
} else {
// 处理 yyyy-MM-dd 格式:直接使用传入的日期
startDate = dateStr;
endDate = dateStr;
}
// 拼接时间部分
return {
start: `${startDate} 00:00:00`,
end: `${endDate} 23:59:59`
};
};
const { start, end } = getDayTimeRange(currentDate) const { start, end } = getDayTimeRange(currentDate)
@@ -232,10 +278,10 @@ export default {
// createBy: 'suanzhakuguan', // createBy: 'suanzhakuguan',
warehouseId: '2019583656787259393' warehouseId: '2019583656787259393'
}, },
'20195833325311414274': { '2019583325311414274': {
selectType: 'product', selectType: 'product',
// createBy: 'suanzhakuguan', // createBy: 'suanzhakuguan',
warehouseId: '20195833325311414274' warehouseId: '2019583325311414274'
}, },
'2019583429955104769': { '2019583429955104769': {
selectType: 'product', selectType: 'product',
@@ -253,47 +299,41 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
// 总钢卷数量、总重、均重 return calcSummary(this.list, this.lossList)
const outCount = this.list.length },
const outTotalWeight = this.list.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错 // 合并两个汇总结果并转换为目标数组的方法
const outAvgWeight = outCount > 0 ? (outTotalWeight / outCount)?.toFixed(2) : 0 teamSummary() {
const teamOutSummary = calcTeamSummary(this.list);
// const teamLossSummary = calcTeamSummary(this.lossList);
// 损失钢卷数量、总重、均重 const allTeams = [...new Set([
const lossCount = this.lossList.length ...Object.keys(teamOutSummary),
const lossTotalWeight = this.lossList.reduce((acc, cur) => acc + (parseFloat(cur.netWeight) || 0), 0) // 增加容错 // ...Object.keys(teamLossSummary)
const lossAvgWeight = lossCount > 0 ? (lossTotalWeight / lossCount)?.toFixed(2) : 0 ])];
// 合计数量、总重、均重
const totalCount = outCount + lossCount
const totalWeight = parseFloat((outTotalWeight + lossTotalWeight).toFixed(2))
const totalAvgWeight = totalCount > 0 ? (totalWeight / totalCount)?.toFixed(2) : 0
// 成品比率 const result = allTeams.map(team => {
const passRate = outCount > 0 ? (outCount / lossCount) : 0 const outData = teamOutSummary[team] || { count: 0, weight: 0 };
// 损失比率 // const lossData = teamLossSummary[team] || { count: 0, weight: 0 };
const lossRate = 1 - passRate
// 异常率,成品在warehouseId在'2019583656787259393',
// '2019583325311414274',
// '2019583429955104769',
// '2019583137616310273',这四个库中的占比
const abRate = this.list.filter(item => {
return item.warehouseId == '2019583656787259393' || item.warehouseId == '2019583325311414274' || item.warehouseId == '2019583429955104769' || item.warehouseId == '2019583137616310273'
}).length / totalCount
// 核心修复:先确保是有效数字,再保留两位小数
const formatWeight = (weight) => {
// 步骤1转数字非数字则置为0步骤2保留两位小数
return Number(weight || 0).toFixed(2);
// 如果需要返回数字类型(而非字符串),用这行:
// return Number(Number(weight || 0).toFixed(2));
};
return { return {
outCount, team: team,
outTotalWeight: outTotalWeight.toFixed(2), outCount: outData.count,
outAvgWeight, outWeight: formatWeight(outData.weight), // 格式化出库重量
lossCount, // lossCount: lossData.count,
lossTotalWeight: lossTotalWeight.toFixed(2), // lossWeight: formatWeight(lossData.weight),
lossAvgWeight, // passRate: (outData.weight / lossData.weight * 100).toFixed(2) + '%', // 计算成品率
totalCount, };
totalWeight: totalWeight.toFixed(2), });
totalAvgWeight,
passRate: passRate?.toFixed(2) * 100 + '%', return result;
lossRate: lossRate?.toFixed(2) * 100 + '%',
abRate: (abRate?.toFixed(2) * 100) || 0 + '%',
}
} }
}, },
methods: { methods: {
@@ -330,7 +370,7 @@ export default {
(a, b) => new Date(b.createTime) - new Date(a.createTime) (a, b) => new Date(b.createTime) - new Date(a.createTime)
) )
this.loading = false this.loading = false
this.getLossList() // this.getLossList()
}).catch(err => { // 增加错误处理 }).catch(err => { // 增加错误处理
console.error('查询失败:', err) console.error('查询失败:', err)
this.loading = false this.loading = false

View File

@@ -66,7 +66,7 @@
<el-descriptions title="明细信息" :column="3" border> <el-descriptions title="明细信息" :column="3" border>
</el-descriptions> </el-descriptions>
<el-tabs v-model="activeTab"> <el-tabs v-model="activeTab">
<el-tab-pane label="损耗钢卷" name="loss"> <el-tab-pane label="投入钢卷" name="loss">
<el-table :data="lossList" border height="calc(100vh - 320px)"> <el-table :data="lossList" border height="calc(100vh - 320px)">
<el-table-column label="入场钢卷号" align="center" prop="enterCoilNo"> <el-table-column label="入场钢卷号" align="center" prop="enterCoilNo">
<template slot-scope="scope"> <template slot-scope="scope">
@@ -238,10 +238,10 @@ export default {
createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '2019583656787259393' warehouseId: '2019583656787259393'
}, },
'20195833325311414274': { '2019583325311414274': {
selectType: 'product', selectType: 'product',
createBy: 'suanzhakuguan', createBy: 'suanzhakuguan',
warehouseId: '20195833325311414274' warehouseId: '2019583325311414274'
}, },
'2019583429955104769': { '2019583429955104769': {
selectType: 'product', selectType: 'product',
@@ -259,7 +259,7 @@ export default {
}, },
computed: { computed: {
summary() { summary() {
return calcSummary(this.list) return calcSummary(this.list, this.lossList)
} }
}, },
methods: { methods: {