盘库操作初设计

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,302 @@
<template>
<div class="app-container">
<el-card shadow="always">
<template #header>
<div class="card-header">
<div class="header-left">
<span class="title">出库拣货选单</span>
<span class="subtitle">(打印目标: 192.168.9.205)</span>
</div>
<div>
<el-button type="success" :icon="Printer" :disabled="selectedItems.length === 0" @click="handlePreview">
生成并预览出库单
</el-button>
</div>
</div>
</template>
<div class="filter-container">
<el-row :gutter="20">
<el-col :span="12">
<el-input
v-model="searchKeyword"
placeholder="请输入物料名称 或 规格型号 进行搜索"
class="search-input"
clearable
:prefix-icon="Search"
/>
</el-col>
<el-col :span="12" style="text-align: right;">
<el-button type="primary" plain :icon="Upload" @click="handleImportBom">
导入 BOM
</el-button>
<el-button type="primary" plain :icon="Plus" @click="handleCreateBom">
创建 BOM
</el-button>
</el-col>
</el-row>
</div>
<el-alert
v-if="selectedItems.length > 0"
:title="`当前已选中 ${selectedItems.length} 项物品`"
type="success"
show-icon
style="margin-bottom: 15px"
:closable="false"
/>
<el-table
v-loading="loading"
:data="filteredTableData"
style="width: 100%"
@selection-change="handleSelectionChange"
row-key="uuid"
border
height="600"
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="类型" width="100" align="center">
<template #default="{ row }">
<el-tag :type="getTypeTag(row.type)">{{ row.typeLabel }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="name" label="名称" min-width="150" show-overflow-tooltip>
<template #default="{ row }">
<span v-html="highlightKeyword(row.name)"></span>
</template>
</el-table-column>
<el-table-column prop="standard" label="规格型号" min-width="150" show-overflow-tooltip>
<template #default="{ row }">
<span v-html="highlightKeyword(row.standard)"></span>
</template>
</el-table-column>
<el-table-column prop="batch_no" label="批号" width="120" />
<el-table-column prop="uuid" label="条码UUID" width="280" show-overflow-tooltip />
<el-table-column prop="create_time" label="入库时间" width="170" />
</el-table>
</el-card>
<el-dialog
v-model="previewVisible"
title="出库单打印预览"
width="800px"
destroy-on-close
>
<div class="print-preview-content">
<el-alert title="请核对以下清单,确认无误后点击下方【确认打印】按钮" type="warning" :closable="false" style="margin-bottom: 10px;" />
<el-table :data="selectedItems" border size="small" style="width: 100%">
<el-table-column prop="typeLabel" label="类型" width="80" />
<el-table-column prop="name" label="名称" />
<el-table-column prop="standard" label="规格" />
<el-table-column prop="batch_no" label="批号" width="100" />
<el-table-column prop="uuid" label="条码UUID" show-overflow-tooltip />
</el-table>
<div class="summary-info" style="margin-top: 20px; text-align: right; font-weight: bold;">
总计出库数量: <span style="color: red; font-size: 18px;">{{ selectedItems.length }}</span>
</div>
</div>
<template #footer>
<span class="dialog-footer">
<el-button @click="previewVisible = false">取消</el-button>
<el-button type="primary" :loading="printLoading" @click="confirmPrint">
确认打印
</el-button>
</span>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { Printer, Search, Upload, Plus } from '@element-plus/icons-vue'
import { getAllStock, printSelectionList } from '@/api/inbound/stock'
import { ElMessage, ElMessageBox } from 'element-plus'
// --- 类型定义 ---
interface BaseStockItem {
id: number | string;
standard: string;
batch_no: string;
uuid: string;
create_time: string;
// 原始数据中可能存在的字段
material_name?: string;
product_name?: string;
}
// 统一后的显示对象
interface DisplayItem extends BaseStockItem {
name: string; // 统一后的名称
type: 'material' | 'semi' | 'product'; // 类型标识
typeLabel: string; // 类型中文名
}
// --- 状态变量 ---
const loading = ref(false)
const printLoading = ref(false)
const searchKeyword = ref('') // 搜索关键词
const previewVisible = ref(false) // 预览弹窗控制
// 原始扁平化数据
const allStockData = ref<DisplayItem[]>([])
// 当前选中的行
const selectedItems = ref<DisplayItem[]>([])
// --- 计算属性:前端模糊搜索过滤 ---
const filteredTableData = computed(() => {
const keyword = searchKeyword.value.trim().toLowerCase()
if (!keyword) {
return allStockData.value
}
return allStockData.value.filter(item => {
const nameMatch = item.name && item.name.toLowerCase().includes(keyword)
const stdMatch = item.standard && item.standard.toLowerCase().includes(keyword)
// 也可以加上UUID搜索
const uuidMatch = item.uuid && item.uuid.toLowerCase().includes(keyword)
return nameMatch || stdMatch || uuidMatch
})
})
// --- 方法 ---
// 1. 获取并处理数据
const fetchData = async () => {
loading.value = true
try {
const res: any = await getAllStock()
// 假设 res 结构为 { materials: [], semis: [], products: [] }
const materials = (res.materials || []).map((item: any) => ({
...item,
name: item.material_name,
type: 'material',
typeLabel: '采购件'
}))
const semis = (res.semis || []).map((item: any) => ({
...item,
name: item.material_name || item.product_name, // 半成品字段名不确定,做个兼容
type: 'semi',
typeLabel: '半成品'
}))
const products = (res.products || []).map((item: any) => ({
...item,
name: item.product_name,
type: 'product',
typeLabel: '成品'
}))
// 合并所有数据
allStockData.value = [...materials, ...semis, ...products]
} catch (error) {
console.error(error)
ElMessage.error('无法获取库存数据')
} finally {
loading.value = false
}
}
// 2. 表格选择
const handleSelectionChange = (val: DisplayItem[]) => {
selectedItems.value = val
}
// 3. 点击“生成并预览”
const handlePreview = () => {
if (selectedItems.value.length === 0) {
ElMessage.warning('请先勾选需要出库的物品')
return
}
previewVisible.value = true
}
// 4. 确认打印 (在弹窗中触发)
const confirmPrint = async () => {
printLoading.value = true
try {
// 这里调用真实的打印接口
await printSelectionList(selectedItems.value)
ElMessage.success('指令已发送,请前往打印机(192.168.9.205)取单')
previewVisible.value = false // 关闭弹窗
// 可选:打印后是否清空选中?
// selectedItems.value = []
// 注意el-table 需要调用 clearSelection 方法来清空UI选中状态
} catch (err) {
ElMessage.error('打印请求失败')
} finally {
printLoading.value = false
}
}
// 5. BOM 操作占位函数
const handleImportBom = () => {
// TODO: 打开上传文件的 Dialog 或者跳转页面
ElMessage.info('点击了导入BOM请实现具体逻辑')
}
const handleCreateBom = () => {
// TODO: 打开新建 BOM 的表单
ElMessage.info('点击了创建BOM请实现具体逻辑')
}
// 辅助函数:高亮关键词 (可选)
const highlightKeyword = (text: string) => {
if (!searchKeyword.value || !text) return text
const reg = new RegExp(searchKeyword.value, 'gi')
return text.replace(reg, (match) => `<span style="color: red; font-weight: bold;">${match}</span>`)
}
// 辅助函数:标签颜色
const getTypeTag = (type: string) => {
switch (type) {
case 'material': return 'info'
case 'semi': return 'warning'
case 'product': return 'success'
default: return ''
}
}
onMounted(() => {
fetchData()
})
</script>
<style scoped>
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.header-left .title {
font-size: 18px;
font-weight: bold;
margin-right: 10px;
}
.header-left .subtitle {
font-size: 12px;
color: #909399;
}
.filter-container {
margin-bottom: 20px;
background-color: #f5f7fa;
padding: 15px;
border-radius: 4px;
}
.search-input {
width: 100%;
max-width: 400px;
}
</style>

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>