盘库操作初设计
This commit is contained in:
@ -2,18 +2,19 @@ from flask import Blueprint
|
||||
from .buy import inbound_buy_bp
|
||||
from .semi import inbound_semi_bp
|
||||
from .base import inbound_base_bp
|
||||
# 导入 product
|
||||
from .product import inbound_product_bp
|
||||
# ★ [新增] 导入 summary
|
||||
from .inbound_summary import bp as inbound_summary_bp
|
||||
# ★ [新增] 导入 stock 模块
|
||||
from .stock import bp as stock_bp
|
||||
|
||||
inbound_bp = Blueprint('inbound', __name__)
|
||||
|
||||
inbound_bp.register_blueprint(inbound_buy_bp, url_prefix='/buy')
|
||||
inbound_bp.register_blueprint(inbound_semi_bp, url_prefix='/semi')
|
||||
inbound_bp.register_blueprint(inbound_base_bp, url_prefix='/base')
|
||||
# 挂载 product,前缀改为 /product
|
||||
inbound_bp.register_blueprint(inbound_product_bp, url_prefix='/product')
|
||||
inbound_bp.register_blueprint(inbound_summary_bp, url_prefix='/summary')
|
||||
|
||||
# ★ [新增] 挂载 summary, url 变成 /api/v1/inbound/summary/list
|
||||
inbound_bp.register_blueprint(inbound_summary_bp, url_prefix='/summary')
|
||||
# ★ [新增] 挂载 stock 模块,路径前缀为 /stock
|
||||
# 最终访问路径例:/api/v1/inbound/stock/all
|
||||
inbound_bp.register_blueprint(stock_bp, url_prefix='/stock')
|
||||
@ -3,7 +3,7 @@ from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.base_service import MaterialBaseService
|
||||
import traceback
|
||||
|
||||
inbound_base_bp = Blueprint('inbound_base', __name__)
|
||||
inbound_base_bp = Blueprint('stock_base', __name__)
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
|
||||
@ -3,7 +3,7 @@ from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.buy_service import BuyInboundService
|
||||
import traceback
|
||||
|
||||
inbound_buy_bp = Blueprint('inbound_buy', __name__)
|
||||
inbound_buy_bp = Blueprint('stock_buy', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@ -3,7 +3,7 @@ from flask import Blueprint, request, jsonify
|
||||
from app.services.inbound.product_service import ProductInboundService
|
||||
import traceback
|
||||
|
||||
inbound_product_bp = Blueprint('inbound_product', __name__)
|
||||
inbound_product_bp = Blueprint('stock_product', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@ -4,7 +4,7 @@ from app.services.inbound.semi_service import SemiInboundService
|
||||
import traceback
|
||||
|
||||
# 定义蓝图
|
||||
inbound_semi_bp = Blueprint('inbound_semi', __name__)
|
||||
inbound_semi_bp = Blueprint('stock_semi', __name__)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
98
inventory-backend/app/api/v1/inbound/stock.py
Normal file
98
inventory-backend/app/api/v1/inbound/stock.py
Normal file
@ -0,0 +1,98 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
# ★ [核心修复] 导入正确的模型类名 StockBuy (替换原来的 InboundBuy)
|
||||
from app.models.inbound.buy import StockBuy
|
||||
|
||||
# 尝试导入半成品和成品模型 (根据你的命名习惯修正为 StockSemi/StockProduct)
|
||||
# 使用 try-except 防止如果其他文件还没改名导致再次报错
|
||||
try:
|
||||
from app.models.inbound.semi import StockSemi
|
||||
except ImportError:
|
||||
StockSemi = None
|
||||
|
||||
try:
|
||||
from app.models.inbound.product import StockProduct
|
||||
except ImportError:
|
||||
StockProduct = None
|
||||
|
||||
from app.services.print.network_print_service import NetworkPrintService
|
||||
|
||||
bp = Blueprint('stock_ops', __name__)
|
||||
|
||||
|
||||
@bp.route('/all', methods=['GET'])
|
||||
def get_all_stock():
|
||||
"""
|
||||
获取所有在库物品(采购件+半成品+成品)
|
||||
用于:盘点初始化、出库选单列表
|
||||
"""
|
||||
try:
|
||||
# 1. 获取采购件
|
||||
# ★ [核心修复] 使用 StockBuy 查询,并将状态条件改为 '在库' (匹配你的 Model 定义)
|
||||
materials = []
|
||||
if StockBuy:
|
||||
materials = StockBuy.query.filter(StockBuy.status == '在库').all()
|
||||
|
||||
# 2. 获取半成品
|
||||
semis = []
|
||||
if StockSemi:
|
||||
try:
|
||||
# 假设半成品也使用 '在库' 状态
|
||||
semis = StockSemi.query.filter(StockSemi.status == '在库').all()
|
||||
except Exception:
|
||||
semis = []
|
||||
|
||||
# 3. 获取成品
|
||||
products = []
|
||||
if StockProduct:
|
||||
try:
|
||||
products = StockProduct.query.filter(StockProduct.status == '在库').all()
|
||||
except Exception:
|
||||
products = []
|
||||
|
||||
return jsonify({
|
||||
"materials": [item.to_dict() for item in materials],
|
||||
"semis": [item.to_dict() for item in semis],
|
||||
"products": [item.to_dict() for item in products]
|
||||
}), 200
|
||||
except Exception as e:
|
||||
print(f"Error in get_all_stock: {e}") # 输出错误日志以便调试
|
||||
return jsonify({"message": f"查询库存失败: {str(e)}"}), 500
|
||||
|
||||
|
||||
@bp.route('/print/selection', methods=['POST'])
|
||||
def print_selection():
|
||||
"""打印出库选单"""
|
||||
try:
|
||||
data = request.json
|
||||
items = data.get('items', [])
|
||||
|
||||
if not items:
|
||||
return jsonify({"message": "未选择任何物品"}), 400
|
||||
|
||||
printer = NetworkPrintService() # 默认连接 192.168.9.205
|
||||
success, msg = printer.print_outbound_selection(items)
|
||||
|
||||
if success:
|
||||
return jsonify({"message": "打印指令已发送"}), 200
|
||||
else:
|
||||
return jsonify({"message": msg}), 500
|
||||
except Exception as e:
|
||||
return jsonify({"message": f"打印服务错误: {str(e)}"}), 500
|
||||
|
||||
|
||||
@bp.route('/print/stocktake', methods=['POST'])
|
||||
def print_stocktake():
|
||||
"""打印盘点报告"""
|
||||
try:
|
||||
data = request.json
|
||||
# data 结构: { total, scanned, missing, missing_items: [] }
|
||||
|
||||
printer = NetworkPrintService()
|
||||
success, msg = printer.print_stocktake_report(data)
|
||||
|
||||
if success:
|
||||
return jsonify({"message": "盘点报告已发送"}), 200
|
||||
else:
|
||||
return jsonify({"message": msg}), 500
|
||||
except Exception as e:
|
||||
return jsonify({"message": f"打印服务错误: {str(e)}"}), 500
|
||||
@ -1,13 +1,19 @@
|
||||
# app/models/__init__.py
|
||||
|
||||
# 1. 基础物料
|
||||
# 1. 基础物料 (必须先加载,因为 buy 依赖它)
|
||||
from app.models.base import MaterialBase
|
||||
|
||||
# 2. 采购入库 (指向新路径)
|
||||
# 2. 采购入库 (现在的类名是 StockBuy)
|
||||
from app.models.inbound.buy import StockBuy
|
||||
|
||||
# 3. 半成品入库 (指向新路径)
|
||||
from app.models.inbound.semi import StockSemi
|
||||
# 3. 半成品入库 (如果有)
|
||||
try:
|
||||
from app.models.inbound.semi import StockSemi
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# 如果有其他模型 (比如 sys_user 等),保留它们
|
||||
# from app.models.sys_user import SysUser
|
||||
# 4. 出库记录 (如果有,BuyService 用到了 TransOutbound)
|
||||
try:
|
||||
from app.models.outbound import TransOutbound
|
||||
except ImportError:
|
||||
pass
|
||||
@ -1,8 +1,6 @@
|
||||
# app/models/inbound/buy.py
|
||||
from app.extensions import db
|
||||
import json
|
||||
|
||||
|
||||
class StockBuy(db.Model):
|
||||
"""
|
||||
采购入库库存表
|
||||
@ -21,7 +19,7 @@ class StockBuy(db.Model):
|
||||
batch_number = db.Column(db.String(100))
|
||||
|
||||
# 状态
|
||||
status = db.Column(db.String(50))
|
||||
status = db.Column(db.String(50), default='在库')
|
||||
inspection_status = db.Column(db.String(50))
|
||||
warehouse_location = db.Column(db.String(100))
|
||||
|
||||
@ -51,6 +49,7 @@ class StockBuy(db.Model):
|
||||
global_print_id = db.Column(db.Integer)
|
||||
|
||||
# 关系定义
|
||||
# 注意:这里使用字符串 'MaterialBase' 引用,避免了直接 import 导致的潜在循环依赖
|
||||
material = db.relationship('MaterialBase', back_populates='stock_buys')
|
||||
|
||||
def to_dict(self):
|
||||
|
||||
@ -1,9 +1,15 @@
|
||||
# app/services/inbound/buy_service.py
|
||||
from app.extensions import db
|
||||
# 引用新的模型类 StockBuy
|
||||
from app.models.inbound.buy import StockBuy
|
||||
from app.models.base import MaterialBase
|
||||
from app.models.outbound import TransOutbound
|
||||
from datetime import datetime, timedelta, timezone # [修改] 引入 timezone
|
||||
|
||||
# 尝试导入出库模型,如果不存在则忽略(防止报错影响入库功能)
|
||||
try:
|
||||
from app.models.outbound import TransOutbound
|
||||
except ImportError:
|
||||
TransOutbound = None
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from sqlalchemy import or_, func, text, and_
|
||||
import traceback
|
||||
import json
|
||||
@ -76,11 +82,22 @@ class BuyInboundService:
|
||||
in_qty = float(data.get('in_quantity') or 0)
|
||||
u_price = float(data.get('unit_price') or 0)
|
||||
|
||||
seq_sql = text("SELECT nextval('global_print_seq')")
|
||||
result = db.session.execute(seq_sql)
|
||||
next_global_id = result.scalar()
|
||||
# [核心逻辑] 获取全局打印流水号
|
||||
try:
|
||||
seq_sql = text("SELECT nextval('global_print_seq')")
|
||||
result = db.session.execute(seq_sql)
|
||||
next_global_id = result.scalar()
|
||||
except Exception:
|
||||
# 如果序列不存在,回退处理(或在数据库创建序列)
|
||||
print("Warning: Sequence global_print_seq not found.")
|
||||
next_global_id = None
|
||||
|
||||
# SKU 生成逻辑:如果没有 ID,用临时随机数或空;通常应该依赖 next_global_id
|
||||
if next_global_id:
|
||||
generated_sku = str(next_global_id).zfill(10)
|
||||
else:
|
||||
generated_sku = datetime.now().strftime('%Y%m%d%H%M%S') # 降级方案
|
||||
|
||||
generated_sku = str(next_global_id).zfill(10)
|
||||
final_barcode = data.get('barcode') or generated_sku
|
||||
|
||||
arrival_list = data.get('arrival_photo', [])
|
||||
@ -151,6 +168,7 @@ class BuyInboundService:
|
||||
|
||||
if 'in_quantity' in data:
|
||||
new_qty = float(data['in_quantity'])
|
||||
# 计算差值,同步更新库存量和可用量
|
||||
diff = new_qty - float(stock.in_quantity)
|
||||
if diff != 0:
|
||||
stock.in_quantity = new_qty
|
||||
@ -189,6 +207,8 @@ class BuyInboundService:
|
||||
@staticmethod
|
||||
def get_outbound_history(stock_id):
|
||||
"""获取出库历史"""
|
||||
if not TransOutbound:
|
||||
return []
|
||||
try:
|
||||
records = TransOutbound.query.filter_by(
|
||||
source_table='stock_buy', stock_id=stock_id
|
||||
@ -228,8 +248,10 @@ class BuyInboundService:
|
||||
statuses = ['在库', '借库']
|
||||
|
||||
if '已出库' in statuses:
|
||||
# 如果明确查已出库,可以包含库存为0的
|
||||
query = query.filter(StockBuy.status.in_(statuses))
|
||||
else:
|
||||
# 默认查在库,必须保证库存 > 0
|
||||
query = query.filter(
|
||||
and_(
|
||||
StockBuy.status.in_(statuses),
|
||||
|
||||
114
inventory-backend/app/services/print/network_print_service.py
Normal file
114
inventory-backend/app/services/print/network_print_service.py
Normal file
@ -0,0 +1,114 @@
|
||||
import socket
|
||||
import datetime
|
||||
|
||||
|
||||
class NetworkPrintService:
|
||||
def __init__(self, ip='192.168.9.205', port=9100):
|
||||
"""
|
||||
初始化网络打印机服务
|
||||
:param ip: 打印机IP,默认 192.168.9.205
|
||||
:param port: 端口,默认 9100
|
||||
"""
|
||||
self.ip = ip
|
||||
self.port = port
|
||||
|
||||
def _send_to_printer(self, content):
|
||||
"""底层发送方法"""
|
||||
try:
|
||||
# 建立 Socket 连接
|
||||
with socket.socket(socket.socket.AF_INET, socket.socket.SOCK_STREAM) as s:
|
||||
s.settimeout(5) # 设置5秒超时
|
||||
s.connect((self.ip, self.port))
|
||||
|
||||
# 发送内容,使用 GB18030 编码以支持中文
|
||||
s.sendall(content.encode('gb18030'))
|
||||
|
||||
# 发送切纸指令 (ESC/POS: GS V m)
|
||||
# 十六进制: 1D 56 42 00
|
||||
s.sendall(b'\x1d\x56\x42\x00')
|
||||
|
||||
return True, "打印成功"
|
||||
except Exception as e:
|
||||
print(f"[NetworkPrint Error] {str(e)}")
|
||||
return False, f"打印失败: {str(e)}"
|
||||
|
||||
def print_outbound_selection(self, items):
|
||||
"""
|
||||
打印出库选单 (拣货单)
|
||||
:param items: 选中的物品列表
|
||||
"""
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
lines = []
|
||||
lines.append("\n")
|
||||
lines.append("********************************")
|
||||
lines.append(" 出库拣货确认单 ")
|
||||
lines.append("********************************")
|
||||
lines.append(f"打印时间: {timestamp}")
|
||||
lines.append(f"待出库总数: {len(items)} 件")
|
||||
lines.append("--------------------------------")
|
||||
lines.append(f"{'名称':<14}{'规格/批号':<10}")
|
||||
lines.append("--------------------------------")
|
||||
|
||||
for item in items:
|
||||
# 获取名称,优先取 material_name, 其次 product_name
|
||||
name = item.get('material_name') or item.get('product_name') or "未知物品"
|
||||
if len(name) > 14: name = name[:13] + "." # 名称过长截断
|
||||
|
||||
standard = item.get('standard', '')
|
||||
batch = item.get('batch_no', '')
|
||||
uuid = item.get('uuid', '')[-6:] # 只显示UUID后6位
|
||||
|
||||
lines.append(f"{name:<14} {standard}")
|
||||
lines.append(f"批号: {batch} | 尾号: {uuid}")
|
||||
lines.append("- - - - - - - - - - - - - - - -")
|
||||
|
||||
lines.append("\n")
|
||||
lines.append("库管员签字: ______________")
|
||||
lines.append("领料人签字: ______________")
|
||||
lines.append("\n\n\n") # 走纸
|
||||
|
||||
content = "\n".join(lines)
|
||||
return self._send_to_printer(content)
|
||||
|
||||
def print_stocktake_report(self, data):
|
||||
"""
|
||||
打印盘点统计报告
|
||||
:param data: 包含 total, scanned, missing, missing_items
|
||||
"""
|
||||
total = data.get('total', 0)
|
||||
scanned = data.get('scanned', 0)
|
||||
missing = data.get('missing', 0)
|
||||
missing_items = data.get('missing_items', [])
|
||||
timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
lines = []
|
||||
lines.append("\n")
|
||||
lines.append("================================")
|
||||
lines.append(" 库存盘点统计报告 ")
|
||||
lines.append("================================")
|
||||
lines.append(f"盘点时间: {timestamp}")
|
||||
lines.append(f"应盘总数: {total}")
|
||||
lines.append(f"实盘(已扫): {scanned}")
|
||||
lines.append(f"差异(未扫): {missing}")
|
||||
lines.append("--------------------------------")
|
||||
|
||||
if missing == 0:
|
||||
lines.append("【结果】: 账实相符,库存完美!")
|
||||
else:
|
||||
lines.append("【差异明细 (未扫码物品)】:")
|
||||
for item in missing_items:
|
||||
name = item.get('material_name') or item.get('product_name') or "未知"
|
||||
batch = item.get('batch_no', '-')
|
||||
# 兼容不同模型的字段
|
||||
code = item.get('uuid', item.get('bar_code', 'N/A'))[-6:]
|
||||
|
||||
lines.append(f"[ ] {name}")
|
||||
lines.append(f" 批:{batch} 码:{code}")
|
||||
|
||||
lines.append("\n")
|
||||
lines.append("监盘人: ______________")
|
||||
lines.append("\n\n\n")
|
||||
|
||||
content = "\n".join(lines)
|
||||
return self._send_to_printer(content)
|
||||
31
inventory-web/src/api/inbound/stock.ts
Normal file
31
inventory-web/src/api/inbound/stock.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
// 获取全量库存
|
||||
// 修改前: url: '/api/v1/inbound/stock/all'
|
||||
// 修改后: url: '/v1/inbound/stock/all'
|
||||
export function getAllStock() {
|
||||
return request({
|
||||
url: '/v1/inbound/stock/all',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 打印出库选单
|
||||
// 修改后: 去掉开头的 /api
|
||||
export function printSelectionList(items: any[]) {
|
||||
return request({
|
||||
url: '/v1/inbound/stock/print/selection',
|
||||
method: 'post',
|
||||
data: { items }
|
||||
})
|
||||
}
|
||||
|
||||
// 打印盘点报告
|
||||
// 修改后: 去掉开头的 /api
|
||||
export function printStocktakeReport(data: any) {
|
||||
return request({
|
||||
url: '/v1/inbound/stock/print/stocktake',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
219
inventory-web/src/components/QrScanner/index.vue
Normal file
219
inventory-web/src/components/QrScanner/index.vue
Normal file
@ -0,0 +1,219 @@
|
||||
<template>
|
||||
<div class="qr-scanner-container">
|
||||
<div id="qr-reader" class="scanner-box"></div>
|
||||
|
||||
<div v-if="errorMsg" class="error-msg">{{ errorMsg }}</div>
|
||||
|
||||
<div class="focus-tip" v-if="!errorMsg">
|
||||
<div class="scan-line"></div>
|
||||
<div class="scan-text">将条码对准取景框</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
import { Html5Qrcode, Html5QrcodeSupportedFormats } from 'html5-qrcode'
|
||||
|
||||
const emit = defineEmits(['decode', 'error'])
|
||||
const errorMsg = ref('')
|
||||
let html5QrCode: Html5Qrcode | null = null
|
||||
const scannerElementId = "qr-reader"
|
||||
|
||||
const startScanning = async () => {
|
||||
try {
|
||||
// 1. 实例化
|
||||
html5QrCode = new Html5Qrcode(scannerElementId, {
|
||||
useBarCodeDetectorIfSupported: true,
|
||||
formatsToSupport: [
|
||||
Html5QrcodeSupportedFormats.CODE_128,
|
||||
Html5QrcodeSupportedFormats.QR_CODE
|
||||
],
|
||||
verbose: false
|
||||
})
|
||||
|
||||
// 2. 启动配置
|
||||
const config = {
|
||||
fps: 25,
|
||||
qrbox: { width: 250, height: 100 }, // 扫描区域设置
|
||||
// ★★★ 修复点1:移除 aspectRatio,让画面自适应容器长宽比 ★★★
|
||||
// aspectRatio: 1.0,
|
||||
disableFlip: false,
|
||||
videoConstraints: {
|
||||
facingMode: "environment",
|
||||
// 限制分辨率,保证速度
|
||||
width: { min: 640, ideal: 1280, max: 1920 },
|
||||
height: { min: 480, ideal: 720, max: 1080 },
|
||||
focusMode: "continuous"
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 启动
|
||||
await html5QrCode.start(
|
||||
{ facingMode: "environment" },
|
||||
config,
|
||||
(decodedText) => {
|
||||
console.log(`Scan: ${decodedText}`)
|
||||
emit('decode', decodedText)
|
||||
},
|
||||
(errorMessage) => {
|
||||
// ignore
|
||||
}
|
||||
)
|
||||
} catch (err: any) {
|
||||
let msg = '无法启动摄像头'
|
||||
const errStr = err.toString()
|
||||
if (errStr.includes('Permission')) msg = '请允许摄像头权限'
|
||||
else if (errStr.includes('Secure')) msg = '需要 HTTPS 或 localhost'
|
||||
else if (errStr.includes('NotFound')) msg = '未检测到摄像头'
|
||||
|
||||
console.error("Scanner Error:", err)
|
||||
errorMsg.value = msg
|
||||
emit('error', msg)
|
||||
}
|
||||
}
|
||||
|
||||
const stopScanning = async () => {
|
||||
if (html5QrCode) {
|
||||
try {
|
||||
if (html5QrCode.isScanning) {
|
||||
await html5QrCode.stop()
|
||||
}
|
||||
html5QrCode.clear()
|
||||
} catch (e) {
|
||||
console.error("Stop failed", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
setTimeout(() => {
|
||||
startScanning()
|
||||
}, 300)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
stopScanning()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.qr-scanner-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
background-color: #000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden; /* 关键:裁剪多余画面 */
|
||||
border-radius: 12px; /* 保持圆角 */
|
||||
}
|
||||
|
||||
.scanner-box {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* ★★★ 修复点2:强制 Video 元素填满容器 ★★★ */
|
||||
:deep(#qr-reader) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none !important;
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
:deep(#qr-reader video) {
|
||||
width: 100% !important;
|
||||
height: 100% !important;
|
||||
object-fit: cover !important; /* 关键:保持比例铺满,裁剪多余部分 */
|
||||
border-radius: 12px;
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
/* 隐藏 html5-qrcode 可能自带的遮罩层,我们用自己的 */
|
||||
:deep(#qr-reader__scan_region) {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* 自定义错误提示 */
|
||||
.error-msg {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
background: rgba(245, 108, 108, 0.85);
|
||||
padding: 15px;
|
||||
transform: translateY(-50%);
|
||||
z-index: 20;
|
||||
}
|
||||
|
||||
/* --- 视觉辅助线 --- */
|
||||
.focus-tip {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 250px;
|
||||
height: 120px;
|
||||
/* 使用半透明黑边框模拟遮罩效果,突出中间区域 */
|
||||
box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.6);
|
||||
border: 1px solid rgba(255, 255, 255, 0.6);
|
||||
border-radius: 8px;
|
||||
pointer-events: none;
|
||||
z-index: 10;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* 四个角的装饰 */
|
||||
.focus-tip::before,
|
||||
.focus-tip::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border-color: #409EFF;
|
||||
border-style: solid;
|
||||
border-width: 0;
|
||||
}
|
||||
.focus-tip::before {
|
||||
top: -1px; left: -1px;
|
||||
border-top-width: 3px;
|
||||
border-left-width: 3px;
|
||||
}
|
||||
.focus-tip::after {
|
||||
bottom: -1px; right: -1px;
|
||||
border-bottom-width: 3px;
|
||||
border-right-width: 3px;
|
||||
}
|
||||
|
||||
/* 红色扫描线动画 */
|
||||
.scan-line {
|
||||
width: 90%;
|
||||
height: 2px;
|
||||
background: #ff0000;
|
||||
box-shadow: 0 0 4px #ff0000;
|
||||
animation: scan-move 2s infinite linear;
|
||||
}
|
||||
|
||||
.scan-text {
|
||||
position: absolute;
|
||||
bottom: -30px;
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
@keyframes scan-move {
|
||||
0% { transform: translateY(-40px); opacity: 0; }
|
||||
10% { opacity: 1; }
|
||||
90% { opacity: 1; }
|
||||
100% { transform: translateY(40px); opacity: 0; }
|
||||
}
|
||||
</style>
|
||||
@ -46,7 +46,7 @@ const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/inventory',
|
||||
component: Layout,
|
||||
meta: { title: '入库管理', icon: 'Shop' }, // 修改标题以区分出库
|
||||
meta: { title: '入库管理', icon: 'Shop' },
|
||||
redirect: '/inventory/buy',
|
||||
children: [
|
||||
{
|
||||
@ -67,7 +67,7 @@ const routes: Array<RouteRecordRaw> = [
|
||||
component: () => import('@/views/stock/inbound/product.vue'),
|
||||
meta: { title: '成品' }
|
||||
},
|
||||
// ★ [新增] 入库记录整合
|
||||
// [原有] 入库记录整合
|
||||
{
|
||||
path: 'summary',
|
||||
name: 'InventorySummary',
|
||||
@ -79,17 +79,31 @@ const routes: Array<RouteRecordRaw> = [
|
||||
name: 'InventoryService',
|
||||
component: () => import('@/views/stock/inbound/service.vue'),
|
||||
meta: { title: '服务权益' }
|
||||
},
|
||||
// ★ [新增] 库存盘点页面 (查库/消除)
|
||||
{
|
||||
path: 'stocktake',
|
||||
name: 'InventoryStocktake',
|
||||
component: () => import('@/views/stock/stocktake/index.vue'),
|
||||
meta: { title: '库存盘点' }
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// 5. ★ [新增] 出库管理
|
||||
// 5. 出库管理
|
||||
{
|
||||
path: '/outbound', // 注意:这里使用了和你提供的文件路径一致的顶级路径
|
||||
path: '/outbound',
|
||||
component: Layout,
|
||||
meta: { title: '出库管理', icon: 'Van' }, // 推荐使用 Van 图标
|
||||
meta: { title: '出库管理', icon: 'Van' },
|
||||
redirect: '/outbound/index',
|
||||
children: [
|
||||
// ★ [新增] 出库选单打印页面
|
||||
{
|
||||
path: 'selection',
|
||||
name: 'OutboundSelection',
|
||||
component: () => import('@/views/outbound/Selection.vue'),
|
||||
meta: { title: '出库选单' }
|
||||
},
|
||||
{
|
||||
path: 'create',
|
||||
name: 'OutboundCreate',
|
||||
|
||||
302
inventory-web/src/views/outbound/Selection.vue
Normal file
302
inventory-web/src/views/outbound/Selection.vue
Normal 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>
|
||||
391
inventory-web/src/views/stock/stocktake/index.vue
Normal file
391
inventory-web/src/views/stock/stocktake/index.vue
Normal 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>
|
||||
Reference in New Issue
Block a user