a355a3a2a2
- 版式参照单据样板:公司抬头 + 两行三列表头 + 统一明细列 (商品编号/名称/系列/规格/批次号/生产日期/数量/单价/金额/备注) - 单据总计独立成行(仅数量+金额,右对齐高亮) - 出库单保留温馨提示,入库单去掉 - 签字行:制单人=当前登录用户(OrderPrintMeta),采购员/销售员=经办人; 公司名取门店(shopInfoProvider) - 出库单单价=售价(sale_price),金额=售价×数量;历史单 sale_price=0 时回退 unit_price/total_price。入库单单价=进价(unit_price) - 桌面 PDF 与 Web HTML 两端同构 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
81 lines
2.7 KiB
Dart
81 lines
2.7 KiB
Dart
import 'dart:typed_data';
|
|
import 'package:flutter/material.dart';
|
|
import '../../models/stock_in.dart';
|
|
import '../../models/stock_out.dart';
|
|
import '../errors/error_reporter.dart';
|
|
import 'label_data.dart';
|
|
export 'label_data.dart';
|
|
import 'order_print_meta.dart';
|
|
export 'order_print_meta.dart';
|
|
import 'print_util_stub.dart'
|
|
if (dart.library.js_interop) 'print_util_web.dart';
|
|
|
|
Future<void> printProductLabel({
|
|
required Uint8List qrBytes,
|
|
required String name,
|
|
required String code,
|
|
String? spec,
|
|
String? series,
|
|
String? batchNo,
|
|
String? productionDate,
|
|
String? remark,
|
|
String shopName = '',
|
|
String shopAddress = '',
|
|
String shopPhone = '',
|
|
String? printerName,
|
|
}) =>
|
|
printProductLabelImpl(
|
|
qrBytes: qrBytes,
|
|
name: name,
|
|
code: code,
|
|
spec: spec,
|
|
series: series,
|
|
batchNo: batchNo,
|
|
productionDate: productionDate,
|
|
remark: remark,
|
|
shopName: shopName,
|
|
shopAddress: shopAddress,
|
|
shopPhone: shopPhone,
|
|
printerName: printerName,
|
|
);
|
|
|
|
/// 渲染标签预览图(PNG 字节);Web 平台返回 null。
|
|
Future<Uint8List?> renderLabelPreview(LabelData label) =>
|
|
renderLabelPreviewImpl(label);
|
|
|
|
/// 枚举当前系统所有可用打印机名;Web 平台返回空列表。
|
|
Future<List<String>> listLabelPrinters() => listLabelPrintersImpl();
|
|
|
|
/// 自动检测默认热敏打印机(名字含 deli/dl-888);找不到或 Web 返回 null。
|
|
Future<String?> detectDefaultPrinter() => detectDefaultPrinterImpl();
|
|
|
|
Future<void> printStockInOrder(StockInOrder order, OrderPrintMeta meta) =>
|
|
printStockInOrderImpl(order, meta);
|
|
|
|
Future<void> printStockOutOrder(StockOutOrder order, OrderPrintMeta meta) =>
|
|
printStockOutOrderImpl(order, meta);
|
|
|
|
/// 生成入库单 PDF 字节(桌面端真实排版,供打印预览光栅化用);Web 端不支持。
|
|
Future<Uint8List> buildStockInOrderPdf(StockInOrder order, OrderPrintMeta meta) =>
|
|
buildStockInOrderPdfImpl(order, meta);
|
|
|
|
/// 生成出库单 PDF 字节(桌面端真实排版,供打印预览光栅化用);Web 端不支持。
|
|
Future<Uint8List> buildStockOutOrderPdf(
|
|
StockOutOrder order, OrderPrintMeta meta) =>
|
|
buildStockOutOrderPdfImpl(order, meta);
|
|
|
|
/// 统一打印入口:catch 任意异常,上报并弹 SnackBar 给用户。
|
|
/// 用法:await safePrint(context, () => printStockInOrder(order));
|
|
Future<void> safePrint(BuildContext context, Future<void> Function() fn) async {
|
|
try {
|
|
await fn();
|
|
} catch (e, st) {
|
|
reportError(e, st);
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(content: Text('打印失败:$e'), backgroundColor: Colors.red),
|
|
);
|
|
}
|
|
}
|
|
}
|