- 重构物料档案字段:将"序列号件"改为"序列号",描述是否有序列号,与类型独立 - 调整入库页逻辑:按物料"序列号"决定记账方式,类型仅用于页签归属 - 新增通用入库组件 InboundEntry,复用三个类型页签的表单逻辑 - 优化成品入库页面,提交后自动切换到入库列表页签 - 修正物料校验提示文案,统一表述为"是否有序列号"
250 lines
11 KiB
Vue
250 lines
11 KiB
Vue
<template>
|
||
<div>
|
||
<el-card>
|
||
<template #header>
|
||
<div style="display:flex;align-items:center;gap:12px;flex-wrap:wrap">
|
||
<span style="font-weight:600">虚拟工位作业</span>
|
||
<el-select v-model="stationNo" placeholder="选择虚拟工位" style="width:240px" @change="loadTask">
|
||
<el-option v-for="s in stations" :key="s.id" :value="s.stationNo"
|
||
:label="`工位${s.stationNo} ${s.name}${s.stationType === 'OFFLINE' ? '(虚拟)' : ''}`" />
|
||
</el-select>
|
||
<el-tag v-if="task" :type="task.flowActive ? 'success' : 'warning'" size="small">
|
||
{{ task.flowActive ? `工艺:${task.flow?.name || '-'}` : '工位未绑定启用工艺' }}
|
||
</el-tag>
|
||
</div>
|
||
</template>
|
||
|
||
<el-alert type="info" :closable="false" style="margin-bottom:12px"
|
||
title="虚拟工位无终端硬件:操作人在本页(手机/电脑均可)选择虚拟工位 → 扫/输工件SN → 查看当前步骤与配料 → 录入 → 点完成报工。与工位终端走同一套接口与校验。" />
|
||
|
||
<el-empty v-if="!task" description="请先选择工位" />
|
||
<template v-else>
|
||
<el-form inline>
|
||
<el-form-item label="工单">
|
||
<el-select v-model="orderNo" placeholder="选择今日排产工单" style="width:220px">
|
||
<el-option v-for="o in orderNos" :key="o" :value="o" :label="o" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="工件SN">
|
||
<el-input v-model="sn" placeholder="扫/输工件SN后回车" style="width:240px"
|
||
@keyup.enter="onSnEntered" />
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" :disabled="!sn" @click="onSnEntered">载入步骤/配料</el-button>
|
||
<el-button type="success" :disabled="!canReport" @click="report">完成报工</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<el-row :gutter="12">
|
||
<!-- 工艺步骤 -->
|
||
<el-col :xs="24" :md="13">
|
||
<el-card shadow="never" header="工艺步骤(按顺序录入)">
|
||
<el-table :data="task.steps || []" border size="small" empty-text="该工艺未配置步骤">
|
||
<el-table-column prop="seq" label="序" width="50" align="center" />
|
||
<el-table-column prop="name" label="步骤" min-width="150" show-overflow-tooltip />
|
||
<el-table-column label="录入" min-width="190">
|
||
<template #default="{ row }">
|
||
<!-- 拧紧(自动采集)步骤:虚拟工位无拧紧枪,需在物理工位完成 -->
|
||
<span v-if="row.collectType === 'AUTO'" style="color:#909399;font-size:12px">
|
||
{{ row.isTorque ? '拧紧步骤(需拧紧枪,物理工位采集)' : '自动采集步骤' }}
|
||
</span>
|
||
<template v-else>
|
||
<el-input v-model="stepValues[row.id]" size="small" placeholder="录入数值/结果"
|
||
style="width:110px;margin-right:6px" />
|
||
<el-checkbox v-if="row.needCheck" v-model="stepChecks[row.id]" size="small">检测确认</el-checkbox>
|
||
</template>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="考核标准" min-width="150" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ criteriaText(row) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" width="90" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag v-if="stepDisplay(row).ok" type="success" size="small">合格</el-tag>
|
||
<el-tag v-else-if="stepDisplay(row).filled" type="danger" size="small">不合格</el-tag>
|
||
<el-tag v-else type="info" size="small">待录入</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</el-card>
|
||
</el-col>
|
||
|
||
<!-- 配料(装机绑定) -->
|
||
<el-col :xs="24" :md="11">
|
||
<el-card shadow="never" header="配料(装机绑定,随报工提交)">
|
||
<el-empty v-if="!bindPanel" description="输入工件SN后载入应绑配料" />
|
||
<template v-else-if="!bindPanel.enabled">
|
||
<el-result icon="info" title="本工艺未配置装配物料" sub-title="无需绑定配料,可直接完成报工" />
|
||
</template>
|
||
<template v-else>
|
||
<el-table :data="bindPanel.required || []" border size="small">
|
||
<el-table-column prop="materialCode" label="图号" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="materialName" label="物料" min-width="110" show-overflow-tooltip />
|
||
<el-table-column label="应绑/已绑" width="90" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.complete ? 'success' : 'warning'" size="small">
|
||
{{ row.boundCount }}/{{ row.need }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="本次录入(批次号/SN,多个用逗号分隔)" min-width="200">
|
||
<template #default="{ row }">
|
||
<el-input v-model="bindInputs[row.materialCode]" size="small"
|
||
:placeholder="row.snMode === 1 ? 'SN,逗号分隔' : '批次号'" />
|
||
<div v-if="row.bound && row.bound.length" style="font-size:12px;color:#909399;margin-top:2px"
|
||
:title="row.bound.join('、')">
|
||
已绑:{{ row.bound.join('、') }}
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div v-if="bindPanel.missing" style="color:#f56c6c;font-size:12px;margin-top:8px">{{ bindPanel.missing }}</div>
|
||
</template>
|
||
</el-card>
|
||
</el-col>
|
||
</el-row>
|
||
</template>
|
||
</el-card>
|
||
<PageHelp :data="helpVirtualStation" page="VirtualStation" />
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, reactive, computed, onMounted } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import request from '../utils/request'
|
||
import PageHelp from '../components/PageHelp.vue'
|
||
import { helpVirtualStation } from '../help'
|
||
|
||
const stations = ref([])
|
||
const stationNo = ref(null)
|
||
const task = ref(null)
|
||
const orderNo = ref('')
|
||
const sn = ref('')
|
||
const bindPanel = ref(null)
|
||
const stepValues = reactive({})
|
||
const stepChecks = reactive({})
|
||
const bindInputs = reactive({})
|
||
const startedAt = ref('')
|
||
|
||
const orderNos = computed(() => (Array.isArray(task.value?.orderNos) ? task.value.orderNos : []))
|
||
|
||
// 可报工:选了工单+SN、工艺已绑定;拧紧步骤不拦(在物理工位采集)
|
||
const manualSteps = computed(() => (task.value?.steps || []).filter((s) => s.collectType === 'MANUAL'))
|
||
const canReport = computed(() => {
|
||
if (!stationNo.value || !sn.value || !orderNo.value) return false
|
||
if (!task.value?.flowActive) return false
|
||
const missing = manualSteps.value.some((s) => stepValues[s.id] === undefined || stepValues[s.id] === '')
|
||
return !missing
|
||
})
|
||
|
||
function criteriaText(step) {
|
||
const arr = step.criteria || []
|
||
if (!arr.length) return '-'
|
||
return arr.map((c) => {
|
||
if (c.logic === 'RANGE') return `${c.name}: ${c.min ?? ''}~${c.max ?? ''}${c.unit || ''}`
|
||
if (c.logic === 'GE') return `${c.name} ≥ ${c.target}${c.unit || ''}`
|
||
if (c.logic === 'LE') return `${c.name} ≤ ${c.target}${c.unit || ''}`
|
||
return `${c.name} ${c.logic} ${c.target}`
|
||
}).join(';')
|
||
}
|
||
|
||
// 步骤判定:有考核标准按标准,无标准录入即合格
|
||
function criterionOk(c, v) {
|
||
const n = Number(v)
|
||
if (isNaN(n)) return false
|
||
if (c.logic === 'GE') return n >= Number(c.target)
|
||
if (c.logic === 'LE') return n <= Number(c.target)
|
||
if (c.logic === 'GT') return n > Number(c.target)
|
||
if (c.logic === 'LT') return n < Number(c.target)
|
||
if (c.logic === 'EQUAL') return n === Number(c.target)
|
||
if (c.logic === 'RANGE') {
|
||
if (c.min != null && n < Number(c.min)) return false
|
||
if (c.max != null && n > Number(c.max)) return false
|
||
return true
|
||
}
|
||
return true
|
||
}
|
||
function stepDisplay(step) {
|
||
const v = stepValues[step.id]
|
||
const filled = v !== undefined && v !== null && v !== ''
|
||
if (!filled) return { filled: false, ok: false }
|
||
const crits = step.criteria || []
|
||
if (crits.length) return { filled: true, ok: crits.every((c) => criterionOk(c, v)) }
|
||
return { filled: true, ok: true }
|
||
}
|
||
|
||
async function load() {
|
||
const list = (await request.get('/stations')) || []
|
||
// 虚拟工位作业只允许选择虚拟工位(0/13/14/15),过滤掉实体工位,防止误选
|
||
stations.value = list.filter((s) => s.stationType === 'OFFLINE')
|
||
}
|
||
|
||
async function loadTask() {
|
||
task.value = null
|
||
bindPanel.value = null
|
||
Object.keys(stepValues).forEach((k) => delete stepValues[k])
|
||
Object.keys(stepChecks).forEach((k) => delete stepChecks[k])
|
||
if (stationNo.value === null || stationNo.value === '') return
|
||
try {
|
||
task.value = await request.get('/station/task', { params: { stationNo: stationNo.value } })
|
||
if (orderNos.value.length && !orderNos.value.includes(orderNo.value)) {
|
||
orderNo.value = orderNos.value[0]
|
||
}
|
||
} catch {
|
||
task.value = null
|
||
}
|
||
}
|
||
|
||
// onSnEntered 载入该工件的配料面板(步骤录入本地进行)
|
||
async function onSnEntered() {
|
||
if (!sn.value) return
|
||
if (!startedAt.value) startedAt.value = new Date().toISOString()
|
||
bindPanel.value = null
|
||
Object.keys(bindInputs).forEach((k) => delete bindInputs[k])
|
||
const flowId = Number(task.value?.flowId || 0)
|
||
if (!flowId) return
|
||
try {
|
||
bindPanel.value = await request.get('/workpiece/bind-panel', { params: { sn: sn.value, flowId } })
|
||
} catch {
|
||
bindPanel.value = null
|
||
}
|
||
}
|
||
|
||
// report 完成报工:步骤数据 + 装机绑定 随单提交(与终端同一接口 /station/report)
|
||
async function report() {
|
||
const steps = manualSteps.value.map((s) => ({
|
||
stepId: s.id, name: s.name,
|
||
value: Number(stepValues[s.id]) || 0,
|
||
text: String(stepValues[s.id] ?? ''),
|
||
checked: !!stepChecks[s.id]
|
||
}))
|
||
const binds = []
|
||
if (bindPanel.value?.enabled) {
|
||
for (const r of bindPanel.value.required || []) {
|
||
const raw = String(bindInputs[r.materialCode] || '').trim()
|
||
if (!raw) continue
|
||
for (const v of raw.split(/[,,;;\s]+/).filter(Boolean)) {
|
||
binds.push({ materialCode: r.materialCode, bindValue: v })
|
||
}
|
||
}
|
||
}
|
||
try {
|
||
await request.post('/station/report', {
|
||
sn: sn.value, flowId: Number(task.value.flowId || 0), stationNo: stationNo.value,
|
||
steps, binds, startedAt: startedAt.value, endedAt: new Date().toISOString()
|
||
})
|
||
ElMessage.success('报工成功')
|
||
sn.value = ''
|
||
startedAt.value = ''
|
||
bindPanel.value = null
|
||
Object.keys(bindInputs).forEach((k) => delete bindInputs[k])
|
||
await onSnEntered()
|
||
} catch {
|
||
// 拦截器已提示(缺料/倒序/状态不符等)
|
||
}
|
||
}
|
||
|
||
onMounted(load)
|
||
</script>
|