diff --git a/inventory-backend/app/models/inbound/buy.py b/inventory-backend/app/models/inbound/buy.py index 99833c0..ee8fe0e 100644 --- a/inventory-backend/app/models/inbound/buy.py +++ b/inventory-backend/app/models/inbound/buy.py @@ -88,5 +88,5 @@ class StockBuy(db.Model): # [新增] 返回全局打印ID及其格式化字符串 'global_print_id': self.global_print_id, - 'global_print_id_str': f"{self.global_print_id:08d}" if self.global_print_id else "" + 'global_print_id_str': f"{self.global_print_id:010d}" if self.global_print_id else "" } \ No newline at end of file diff --git a/inventory-backend/app/services/inbound/buy_service.py b/inventory-backend/app/services/inbound/buy_service.py index ce85248..4051013 100644 --- a/inventory-backend/app/services/inbound/buy_service.py +++ b/inventory-backend/app/services/inbound/buy_service.py @@ -79,7 +79,7 @@ class BuyInboundService: # ------------------------------------------------------------------ # 2. 自动生成 SKU (格式: 00000001) # ------------------------------------------------------------------ - generated_sku = f"{next_global_id:08d}" + generated_sku = str(next_global_id).zfill(10) # ------------------------------------------------------------------ # 3. 条码逻辑处理 (核心修改) diff --git a/inventory-backend/app/services/print/label_service.py b/inventory-backend/app/services/print/label_service.py index 1ed8c27..b5c3d3a 100644 --- a/inventory-backend/app/services/print/label_service.py +++ b/inventory-backend/app/services/print/label_service.py @@ -26,12 +26,13 @@ class LabelPrintService: LABEL_HEIGHT = int(LABEL_HEIGHT_MM * DOTS_PER_MM) # 顶部留白: 10mm (120px) - 内容从这里开始 - TOP_MARGIN_MM = 5 + TOP_MARGIN_MM = 2 TOP_MARGIN_PX = int(TOP_MARGIN_MM * DOTS_PER_MM) @staticmethod def _get_font(size): """获取字体""" + # 尝试加载中文字体,否则乱码 font_names = ["simhei.ttf", "msyh.ttf", "SimHei.ttf", "arial.ttf"] base_dirs = [os.getcwd(), os.path.dirname(__file__)] @@ -48,6 +49,10 @@ class LabelPrintService: 生成真实的条形码图片 """ try: + # 确保内容字符串有效 + if not content: + content = "0000000000" + # 使用 Code128 编码(通用性最强) code128 = barcode.get('code128', content, writer=ImageWriter()) @@ -85,31 +90,31 @@ class LabelPrintService: sku_code = data.get('sku') if not sku_code: # 兜底逻辑:如果没有 SKU,尝试用 serial_number 或 global_id - sku_code = data.get('serial_number') or str(data.get('global_print_id', '00000000')).zfill(8) + sku_code = data.get('serial_number') or str(data.get('global_print_id', '0000000000')).zfill(10) # ==================== 绘制布局 ==================== # X 轴偏移 (5mm) - GLOBAL_OFFSET_X = int(5 * LabelPrintService.DOTS_PER_MM) + GLOBAL_OFFSET_X = int(2 * LabelPrintService.DOTS_PER_MM) # Y 轴起始: 10mm 处 CURRENT_Y = LabelPrintService.TOP_MARGIN_PX - # --- A. 绘制真实条形码 --- - bc_w = int(28 * LabelPrintService.DOTS_PER_MM) # 条码宽约 28mm - bc_h = int(6 * LabelPrintService.DOTS_PER_MM) # 条码高约 6mm + # --- A. 绘制真实条形码 (内容为 SKU) --- + bc_w = int(35 * LabelPrintService.DOTS_PER_MM) # 条码宽约 28mm + bc_h = int(10 * LabelPrintService.DOTS_PER_MM) # 条码高约 6mm # 生成并粘贴条码 bc_img = LabelPrintService._generate_barcode_image(sku_code, bc_w, bc_h) # 粘贴位置: (X, Y) - img.paste(bc_img, (GLOBAL_OFFSET_X - 5, CURRENT_Y)) + img.paste(bc_img, (GLOBAL_OFFSET_X - 10, CURRENT_Y)) # 更新 Y 坐标 (条码高度 + 间距) CURRENT_Y += bc_h + 5 # --- B. 绘制文字 (统一加粗) --- - # 准备数据 + # 准备数据 (名称、规格等) name = str(data.get('material_name', '') or '-') if len(name) > 8: name = name[:7] + ".." @@ -123,15 +128,43 @@ class LabelPrintService: attr = f"{cat}/{typ}" if len(attr) > 11: attr = attr[:10] + ".." - # 底部显示的文字:SKU 编号 - sku_str = f"NO.{sku_code}" + # ----------------------------------------------------------- + # [修改点] 底部显示的文字:不再显示 NO.SKU,而是显示 SN 或 BN + # ----------------------------------------------------------- + bottom_text = "" + + # 1. 优先检查前端是否传了明确的 print_no (打印值) 和 print_label (序/批) + if data.get('print_no'): + val = str(data.get('print_no')) + label_type = data.get('print_label', '') + + if label_type == '序': + bottom_text = f"SN: {val}" + elif label_type == '批': + bottom_text = f"BN: {val}" + else: + bottom_text = f"NO: {val}" + + # 2. 如果没有前端打印参数,检查数据中的序列号 + elif data.get('serial_number'): + bottom_text = f"SN: {data.get('serial_number')}" + + # 3. 检查数据中的批号 + elif data.get('batch_number'): + bottom_text = f"BN: {data.get('batch_number')}" + + # 4. 兜底 (如果什么都没有,才显示 SKU) + else: + bottom_text = f"NO: {sku_code}" + + # ----------------------------------------------------------- lines = [ f"名: {name}", f"规: {spec}", f"库: {loc}", f"属: {attr}", - f"{sku_str}" + f"{bottom_text}" # 这里放置计算好的 SN/BN 文字 ] line_height = 36 # 行高 (字号30 + 6间距) diff --git a/inventory-web/src/views/stock/inbound/buy.vue b/inventory-web/src/views/stock/inbound/buy.vue index 58e85f6..e63e014 100644 --- a/inventory-web/src/views/stock/inbound/buy.vue +++ b/inventory-web/src/views/stock/inbound/buy.vue @@ -11,7 +11,7 @@ @keyup.enter="fetchData" > - + @@ -27,11 +27,15 @@ 基础信息 - {{ c.label }} + + {{ c.label }} + 库存与商务 - {{ c.label }} + + {{ c.label }} + @@ -80,8 +84,12 @@ - - 查看 + + + + + 查看 @@ -94,7 +102,10 @@ - 打印 + + + + 打印 编辑 @@ -132,7 +143,9 @@ - + + + 1. 基础信息 (请先搜索锁定物料) @@ -172,18 +185,38 @@ - 未输入时展示最新物料;输入关键词进行精确搜索。 + 未输入时展示最新物料;输入关键词进行精确搜索。 - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -191,7 +224,9 @@ - + + + 2. 入库详情 @@ -201,28 +236,38 @@ - + + + + + + + + + + + - - - + 按批号入库 (Batch) 按序列号入库 (SN) - 历史锁定 + 历史锁定 @@ -257,27 +302,28 @@ - + - + - + - - - + + + @@ -292,7 +338,11 @@ - + + + + + 商务与采购信息 @@ -314,15 +364,22 @@ - + + + + + - + - + @@ -370,8 +427,16 @@ - - + + + + + + + + + + @@ -398,7 +463,7 @@ > - + 正在生成预览... @@ -411,7 +476,10 @@ @@ -421,9 +489,9 @@