Files
bj_power/bj_power_mes/frontend/src/pages/MaterialRequest.vue
T
SunYF 8be6e03a15 docs: 统一修正全项目“SN管理”相关术语为“序列号”
本次 commit 统一修正了全项目范围内关于 SN 管理的术语表述,将原“SN管理”、“序列号件”、“批次件”等表述调整为“序列号”、“序列号=是”、“序列号=否”,同时同步更新了相关文档、代码注释、前端提示文本、数据库 schema 注释、API 文档等,确保全链路术语统一,消除理解歧义。
2026-10-10 15:58:59 +08:00

348 lines
19 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.
<template>
<el-card>
<el-alert type="info" :closable="false" style="margin-bottom:12px"
title="备料单:根据「日排产」自动算出某天要生产的所有工单所需物料。选好排产日期后点「按日排产生成备料」,系统按各产品物料清单(单台用量×计划数量×(1+损耗率))自动汇总生成备料单,仓库据此备料出库。" />
<el-form inline>
<el-form-item label="日期">
<el-date-picker v-model="query.planDate" type="date" value-format="YYYY-MM-DD" @change="load" />
</el-form-item>
<el-form-item label="工单号"><el-input v-model="query.orderNo" clearable style="width:160px" @keyup.enter="load" /></el-form-item>
<el-form-item label="图号"><el-input v-model="query.materialCode" clearable style="width:150px" placeholder="不区分大小写" @keyup.enter="load" /></el-form-item>
<el-form-item label="物料名称"><el-input v-model="query.materialName" clearable style="width:150px" @keyup.enter="load" /></el-form-item>
<el-form-item label="接驳台"><el-input v-model="query.targetDock" clearable style="width:120px" placeholder="如 DOCK05" @keyup.enter="load" /></el-form-item>
<el-form-item label="工位"><el-input v-model="query.stationNo" clearable style="width:90px" placeholder="如 3" @keyup.enter="load" /></el-form-item>
<el-form-item label="来源">
<el-select v-model="query.source" clearable placeholder="全部" style="width:120px">
<el-option label="排产备料" value="PLAN" />
<el-option label="工位补料" value="REFILL" />
</el-select>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="query.status" clearable placeholder="全部" style="width:130px">
<el-option label="待备料" value="PENDING" />
<el-option label="已备料(已出库)" value="LOCKED" />
<el-option label="配送中" value="DELIVERING" />
<el-option label="已接料完结" value="DONE" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="load">查询</el-button>
<el-button @click="resetFilters">重置</el-button>
<el-button v-if="can('produce.material:generate')" type="success" @click="generate">按日排产生成备料</el-button>
<el-button v-if="can('produce.material:outbound')" type="warning" plain :loading="autoing" @click="autoOutbound">一键自动出库</el-button>
<el-button type="info" plain :loading="progressing" @click="showProgress">物料去向对账</el-button>
</el-form-item>
</el-form>
<el-table :data="list" border size="small">
<el-table-column prop="requestNo" label="备料单号" min-width="180" />
<el-table-column prop="orderNo" label="工单号" min-width="130" />
<el-table-column prop="planDate" label="排产日期" width="110" />
<el-table-column label="来源" width="95" align="center">
<template #default="{row}">
<el-tag v-if="row.source === 'REFILL'" type="danger" size="small">工位补料</el-tag>
<el-tag v-else type="info" size="small">排产备料</el-tag>
</template>
</el-table-column>
<el-table-column prop="materialCode" label="图号" min-width="110" />
<el-table-column prop="materialName" label="物料名称" min-width="110" show-overflow-tooltip />
<el-table-column prop="unit" label="单位" width="70" />
<el-table-column label="管理方式" width="100">
<template #default="{row}">{{ row.snMode === 1 ? '序列号=是' : '序列号=否' }}</template>
</el-table-column>
<el-table-column prop="stationNo" label="工位" width="70" align="center" />
<el-table-column prop="targetDock" label="接驳台" width="100" align="center" />
<el-table-column prop="batchNo" label="批次" width="120" align="center" show-overflow-tooltip />
<el-table-column prop="reqQty" label="需求数量" width="90" align="center" />
<el-table-column label="已发出" width="90" align="center">
<template #default="{row}">{{ fmtQty(row.sentQty) }}</template>
</el-table-column>
<el-table-column label="已接料" width="90" align="center">
<template #default="{row}">{{ Number(row.sentQty || 0) > 0 ? fmtQty(row.receivedQty) : '—' }}</template>
</el-table-column>
<el-table-column label="分批进度" min-width="150">
<template #default="{row}">
<el-progress :percentage="progressPct(row)" :status="row.status === 'DONE' ? 'success' : ''" />
</template>
</el-table-column>
<el-table-column prop="status" label="状态" width="100">
<template #default="{row}">{{ statusText(row.status) }}</template>
</el-table-column>
<el-table-column label="操作" width="100" align="center" fixed="right">
<template #default="{row}">
<el-tooltip content="仓库发出后才能确认接料" :disabled="Number(row.sentQty || 0) > 0" placement="top">
<el-button size="small" type="success" :disabled="row.status === 'DONE' || Number(row.sentQty || 0) <= 0" :loading="receiving && receivingNo === row.requestNo" @click="receive(row)">确认接料</el-button>
</el-tooltip>
</template>
</el-table-column>
<el-table-column prop="operator" label="操作人" width="90" />
</el-table>
</el-card>
<el-dialog v-model="progressVisible" title="物料去向对账(在库 / 在途 / 线边 / 已消耗)" width="1060px" top="5vh">
<el-table :data="progressRows" border size="small" max-height="560" row-key="rowKey" @expand-change="onExpandRow">
<el-table-column type="expand">
<template #default="{ row }">
<div style="padding:8px 16px">
<div style="font-weight:600;margin-bottom:6px">接料明细(按备料单,{{ row.orderNo }} / {{ row.materialCode }})</div>
<el-table v-if="expandMap[row.rowKey]?.loaded" :data="expandMap[row.rowKey]?.receives || []" border size="small" max-height="220">
<el-table-column prop="requestNo" label="备料单号" min-width="180" />
<el-table-column label="来源" width="95" align="center">
<template #default="{ row: r }">
<el-tag v-if="r.source === 'REFILL'" type="danger" size="small">工位补料</el-tag>
<el-tag v-else type="info" size="small">排产备料</el-tag>
</template>
</el-table-column>
<el-table-column prop="stationNo" label="工位" width="70" align="center" />
<el-table-column label="已发出" width="85" align="center">
<template #default="{ row: r }">{{ fmtQty(r.sentQty) }}</template>
</el-table-column>
<el-table-column label="已接料" width="85" align="center">
<template #default="{ row: r }">{{ fmtQty(r.receivedQty) }}</template>
</el-table-column>
<el-table-column prop="status" label="状态" width="100">
<template #default="{ row: r }">{{ statusText(r.status) }}</template>
</el-table-column>
<el-table-column prop="operator" label="接料确认人" width="100" />
</el-table>
<div v-else style="color:#909399;font-size:12px;padding:6px 0">加载中…</div>
<div style="color:#909399;font-size:12px;margin-top:8px">
消耗明细:已消耗量由 WMS 报工反冲核销(台账「已消耗」列),按工位合计的留痕在 WMS 操作日志按工单号查询;出库明细与超领原因在 WMS「出库管理」按工单号查询——本页不做跨系统重复建设。
</div>
</div>
</template>
</el-table-column>
<el-table-column prop="orderNo" label="工单号" min-width="130" />
<el-table-column prop="materialCode" label="图号" min-width="110" />
<el-table-column prop="materialName" label="物料名称" min-width="110" show-overflow-tooltip />
<el-table-column prop="targetStation" label="目标工位" width="80" align="center" />
<el-table-column prop="totalQty" label="需求" width="70" align="center" />
<el-table-column prop="outQty" label="已发出" width="75" align="center" />
<el-table-column prop="returnedQty" label="已退回" width="75" align="center" />
<el-table-column label="已接料" width="75" align="center">
<template #default="{row}">{{ Number(row.outQty || 0) > 0 ? fmtQty(row.receivedQty) : '—' }}</template>
</el-table-column>
<el-table-column prop="consumedQty" label="已消耗" width="75" align="center" />
<el-table-column label="在途" width="70" align="center">
<template #default="{row}"><span :style="row.inTransit > 0 ? 'color:#E6A23C;font-weight:600' : ''">{{ row.inTransit }}</span></template>
</el-table-column>
<el-table-column label="工位余" width="70" align="center">
<template #default="{row}"><span :style="lineSideOf(row) > 0 ? 'color:#E6A23C;font-weight:600' : ''">{{ lineSideOf(row) }}</span></template>
</el-table-column>
<el-table-column prop="gap" label="待发缺口" width="85" align="center">
<template #default="{row}">
<el-tag v-if="row.gap > 0" type="danger" size="small">{{ row.gap }}</el-tag>
<span v-else>0</span>
</template>
</el-table-column>
<el-table-column label="对账状态" width="100" align="center" fixed="right">
<template #default="{ row }">
<el-tooltip :content="anomalyTip(row)" placement="top">
<el-tag :type="anomalyOf(row).type" size="small">{{ anomalyOf(row).label }}</el-tag>
</el-tooltip>
</template>
</el-table-column>
</el-table>
<div style="color:#909399;font-size:12px;margin-top:8px">
口径:净领用 = 已发出 − 已退回;在途 = 已发出 − 已接料;工位余 = 已接料 − 已消耗 − 已退回;恒等式:入库总量 = 在库 + 在途 + 工位余 + 已消耗 + 退库回仓 + 盘点差异。
异常判定只标三类硬异常:<b>超领</b>(净领用 &gt; 需求)、<b>完结剩料</b>(台账领料完结但工位仍压料)、<b>在途等待</b>(已发出未接料,含已送达未扫码);生产中的待发缺口属正常状态,不标色。
<br>注:「已接料」为<b>本工单+图号的累计接料量</b>(MES 按工单汇总,不细分到每行),并非本行发出对应的接料;某行「已发出」为 0 时该列显示「—」,详情见上方接料明细。
</div>
<div style="margin-top:10px;text-align:right">
<el-button size="small" @click="exportLedgerCsv">导出 CSV</el-button>
</div>
</el-dialog>
<PageHelp :data="helpMaterial" page="MaterialRequest" />
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import request from '../utils/request'
import { confirmExport } from '../utils/confirm'
import { can } from '../utils/perm'
import PageHelp from '../components/PageHelp.vue'
import { helpMaterial } from '../help'
const query = reactive({ planDate: '', orderNo: '', status: '', materialCode: '', materialName: '', targetDock: '', stationNo: '', source: '' })
function resetFilters() {
query.planDate = new Date().toISOString().slice(0, 10)
Object.assign(query, { orderNo: '', status: '', materialCode: '', materialName: '', targetDock: '', stationNo: '', source: '' })
load()
}
const list = ref([])
const receiving = ref(false)
const receivingNo = ref('')
const autoing = ref(false)
const progressing = ref(false)
const progressVisible = ref(false)
const progressRows = ref([])
const statusText = (s) => (s === 'PENDING' ? '待备料' : s === 'LOCKED' ? '已备料(已出库)' : s === 'DELIVERING' ? '配送中' : s === 'DONE' ? '已接料完结' : s)
function fmtQty(v) {
const n = Number(v || 0)
return Number.isInteger(n) ? String(n) : n.toFixed(2)
}
// 进度按「已接料」计算:接料才是工位真正拿到料的节点(已发出只代表仓库发了)
function progressPct(row) {
const req = Number(row.reqQty || 0)
const got = Number(row.receivedQty || 0)
if (req <= 0) return 0
return Math.min(100, Math.round((got / req) * 100))
}
// ============ 物料去向对账(只读,后端 progress 接口 + 前端现算,不新增账本) ============
// 口径:净领用 netOut = 已发出 − 已退回;在途 = 已发出 − 已接料;工位余 = 已接料 − 已消耗 − 已退回。
// 异常判定只标三类硬异常(生产中的待发缺口属正常状态,不标色):
// 超领:净领用 > 需求(超领原因在 WMS 出库单留痕,可查)
// 完结剩料:台账「领料完结」但工位仍压料(没耗也没退)
// 在途等待:已发出未接料(含已送达未扫码;是否已送达需 WMS 出库单状态,本页不跨系统拉取)
const expandMap = reactive({})
function lineSideOf(row) {
return Number(row.receivedQty || 0) - Number(row.consumedQty || 0) - Number(row.returnedQty || 0)
}
function anomalyOf(row) {
const netOut = Number(row.netOut ?? (Number(row.outQty || 0) - Number(row.returnedQty || 0)))
if (netOut > Number(row.totalQty || 0)) return { key: 'over', label: '超领', type: 'danger' }
if (row.status === '领料完结' && lineSideOf(row) > 0) return { key: 'left', label: '完结剩料', type: 'warning' }
if (Number(row.inTransit || 0) > 0) return { key: 'transit', label: '在途等待', type: 'warning' }
return { key: 'ok', label: '正常', type: 'success' }
}
function anomalyTip(row) {
const a = anomalyOf(row)
if (a.key === 'over') return '净领用超过工单需求:请到 WMS「出库管理」按工单号查超领原因与明细'
if (a.key === 'left') return '台账已领料完结,但工位仍压料未消耗也未退回:请催报工或发起退料'
if (a.key === 'transit') return '已发出尚未接料(含已送达未扫码):请到 WMS「出库管理」看是否已送达,或催工位扫码接料'
return '在库 / 在途 / 线边 / 已消耗均在正常区间'
}
// 展开行:懒加载该工单+图号的接料明细(备料单行即接料台账,含实收与确认人)
async function onExpandRow(row, expandedRows) {
const key = row.rowKey
if (!expandedRows.some((r) => r.rowKey === key) || expandMap[key]?.loaded) return
expandMap[key] = { loaded: false, receives: [] }
try {
const reqs = (await request.get('/material-requests', { params: { orderNo: row.orderNo } })) || []
const receives = reqs.filter((r) => r.materialCode === row.materialCode)
expandMap[key] = { loaded: true, receives }
} catch {
expandMap[key] = { loaded: true, receives: [] }
}
}
// 导出 CSV(带 BOM,Excel 直接打开中文不乱码;MES 前端无 xlsx 库,纯前端导出)
async function exportLedgerCsv() {
if (!(await confirmExport(progressRows.value.length, '物料去向对账记录'))) return
const header = ['工单号', '图号', '物料名称', '目标工位', '需求', '已发出', '已退回', '已接料', '已消耗', '在途', '工位余', '待发缺口', '对账状态', '台账状态']
const lines = [header.join(',')]
for (const r of progressRows.value) {
const cells = [
r.orderNo, r.materialCode, r.materialName, r.targetStation,
r.totalQty, r.outQty, r.returnedQty, r.receivedQty, r.consumedQty,
r.inTransit, lineSideOf(r), r.gap, anomalyOf(r).label, r.status
]
lines.push(cells.map((c) => '"' + String(c ?? '').replace(/"/g, '""') + '"').join(','))
}
const blob = new Blob(['\ufeff' + lines.join('\r\n')], { type: 'text/csv;charset=utf-8' })
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
a.download = '物料去向对账.csv'
a.click()
URL.revokeObjectURL(a.href)
}
// 配送进度:WMS 台账(已发出/已退回/已消耗/缺口)+ 本系统已接料 → 在途/线边
async function showProgress() {
progressing.value = true
try {
const data = await request.get('/material-requests/progress', {
params: { orderNo: query.orderNo, materialCode: query.materialCode, page: 1, pageSize: 100 }
})
progressRows.value = (data?.list || []).map((r) => ({ ...r, rowKey: r.orderNo + '|' + r.materialCode }))
progressVisible.value = true
} catch {
// 拦截器已提示
}
progressing.value = false
}
async function load() {
list.value = (await request.get('/material-requests', { params: query })) || []
}
// 已接料(班组长补录入口):确认本批全部剩余(sentQty 补到 reqQty),达到即置 DONE
async function receive(row) {
if (!row?.requestNo) return
try {
await ElMessageBox.confirm(`确认「${row.requestNo}」已接料(物料将累计到已发料,达需求即完结)?`, '接料确认', { type: 'warning' })
} catch {
return
}
receiving.value = true
receivingNo.value = row.requestNo
try {
await request.post('/material-requests/receive', { requestNo: row.requestNo })
ElMessage.success('已接料确认:' + row.requestNo)
load()
} catch {
// 拦截器已提示
}
receiving.value = false
receivingNo.value = ''
}
async function generate() {
if (!query.planDate) return ElMessage.warning('请先选择排产日期')
await ElMessageBox.confirm(
`将按排产日期 ${query.planDate} 的所有工单,根据各产品物料清单自动计算所需物料并生成备料单。确认继续?`,
'生成备料', { type: 'info' })
const data = await request.post('/material-requests/generate', { planDate: query.planDate })
if (data?.blocked) {
const missing = (data.missing || []).join('、')
await ElMessageBox.alert(
`以下物料在 WMS 物料档案中不存在,请先到 WMS 创建物料档案后再生成备料单:\n\n${missing}`,
'无法生成备料单', { type: 'error', confirmButtonText: '知道了' })
return
}
ElMessage.success(`已生成 ${data?.count || 0} 条备料`)
load()
}
// 一键自动出库:按排产日(或指定工单)把未出齐的备料单从 WMS 合格库存 FIFO 自动领料。
// 日常「按日排产生成备料」已自动执行本动作,此处用于库存补齐后的补出。
async function autoOutbound() {
if (!query.planDate && !query.orderNo) return ElMessage.warning('请先选择排产日期或填写工单号')
try {
await ElMessageBox.confirm(
`将对 ${query.orderNo ? '工单 ' + query.orderNo : '排产日期 ' + query.planDate} 下未出齐的备料单,按 FIFO 从 WMS 合格库存自动领料出库。确认继续?`,
'一键自动出库', { type: 'warning' })
} catch {
return
}
autoing.value = true
try {
const data = await request.post('/material-requests/auto-outbound', {
planDate: query.planDate, orderNo: query.orderNo
})
const short = data?.short || []
if (short.length) {
await ElMessageBox.alert(
`已出库达标 ${data?.done || 0} 条;以下仍未出齐(库存不足,等补货后可再次执行):\n\n${short.join('\n')}`,
'自动出库结果', { type: 'warning', confirmButtonText: '知道了' })
} else {
ElMessage.success(`自动出库完成:${data?.done || 0} 条已备料`)
}
load()
} catch {
// 拦截器已提示
}
autoing.value = false
}
onMounted(() => {
query.planDate = new Date().toISOString().slice(0, 10)
load()
})</script>