盘库操作初设计

This commit is contained in:
dxc
2026-02-06 10:16:37 +08:00
parent c1ddb8093f
commit e027ebd4a9
15 changed files with 1227 additions and 30 deletions

View File

@ -0,0 +1,391 @@
<template>
<div class="app-container mobile-optimized">
<el-card class="main-card" shadow="never">
<template #header>
<div class="header-row">
<div class="title">
<span>📷 库存盘点</span>
<el-tag v-if="!showList" type="success" size="small" effect="dark">扫描中</el-tag>
<el-tag v-else type="info" size="small">暂停</el-tag>
</div>
<el-button type="primary" plain @click="openInventoryList" icon="List">
查看清单/手动查找
</el-button>
</div>
</template>
<div class="scanner-container">
<div v-if="!showList" class="camera-active-box">
<QrScanner @decode="onScanSuccess" />
<div class="scan-overlay-tip">将条码对准取景框</div>
</div>
<div v-else class="camera-paused-box" @click="showList = false">
<el-icon :size="60" color="#909399"><VideoPause /></el-icon>
<p>正在查看清单<br>摄像头已暂停</p>
<el-button type="primary" link>点击返回扫描</el-button>
</div>
</div>
<div class="stats-dashboard">
<div class="stat-card">
<div class="stat-val">{{ stats.total }}</div>
<div class="stat-label">应盘总数</div>
</div>
<div class="stat-card success">
<div class="stat-val">{{ stats.scanned }}</div>
<div class="stat-label">已扫(相符)</div>
</div>
<div class="stat-card error">
<div class="stat-val">{{ stats.missing }}</div>
<div class="stat-label">差异(未扫)</div>
</div>
</div>
<div class="main-actions">
<el-button
type="danger"
size="large"
class="finish-btn"
@click="handleFinish"
:loading="printing"
:disabled="stats.total === 0"
icon="Printer"
>
结束盘点并打印差异报告
</el-button>
<p class="printer-tip">目标打印机: 192.168.9.205</p>
</div>
</el-card>
<el-drawer
v-model="showList"
title="📦 在库物品清单"
direction="btt"
size="90%"
:with-header="true"
destroy-on-close
class="inventory-drawer"
>
<div class="drawer-content">
<div class="search-bar">
<el-input
v-model="searchKeyword"
placeholder="搜索名称 / 规格 / 条码"
prefix-icon="Search"
clearable
size="large"
/>
<el-select
v-model="filterType"
placeholder="类型"
style="width: 100px; margin-left: 8px;"
size="large"
>
<el-option label="全部" value="all" />
<el-option label="采购" value="material" />
<el-option label="半成品" value="semi" />
<el-option label="成品" value="product" />
</el-select>
</div>
<el-table
:data="filteredList"
height="100%"
style="width: 100%; flex: 1;"
stripe
border
row-key="uniqueKey"
>
<el-table-column prop="name" label="名称" min-width="120" show-overflow-tooltip />
<el-table-column prop="standard" label="规格" min-width="100" show-overflow-tooltip />
<el-table-column prop="uuid" label="条码后6位" width="100">
<template #default="scope">
{{ scope.row.uuid ? '...' + scope.row.uuid.slice(-6) : '-' }}
</template>
</el-table-column>
<el-table-column label="状态" width="80" align="center" fixed="right">
<template #default="scope">
<el-tag v-if="scope.row.scanned" type="success" effect="dark">已盘</el-tag>
<el-tag v-else type="danger" effect="plain">未扫</el-tag>
</template>
</el-table-column>
</el-table>
</div>
</el-drawer>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { getAllStock, printStocktakeReport } from '@/api/inbound/stock'
import QrScanner from '@/components/QrScanner/index.vue'
import { ElMessage, ElNotification, ElMessageBox } from 'element-plus'
import { Search, List, Printer, VideoPause } from '@element-plus/icons-vue'
// --- 类型定义 ---
interface StockItem {
id: number
name: string
standard: string
batch_no: string
uuid: string
bar_code: string
scanned: boolean
category_type: 'material' | 'semi' | 'product'
category_label: string
uniqueKey: string
[key: string]: any
}
// --- 状态管理 ---
const printing = ref(false)
const showList = ref(false) // 控制抽屉显示
const filterType = ref('all')
const searchKeyword = ref('')
const allData = ref<StockItem[]>([])
// --- 初始化 ---
const init = async () => {
try {
const res = await getAllStock()
const list: StockItem[] = []
const processItem = (item: any, type: 'material' | 'semi' | 'product', label: string) => {
const name = item.material_name || item.product_name || item.name || '未知物品'
return {
...item,
name: name,
standard: item.standard || '',
batch_no: item.batch_no || item.batch_number || '',
uuid: item.uuid || item.sku || '',
bar_code: item.bar_code || item.barcode || '',
scanned: false,
category_type: type,
category_label: label,
uniqueKey: `${type}_${item.id}`
}
}
if (res.materials) res.materials.forEach((i: any) => list.push(processItem(i, 'material', '采购件')))
if (res.semis) res.semis.forEach((i: any) => list.push(processItem(i, 'semi', '半成品')))
if (res.products) res.products.forEach((i: any) => list.push(processItem(i, 'product', '成品')))
allData.value = list
ElMessage.success(`加载成功,共 ${list.length} 件物品`)
} catch (e) {
ElMessage.error('库存加载失败,请重试')
}
}
// --- 打开清单 (同时会自动触发 v-if 销毁摄像头) ---
const openInventoryList = () => {
showList.value = true
}
// --- 过滤逻辑 ---
const filteredList = computed(() => {
let result = allData.value
if (filterType.value !== 'all') {
result = result.filter(item => item.category_type === filterType.value)
}
if (searchKeyword.value) {
const kw = searchKeyword.value.toLowerCase().trim()
result = result.filter(item =>
(item.name && item.name.toLowerCase().includes(kw)) ||
(item.standard && item.standard.toLowerCase().includes(kw)) ||
(item.uuid && item.uuid.toLowerCase().includes(kw)) ||
(item.bar_code && item.bar_code.toLowerCase().includes(kw))
)
}
return result
})
const stats = computed(() => {
const total = allData.value.length
const scanned = allData.value.filter(i => i.scanned).length
return { total, scanned, missing: total - scanned }
})
// --- 扫码逻辑 ---
const onScanSuccess = (code: string) => {
if (!code) return
const trimCode = code.trim()
const item = allData.value.find(i => i.uuid === trimCode || i.bar_code === trimCode)
if (item) {
if (item.scanned) {
ElMessage.warning(`${item.name} 已扫过`)
return
}
item.scanned = true
// 震动反馈 (如果设备支持)
if (navigator.vibrate) navigator.vibrate(200);
ElNotification({
title: '✅ 匹配成功',
message: `${item.name}\n${item.standard}`,
type: 'success',
duration: 2000,
position: 'top-left' // 移动端通常顶部提示更明显
})
} else {
ElMessage.error(`未找到: ${trimCode}`)
if (navigator.vibrate) navigator.vibrate([100, 50, 100]);
}
}
// --- 结束打印 ---
const handleFinish = async () => {
if (stats.value.total === 0) return
try {
await ElMessageBox.confirm(
`应盘: ${stats.value.total} | 差异: ${stats.value.missing}\n确认结束并打印`,
'结束盘点',
{ confirmButtonText: '打印报告', cancelButtonText: '取消', type: 'warning', center: true }
)
const missingItems = allData.value.filter(i => !i.scanned)
const payload = {
total: stats.value.total,
scanned: stats.value.scanned,
missing: stats.value.missing,
missing_items: missingItems
}
printing.value = true
await printStocktakeReport(payload)
ElMessage.success('打印指令已发送')
} catch (e) {
if (e !== 'cancel') ElMessage.error('打印失败')
} finally {
printing.value = false
}
}
onMounted(() => {
init()
})
</script>
<style scoped>
/* 移动端容器适配 */
.app-container.mobile-optimized {
padding: 10px;
max-width: 600px; /* 在平板/PC上限制宽度保持手机观感 */
margin: 0 auto;
}
/* 头部样式 */
.header-row {
display: flex;
justify-content: space-between;
align-items: center;
}
.header-row .title {
display: flex;
flex-direction: column;
gap: 4px;
font-weight: bold;
font-size: 16px;
}
/* 扫描区域 */
.scanner-container {
height: 35vh; /* 占据屏幕高度的 35% */
background: #000;
border-radius: 12px;
overflow: hidden;
margin-bottom: 15px;
position: relative;
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
.camera-active-box {
width: 100%;
height: 100%;
}
.scan-overlay-tip {
position: absolute;
bottom: 10px;
left: 0;
width: 100%;
text-align: center;
color: rgba(255, 255, 255, 0.8);
font-size: 12px;
background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
padding: 10px 0;
pointer-events: none;
}
.camera-paused-box {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #f0f2f5;
color: #909399;
cursor: pointer;
text-align: center;
}
/* 统计仪表盘 */
.stats-dashboard {
display: flex;
gap: 10px;
margin-bottom: 20px;
}
.stat-card {
flex: 1;
background: #f8f9fa;
border-radius: 8px;
padding: 15px 5px;
text-align: center;
border: 1px solid #ebeef5;
}
.stat-card .stat-val {
font-size: 24px;
font-weight: 800;
line-height: 1.2;
}
.stat-card .stat-label {
font-size: 12px;
color: #909399;
margin-top: 4px;
}
.stat-card.success .stat-val { color: #67c23a; }
.stat-card.error .stat-val { color: #f56c6c; }
/* 底部按钮 */
.main-actions {
margin-top: 10px;
}
.finish-btn {
height: 50px;
font-size: 16px;
border-radius: 25px; /* 圆角按钮更好点 */
}
.printer-tip {
text-align: center;
font-size: 12px;
color: #909399;
margin-top: 12px;
}
/* 抽屉内容布局 */
.drawer-content {
height: 100%;
display: flex;
flex-direction: column;
padding: 10px;
}
.search-bar {
display: flex;
margin-bottom: 10px;
}
</style>