|
|
|
|
@ -150,6 +150,7 @@ import { useI18n } from 'vue-i18n'
|
|
|
|
|
import NavBar from '@/components/common/NavBar.vue'
|
|
|
|
|
import { getDeviceLedgerList, createMoldOperate } from '@/api/mes/moldoperate'
|
|
|
|
|
import { getMoldBrandPage } from '@/api/mes/mold'
|
|
|
|
|
import { getDeviceLineTree } from '@/api/mes/deviceLine'
|
|
|
|
|
import useUserStore from '@/store/modules/user'
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
@ -190,6 +191,70 @@ async function loadDevices() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 产线树 - 用于设备产线名称转换
|
|
|
|
|
const lineInfoMap = ref(new Map())
|
|
|
|
|
|
|
|
|
|
function flattenLineTree(nodes, parentId) {
|
|
|
|
|
if (!Array.isArray(nodes)) return
|
|
|
|
|
for (const node of nodes) {
|
|
|
|
|
if (node.id != null && node.name != null) {
|
|
|
|
|
lineInfoMap.value.set(String(node.id), {
|
|
|
|
|
id: node.id,
|
|
|
|
|
name: node.name,
|
|
|
|
|
parentId: node.parentId != null ? node.parentId : (parentId || null),
|
|
|
|
|
parentChain: node.parentChain || ''
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (Array.isArray(node.children)) {
|
|
|
|
|
flattenLineTree(node.children, node.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getTopLineName(deviceLineId) {
|
|
|
|
|
if (deviceLineId == null) return '-'
|
|
|
|
|
const node = lineInfoMap.value.get(String(deviceLineId))
|
|
|
|
|
if (!node) return '-'
|
|
|
|
|
if (node.parentChain) {
|
|
|
|
|
const firstId = node.parentChain.split(',')[0]?.trim()
|
|
|
|
|
if (firstId) {
|
|
|
|
|
const topNode = lineInfoMap.value.get(firstId)
|
|
|
|
|
if (topNode) return topNode.name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let current = node
|
|
|
|
|
const visited = new Set()
|
|
|
|
|
while (current.parentId != null && current.parentId > 0 && !visited.has(current.id)) {
|
|
|
|
|
visited.add(current.id)
|
|
|
|
|
const parent = lineInfoMap.value.get(String(current.parentId))
|
|
|
|
|
if (!parent) break
|
|
|
|
|
current = parent
|
|
|
|
|
}
|
|
|
|
|
return current.name || '-'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function loadLineTree() {
|
|
|
|
|
if (lineInfoMap.value.size > 0) return
|
|
|
|
|
try {
|
|
|
|
|
const res = await getDeviceLineTree()
|
|
|
|
|
const tree = (res && res.data !== undefined) ? res.data : res
|
|
|
|
|
const nodes = Array.isArray(tree) ? tree : (tree?.list || tree?.children || [])
|
|
|
|
|
flattenLineTree(nodes)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('load line tree error', e)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置设备产线名称(从产线树转换)
|
|
|
|
|
function setDeviceLineName(device) {
|
|
|
|
|
if (device && device.deviceLine != null) {
|
|
|
|
|
const lineName = getTopLineName(device.deviceLine)
|
|
|
|
|
if (lineName && lineName !== '-') {
|
|
|
|
|
device.workshopName = lineName
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== 上模模块 ====================
|
|
|
|
|
const selectedDevice = ref({})
|
|
|
|
|
|
|
|
|
|
@ -238,13 +303,10 @@ async function fetchCurrentMolds(deviceName) {
|
|
|
|
|
try {
|
|
|
|
|
// 查模具型号表,按当前设备名称筛选
|
|
|
|
|
const params = { deviceName, pageSize: 100 }
|
|
|
|
|
console.log('[上模] fetchCurrentMolds 请求参数:', JSON.stringify(params))
|
|
|
|
|
const res = await getMoldBrandPage(params)
|
|
|
|
|
console.log('[上模] fetchCurrentMolds 原始响应:', JSON.stringify(res))
|
|
|
|
|
const root = res && res.data !== undefined ? res.data : res
|
|
|
|
|
const pageData = root?.pageResult || root
|
|
|
|
|
const list = Array.isArray(pageData) ? pageData : (Array.isArray(pageData?.list) ? pageData.list : [])
|
|
|
|
|
console.log('[上模] fetchCurrentMolds 解析后:', list.length, '条数据', list.map(m => ({ id: m.id, name: m.name, currentDevice: m.currentDevice })))
|
|
|
|
|
currentMoldList.value = list
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error('fetchCurrentMolds error', e)
|
|
|
|
|
@ -350,12 +412,31 @@ function handleScan() {
|
|
|
|
|
onlyFromCamera: false,
|
|
|
|
|
scanType: ['qrCode', 'barCode'],
|
|
|
|
|
success(res) {
|
|
|
|
|
const code = res.result?.trim()
|
|
|
|
|
const code = (res.result || '').trim()
|
|
|
|
|
if (!code) return
|
|
|
|
|
const matched = deviceOptions.value.find((d) =>
|
|
|
|
|
d.raw.deviceCode === code || String(d.raw.code) === code || d.label.includes(code)
|
|
|
|
|
)
|
|
|
|
|
let matched = null
|
|
|
|
|
// 格式1: EQUIPMENT-{设备ID}
|
|
|
|
|
if (code.toUpperCase().startsWith('EQUIPMENT-')) {
|
|
|
|
|
const idFromQr = code.replace(/EQUIPMENT-/i, '')
|
|
|
|
|
matched = deviceOptions.value.find((d) => String(d.raw.id) === idFromQr)
|
|
|
|
|
}
|
|
|
|
|
// 格式2: 匹配设备字段或 label
|
|
|
|
|
if (!matched) {
|
|
|
|
|
matched = deviceOptions.value.find((d) =>
|
|
|
|
|
Object.values(d.raw).some((v) =>
|
|
|
|
|
typeof v === 'string' && v.trim().toUpperCase() === code.toUpperCase()
|
|
|
|
|
) || d.label.toUpperCase().includes(code.toUpperCase())
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
// 格式3: 提取末尾数字匹配设备ID
|
|
|
|
|
if (!matched) {
|
|
|
|
|
const idMatch = code.match(/(\d+)$/)
|
|
|
|
|
if (idMatch) {
|
|
|
|
|
matched = deviceOptions.value.find((d) => String(d.raw.id) === idMatch[1])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (matched) {
|
|
|
|
|
setDeviceLineName(matched.raw)
|
|
|
|
|
selectDevice(matched.raw)
|
|
|
|
|
} else {
|
|
|
|
|
uni.showToast({ title: t('moldOperate.deviceNotFound'), icon: 'none' })
|
|
|
|
|
@ -385,7 +466,7 @@ function goToHistory() {
|
|
|
|
|
|
|
|
|
|
onShow(async () => {
|
|
|
|
|
autoSetOperator()
|
|
|
|
|
await Promise.allSettled([loadDevices()])
|
|
|
|
|
await Promise.allSettled([loadDevices(), loadLineTree()])
|
|
|
|
|
// 从 globalData 读取设备选择页回传的设备
|
|
|
|
|
const device = getApp().globalData._deviceSelectResult
|
|
|
|
|
if (device) {
|
|
|
|
|
|