Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5187702fc5 | |||
| 3d83f94f24 | |||
| 5861b9210c | |||
| a678c3806e | |||
| 5ff41cc505 |
@@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [1.0.82] - 2026-06-26
|
||||||
|
|
||||||
|
### 新功能
|
||||||
|
- 出库单 / 入库单打印新增「打印预览」:点击打印先弹出整页预览(所见即所得),确认无误后再调用系统打印,解决部分 Windows 电脑打印对话框无法预览的问题。
|
||||||
|
|
||||||
|
## [1.0.81] - 2026-06-24
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
- 出库 / 入库单详情全屏弹窗只覆盖内容区,不再遮挡左侧菜单栏、顶栏与状态栏。
|
||||||
|
- 出库 / 入库单详情标题栏改为浅色配色(浅蓝底 + 深色文字),观感更清爽。
|
||||||
|
|
||||||
|
## [1.0.80] - 2026-06-24
|
||||||
|
|
||||||
|
### 新功能
|
||||||
|
- 出库单详情新增「售价」与「利润」列,利润 = 售价 − 成本,一眼看清每笔出库的盈亏。
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
- 出库 / 入库单详情改为全屏展示,内容更大更清晰,左上角返回箭头关闭。
|
||||||
|
- 出库单详情自动带出商品的生产日期与批次号(明细未单独填写时回退商品资料),去掉冗余的「数量」列。
|
||||||
|
|
||||||
|
## [1.0.79] - 2026-06-24
|
||||||
|
|
||||||
|
### 改进
|
||||||
|
- 入库单 / 出库单搜索框升级:搜索后关键词以标签形式显示在搜索框内,带一键清除(✕)按钮,输入框自动清空便于继续输入;当前仅支持单个搜索词。
|
||||||
|
|
||||||
## [1.0.78] - 2026-06-24
|
## [1.0.78] - 2026-06-24
|
||||||
|
|
||||||
### 改进
|
### 改进
|
||||||
|
|||||||
@@ -5,6 +5,11 @@
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [1.0.81] - 2026-06-24
|
||||||
|
|
||||||
|
### 修复
|
||||||
|
- 入库单 / 出库单按商品名搜索:历史导入的单据现在也能按商品名搜到(此前明细统一挂占位商品,搜索被占位名顶替,只能搜到新建单据)。
|
||||||
|
|
||||||
## [1.0.80] - 2026-06-24
|
## [1.0.80] - 2026-06-24
|
||||||
|
|
||||||
### 改进
|
### 改进
|
||||||
|
|||||||
@@ -53,16 +53,18 @@ func (h *StockInHandler) List(c *gin.Context) {
|
|||||||
if kw := strings.TrimSpace(c.Query("keyword")); kw != "" {
|
if kw := strings.TrimSpace(c.Query("keyword")); kw != "" {
|
||||||
like := "%" + kw + "%"
|
like := "%" + kw + "%"
|
||||||
// keyword 同时命中:单号 / 往来单位 / 酒名(含全拼+首字母,反查含该酒明细的单据)。
|
// keyword 同时命中:单号 / 往来单位 / 酒名(含全拼+首字母,反查含该酒明细的单据)。
|
||||||
// 酒名优先取 product 主数据、回退快照列;拼音只在 products 上(快照无拼音列)。
|
// 酒名「product 主数据名 OR 明细快照名」任一命中——不能用 COALESCE 二选一:历史导入单的
|
||||||
|
// 明细 product_id 统一指向占位商品「历史导入占位」(p.name 非空),COALESCE 会被占位名劫持,
|
||||||
|
// 永远取不到真实快照 product_name,导致导入单按真实酒名搜不到。拼音只在 products 上(快照无拼音列)。
|
||||||
query = query.Where(
|
query = query.Where(
|
||||||
"order_no LIKE ?"+
|
"order_no LIKE ?"+
|
||||||
" OR partner_id IN (SELECT id FROM partners WHERE shop_id = ? AND name LIKE ?)"+
|
" OR partner_id IN (SELECT id FROM partners WHERE shop_id = ? AND name LIKE ?)"+
|
||||||
" OR id IN (SELECT it.order_id FROM stock_in_items it"+
|
" OR id IN (SELECT it.order_id FROM stock_in_items it"+
|
||||||
" LEFT JOIN products p ON p.id = it.product_id AND p.shop_id = it.shop_id"+
|
" LEFT JOIN products p ON p.id = it.product_id AND p.shop_id = it.shop_id"+
|
||||||
" WHERE it.shop_id = ? AND it.deleted_at IS NULL"+
|
" WHERE it.shop_id = ? AND it.deleted_at IS NULL"+
|
||||||
" AND (COALESCE(NULLIF(p.name,''), it.product_name) LIKE ?"+
|
" AND (p.name LIKE ? OR it.product_name LIKE ?"+
|
||||||
" OR p.name_pinyin LIKE ? OR p.name_initials LIKE ?))",
|
" OR p.name_pinyin LIKE ? OR p.name_initials LIKE ?))",
|
||||||
like, shopID, like, shopID, like, like, like,
|
like, shopID, like, shopID, like, like, like, like,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ func TestStockInHandler_TotalAmount(t *testing.T) {
|
|||||||
"warehouse_id": warehouse.ID,
|
"warehouse_id": warehouse.ID,
|
||||||
"order_date": time.Now().Format(time.RFC3339),
|
"order_date": time.Now().Format(time.RFC3339),
|
||||||
"items": []map[string]interface{}{
|
"items": []map[string]interface{}{
|
||||||
{"product_id": product1.ID, "quantity": 10.0, "unit_price": 5.0}, // 50
|
{"product_id": product1.ID, "quantity": 10.0, "unit_price": 5.0}, // 50
|
||||||
{"product_id": product2.ID, "quantity": 3.0, "unit_price": 20.0}, // 60
|
{"product_id": product2.ID, "quantity": 3.0, "unit_price": 20.0}, // 60
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@@ -487,6 +487,49 @@ func TestStockInHandler_List_FilterByProductName(t *testing.T) {
|
|||||||
assert.Equal(t, float64(2), parseResponse(w)["total"].(float64))
|
assert.Equal(t, float64(2), parseResponse(w)["total"].(float64))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 回归:历史导入单的明细 product_id 统一指向占位商品「历史导入占位」(p.name 非空),
|
||||||
|
// 真实酒名只在快照列 product_name。修复前搜索用 COALESCE(NULLIF(p.name,”), product_name)
|
||||||
|
// 被占位名劫持,导入单按真实酒名搜不到;修复后「p.name OR product_name」任一命中。
|
||||||
|
func TestStockInHandler_List_FilterByImportedSnapshotName(t *testing.T) {
|
||||||
|
db := testutil.SetupTestDB()
|
||||||
|
shop := testutil.CreateTestShop(db, "SI012B")
|
||||||
|
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||||
|
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Warehouse")
|
||||||
|
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||||
|
r := setupProtectedRouter(db)
|
||||||
|
|
||||||
|
// 占位商品:名「历史导入占位」,编码 HIST-PLACEHOLDER(模拟 import-history)
|
||||||
|
placeholder := &model.Product{
|
||||||
|
TenantBase: model.TenantBase{ShopID: shop.ID},
|
||||||
|
Name: "历史导入占位",
|
||||||
|
Code: "HIST-PLACEHOLDER",
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Create(placeholder).Error)
|
||||||
|
|
||||||
|
// 导入单:明细 product_id 指向占位商品,真实酒名「飞天茅台」仅在快照 product_name
|
||||||
|
order := &model.StockInOrder{
|
||||||
|
TenantBase: model.TenantBase{ShopID: shop.ID},
|
||||||
|
OrderNo: "RK-IMPORT-001",
|
||||||
|
WarehouseID: warehouse.ID,
|
||||||
|
OperatorID: user.ID,
|
||||||
|
Status: "approved",
|
||||||
|
OrderDate: model.Date{Time: time.Now()},
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Create(order).Error)
|
||||||
|
require.NoError(t, db.Create(&model.StockInItem{
|
||||||
|
OrderID: order.ID,
|
||||||
|
ShopID: shop.ID,
|
||||||
|
ProductID: placeholder.ID,
|
||||||
|
ProductCode: "ZXZ000010",
|
||||||
|
ProductName: "飞天茅台",
|
||||||
|
Quantity: 5.0,
|
||||||
|
}).Error)
|
||||||
|
|
||||||
|
// 按真实酒名搜 → 命中导入单(修复前为 0)
|
||||||
|
w := makeRequest(r, "GET", "/api/v1/stock-in/orders?keyword=茅台", token, nil)
|
||||||
|
assert.Equal(t, float64(1), parseResponse(w)["total"].(float64))
|
||||||
|
}
|
||||||
|
|
||||||
func TestStockInHandler_List_FilterByProductPinyin(t *testing.T) {
|
func TestStockInHandler_List_FilterByProductPinyin(t *testing.T) {
|
||||||
db := testutil.SetupTestDB()
|
db := testutil.SetupTestDB()
|
||||||
shop := testutil.CreateTestShop(db, "SI013")
|
shop := testutil.CreateTestShop(db, "SI013")
|
||||||
|
|||||||
@@ -46,16 +46,18 @@ func (h *StockOutHandler) List(c *gin.Context) {
|
|||||||
if kw := strings.TrimSpace(c.Query("keyword")); kw != "" {
|
if kw := strings.TrimSpace(c.Query("keyword")); kw != "" {
|
||||||
like := "%" + kw + "%"
|
like := "%" + kw + "%"
|
||||||
// keyword 同时命中:单号 / 往来单位 / 酒名(含全拼+首字母,反查含该酒明细的单据)。
|
// keyword 同时命中:单号 / 往来单位 / 酒名(含全拼+首字母,反查含该酒明细的单据)。
|
||||||
// 酒名优先取 product 主数据、回退快照列;拼音只在 products 上(快照无拼音列)。
|
// 酒名「product 主数据名 OR 明细快照名」任一命中——不能用 COALESCE 二选一:历史导入单的
|
||||||
|
// 明细 product_id 统一指向占位商品「历史导入占位」(p.name 非空),COALESCE 会被占位名劫持,
|
||||||
|
// 永远取不到真实快照 product_name,导致导入单按真实酒名搜不到。拼音只在 products 上(快照无拼音列)。
|
||||||
query = query.Where(
|
query = query.Where(
|
||||||
"order_no LIKE ?"+
|
"order_no LIKE ?"+
|
||||||
" OR partner_id IN (SELECT id FROM partners WHERE shop_id = ? AND name LIKE ?)"+
|
" OR partner_id IN (SELECT id FROM partners WHERE shop_id = ? AND name LIKE ?)"+
|
||||||
" OR id IN (SELECT it.order_id FROM stock_out_items it"+
|
" OR id IN (SELECT it.order_id FROM stock_out_items it"+
|
||||||
" LEFT JOIN products p ON p.id = it.product_id AND p.shop_id = it.shop_id"+
|
" LEFT JOIN products p ON p.id = it.product_id AND p.shop_id = it.shop_id"+
|
||||||
" WHERE it.shop_id = ? AND it.deleted_at IS NULL"+
|
" WHERE it.shop_id = ? AND it.deleted_at IS NULL"+
|
||||||
" AND (COALESCE(NULLIF(p.name,''), it.product_name) LIKE ?"+
|
" AND (p.name LIKE ? OR it.product_name LIKE ?"+
|
||||||
" OR p.name_pinyin LIKE ? OR p.name_initials LIKE ?))",
|
" OR p.name_pinyin LIKE ? OR p.name_initials LIKE ?))",
|
||||||
like, shopID, like, shopID, like, like, like,
|
like, shopID, like, shopID, like, like, like, like,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// 按商品编码反查单据:精确匹配,走 idx_so_items_shop_code(shop_id, product_code) 索引
|
// 按商品编码反查单据:精确匹配,走 idx_so_items_shop_code(shop_id, product_code) 索引
|
||||||
|
|||||||
@@ -248,6 +248,46 @@ func TestStockOutHandler_List_FilterByProductName(t *testing.T) {
|
|||||||
assert.Equal(t, float64(2), parseResponse(w)["total"].(float64))
|
assert.Equal(t, float64(2), parseResponse(w)["total"].(float64))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 回归:历史导入出库单的明细 product_id 指向占位商品「历史导入占位」,真实酒名只在快照列。
|
||||||
|
// 修复前 COALESCE 被占位名劫持搜不到,修复后「p.name OR product_name」任一命中。
|
||||||
|
func TestStockOutHandler_List_FilterByImportedSnapshotName(t *testing.T) {
|
||||||
|
db := testutil.SetupTestDB()
|
||||||
|
shop := testutil.CreateTestShop(db, "SO012B")
|
||||||
|
user := testutil.CreateTestUser(db, shop.ID, "admin", "pass", "admin")
|
||||||
|
warehouse := testutil.CreateTestWarehouse(db, shop.ID, "Warehouse")
|
||||||
|
token := getAuthToken(user.ID, shop.ID, "admin")
|
||||||
|
r := setupProtectedRouter(db)
|
||||||
|
|
||||||
|
placeholder := &model.Product{
|
||||||
|
TenantBase: model.TenantBase{ShopID: shop.ID},
|
||||||
|
Name: "历史导入占位",
|
||||||
|
Code: "HIST-PLACEHOLDER",
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Create(placeholder).Error)
|
||||||
|
|
||||||
|
order := &model.StockOutOrder{
|
||||||
|
TenantBase: model.TenantBase{ShopID: shop.ID},
|
||||||
|
OrderNo: "CK-IMPORT-001",
|
||||||
|
WarehouseID: warehouse.ID,
|
||||||
|
OperatorID: user.ID,
|
||||||
|
Status: "approved",
|
||||||
|
OrderDate: model.Date{Time: time.Now()},
|
||||||
|
}
|
||||||
|
require.NoError(t, db.Create(order).Error)
|
||||||
|
require.NoError(t, db.Create(&model.StockOutItem{
|
||||||
|
OrderID: order.ID,
|
||||||
|
ShopID: shop.ID,
|
||||||
|
ProductID: placeholder.ID,
|
||||||
|
ProductCode: "ZXZ000010",
|
||||||
|
ProductName: "飞天茅台",
|
||||||
|
Quantity: 5.0,
|
||||||
|
}).Error)
|
||||||
|
|
||||||
|
// 按真实酒名搜 → 命中导入单(修复前为 0)
|
||||||
|
w := makeRequest(r, "GET", "/api/v1/stock-out/orders?keyword=茅台", token, nil)
|
||||||
|
assert.Equal(t, float64(1), parseResponse(w)["total"].(float64))
|
||||||
|
}
|
||||||
|
|
||||||
func TestStockOutHandler_Reject(t *testing.T) {
|
func TestStockOutHandler_Reject(t *testing.T) {
|
||||||
db := testutil.SetupTestDB()
|
db := testutil.SetupTestDB()
|
||||||
shop := testutil.CreateTestShop(db, "SO004")
|
shop := testutil.CreateTestShop(db, "SO004")
|
||||||
|
|||||||
@@ -53,6 +53,14 @@ Future<void> printStockInOrder(StockInOrder order) =>
|
|||||||
Future<void> printStockOutOrder(StockOutOrder order) =>
|
Future<void> printStockOutOrder(StockOutOrder order) =>
|
||||||
printStockOutOrderImpl(order);
|
printStockOutOrderImpl(order);
|
||||||
|
|
||||||
|
/// 生成入库单 PDF 字节(桌面端真实排版,供打印预览光栅化用);Web 端不支持。
|
||||||
|
Future<Uint8List> buildStockInOrderPdf(StockInOrder order) =>
|
||||||
|
buildStockInOrderPdfImpl(order);
|
||||||
|
|
||||||
|
/// 生成出库单 PDF 字节(桌面端真实排版,供打印预览光栅化用);Web 端不支持。
|
||||||
|
Future<Uint8List> buildStockOutOrderPdf(StockOutOrder order) =>
|
||||||
|
buildStockOutOrderPdfImpl(order);
|
||||||
|
|
||||||
/// 统一打印入口:catch 任意异常,上报并弹 SnackBar 给用户。
|
/// 统一打印入口:catch 任意异常,上报并弹 SnackBar 给用户。
|
||||||
/// 用法:await safePrint(context, () => printStockInOrder(order));
|
/// 用法:await safePrint(context, () => printStockInOrder(order));
|
||||||
Future<void> safePrint(BuildContext context, Future<void> Function() fn) async {
|
Future<void> safePrint(BuildContext context, Future<void> Function() fn) async {
|
||||||
|
|||||||
@@ -799,8 +799,8 @@ pw.Widget _sig(pw.Font font, pw.Font bold, String label) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> printStockInOrderImpl(StockInOrder order) async {
|
/// 生成入库单 A4 PDF 字节(与实际打印同一套排版,供预览光栅化 + 打印共用)。
|
||||||
try {
|
Future<Uint8List> buildStockInOrderPdfImpl(StockInOrder order) async {
|
||||||
final font = await _loadFont();
|
final font = await _loadFont();
|
||||||
final bold = await _loadBoldFont();
|
final bold = await _loadBoldFont();
|
||||||
|
|
||||||
@@ -848,7 +848,12 @@ Future<void> printStockInOrderImpl(StockInOrder order) async {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
final bytes = await doc.save();
|
return doc.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> printStockInOrderImpl(StockInOrder order) async {
|
||||||
|
try {
|
||||||
|
final bytes = await buildStockInOrderPdfImpl(order);
|
||||||
if (!kIsWeb && Platform.isMacOS) {
|
if (!kIsWeb && Platform.isMacOS) {
|
||||||
await Future<void>.delayed(Duration.zero);
|
await Future<void>.delayed(Duration.zero);
|
||||||
}
|
}
|
||||||
@@ -862,7 +867,8 @@ Future<void> printStockInOrderImpl(StockInOrder order) async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> printStockOutOrderImpl(StockOutOrder order) async {
|
/// 生成出库单 A4 PDF 字节(与实际打印同一套排版,供预览光栅化 + 打印共用)。
|
||||||
|
Future<Uint8List> buildStockOutOrderPdfImpl(StockOutOrder order) async {
|
||||||
final font = await _loadFont();
|
final font = await _loadFont();
|
||||||
final bold = await _loadBoldFont();
|
final bold = await _loadBoldFont();
|
||||||
|
|
||||||
@@ -909,8 +915,12 @@ Future<void> printStockOutOrderImpl(StockOutOrder order) async {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
|
return doc.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> printStockOutOrderImpl(StockOutOrder order) async {
|
||||||
try {
|
try {
|
||||||
final bytes = await doc.save();
|
final bytes = await buildStockOutOrderPdfImpl(order);
|
||||||
if (!kIsWeb && Platform.isMacOS) {
|
if (!kIsWeb && Platform.isMacOS) {
|
||||||
await Future<void>.delayed(Duration.zero);
|
await Future<void>.delayed(Duration.zero);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,6 +170,14 @@ body { width: 38mm; height: 20mm; overflow: hidden; background: #fff; }
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 单据 PDF 字节(Web 走 HTML 打印路径,不生成 PDF;预览弹窗仅桌面端调用)──────
|
||||||
|
|
||||||
|
Future<Uint8List> buildStockInOrderPdfImpl(StockInOrder order) async =>
|
||||||
|
throw UnsupportedError('Web 端入库单走 HTML 打印,不生成 PDF');
|
||||||
|
|
||||||
|
Future<Uint8List> buildStockOutOrderPdfImpl(StockOutOrder order) async =>
|
||||||
|
throw UnsupportedError('Web 端出库单走 HTML 打印,不生成 PDF');
|
||||||
|
|
||||||
// ── 入库单 ──────────────────────────────────────────────────────────────────
|
// ── 入库单 ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
Future<void> printStockInOrderImpl(StockInOrder order) async {
|
Future<void> printStockInOrderImpl(StockInOrder order) async {
|
||||||
|
|||||||
@@ -61,8 +61,9 @@ class StockOutItem {
|
|||||||
productSeries: lineOrProduct('series', 'series'),
|
productSeries: lineOrProduct('series', 'series'),
|
||||||
productSpec: lineOrProduct('spec', 'spec'),
|
productSpec: lineOrProduct('spec', 'spec'),
|
||||||
productUnit: (json['product'] as Map<String, dynamic>?)?['unit'] as String?,
|
productUnit: (json['product'] as Map<String, dynamic>?)?['unit'] as String?,
|
||||||
batchNo: json['batch_no'] as String?,
|
// 批次号/生产日期:优先明细行快照,回退 product 关联(App 新建单据快照列常为空)
|
||||||
productionDate: json['production_date'] as String?,
|
batchNo: lineOrProduct('batch_no', 'batch_no'),
|
||||||
|
productionDate: lineOrProduct('production_date', 'production_date'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ class StockInListNotifier extends AsyncNotifier<PageResult<StockInOrder>> {
|
|||||||
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
|
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
|
||||||
String get currentStatus => _status;
|
String get currentStatus => _status;
|
||||||
|
|
||||||
|
String get currentKeyword => _keyword;
|
||||||
|
|
||||||
void setStatus(String status) {
|
void setStatus(String status) {
|
||||||
_status = status;
|
_status = status;
|
||||||
_page = 1;
|
_page = 1;
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ class StockOutListNotifier extends AsyncNotifier<PageResult<StockOutOrder>> {
|
|||||||
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
|
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
|
||||||
String get currentStatus => _status;
|
String get currentStatus => _status;
|
||||||
|
|
||||||
|
String get currentKeyword => _keyword;
|
||||||
|
|
||||||
void setStatus(String status) {
|
void setStatus(String status) {
|
||||||
_status = status;
|
_status = status;
|
||||||
_page = 1;
|
_page = 1;
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import '../../core/responsive/responsive.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/auth/auth_state.dart';
|
import '../../core/auth/auth_state.dart';
|
||||||
import '../../core/utils/print_util.dart';
|
|
||||||
import '../../core/utils/date_util.dart';
|
import '../../core/utils/date_util.dart';
|
||||||
|
import '../../widgets/order_print_preview_dialog.dart';
|
||||||
import '../../models/stock_in.dart';
|
import '../../models/stock_in.dart';
|
||||||
import '../../core/config/app_constants.dart';
|
import '../../core/config/app_constants.dart';
|
||||||
import '../../providers/partner_provider.dart';
|
import '../../providers/partner_provider.dart';
|
||||||
@@ -227,7 +227,7 @@ class _StockInFormScreenState extends ConsumerState<StockInFormScreen> {
|
|||||||
|
|
||||||
Future<void> _printOrder() async {
|
Future<void> _printOrder() async {
|
||||||
if (_loadedOrder == null) return;
|
if (_loadedOrder == null) return;
|
||||||
await safePrint(context, () => printStockInOrder(_loadedOrder!));
|
await showStockInOrderPrint(context, _loadedOrder!);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _submit(bool asDraft) async {
|
Future<void> _submit(bool asDraft) async {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import '../../core/utils/dialog_util.dart';
|
import '../../core/utils/dialog_util.dart';
|
||||||
import '../../core/errors/error_reporter.dart';
|
import '../../core/errors/error_reporter.dart';
|
||||||
import '../../core/exceptions.dart';
|
import '../../core/exceptions.dart';
|
||||||
import '../../core/utils/print_util.dart' show safePrint, printStockInOrder, LabelData;
|
import '../../core/utils/print_util.dart' show LabelData;
|
||||||
import '../../widgets/label_preview_dialog.dart';
|
import '../../widgets/label_preview_dialog.dart';
|
||||||
|
import '../../widgets/order_print_preview_dialog.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -17,6 +18,7 @@ import '../../widgets/multi_select_dropdown.dart' show ColDef, ColumnToggleButto
|
|||||||
import '../../core/storage/column_prefs.dart';
|
import '../../core/storage/column_prefs.dart';
|
||||||
import '../../widgets/page_scaffold.dart';
|
import '../../widgets/page_scaffold.dart';
|
||||||
import '../../widgets/status_badge.dart';
|
import '../../widgets/status_badge.dart';
|
||||||
|
import '../../widgets/search_chip.dart';
|
||||||
import '../../core/utils/export_util.dart';
|
import '../../core/utils/export_util.dart';
|
||||||
import '../../providers/inventory_provider.dart';
|
import '../../providers/inventory_provider.dart';
|
||||||
import '../../providers/tab_state_provider.dart';
|
import '../../providers/tab_state_provider.dart';
|
||||||
@@ -44,6 +46,7 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
|||||||
Set<String> _filterSupplier = {};
|
Set<String> _filterSupplier = {};
|
||||||
Set<String>? _hiddenCols; // null = 尚未载入本地存档(回退到 minWidth 首次默认)
|
Set<String>? _hiddenCols; // null = 尚未载入本地存档(回退到 minWidth 首次默认)
|
||||||
final _searchCtrl = TextEditingController();
|
final _searchCtrl = TextEditingController();
|
||||||
|
String _appliedKw = ''; // 已生效的搜索词(框内 chip 标签展示)
|
||||||
|
|
||||||
static const _screenId = 'stock_in_list';
|
static const _screenId = 'stock_in_list';
|
||||||
|
|
||||||
@@ -72,6 +75,10 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
|||||||
final want = tab == 1 ? 'pending,draft' : _statusFilter;
|
final want = tab == 1 ? 'pending,draft' : _statusFilter;
|
||||||
final notifier = ref.read(stockInListProvider.notifier);
|
final notifier = ref.read(stockInListProvider.notifier);
|
||||||
if (notifier.currentStatus != want) notifier.setStatus(want);
|
if (notifier.currentStatus != want) notifier.setStatus(want);
|
||||||
|
// 同步已生效的搜索词到框内 chip(provider 持久化,切走再回来不丢)
|
||||||
|
if (notifier.currentKeyword != _appliedKw) {
|
||||||
|
setState(() => _appliedKw = notifier.currentKeyword);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +88,19 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _triggerSearch() =>
|
void _triggerSearch() {
|
||||||
ref.read(stockInListProvider.notifier).setKeyword(_searchCtrl.text.trim());
|
final kw = _searchCtrl.text.trim();
|
||||||
|
ref.read(stockInListProvider.notifier).setKeyword(kw);
|
||||||
|
// 仅支持单个搜索词:生效后输入框清空,搜索词转为框内 chip 标签
|
||||||
|
setState(() => _appliedKw = kw);
|
||||||
|
if (kw.isNotEmpty) _searchCtrl.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _clearSearch() {
|
||||||
|
_searchCtrl.clear();
|
||||||
|
setState(() => _appliedKw = '');
|
||||||
|
ref.read(stockInListProvider.notifier).setKeyword('');
|
||||||
|
}
|
||||||
|
|
||||||
String? get _startDate => _dateRange != null
|
String? get _startDate => _dateRange != null
|
||||||
? '${_dateRange!.start.year}-${_dateRange!.start.month.toString().padLeft(2, '0')}-${_dateRange!.start.day.toString().padLeft(2, '0')}'
|
? '${_dateRange!.start.year}-${_dateRange!.start.month.toString().padLeft(2, '0')}-${_dateRange!.start.day.toString().padLeft(2, '0')}'
|
||||||
@@ -363,12 +381,29 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
|||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
final hasKw = _appliedKw.isNotEmpty;
|
||||||
final searchField = TextField(
|
final searchField = TextField(
|
||||||
controller: _searchCtrl,
|
controller: _searchCtrl,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: '单号/往来单位/酒名,回车搜索',
|
hintText: hasKw ? '继续输入新关键词…' : '单号/往来单位/酒名,回车搜索',
|
||||||
prefixIcon: const Icon(Icons.search, size: 16),
|
|
||||||
hintStyle: const TextStyle(fontSize: 12),
|
hintStyle: const TextStyle(fontSize: 12),
|
||||||
|
// 搜索图标 +(已生效时)框内 chip 标签,仅一个词;✕ 删除即清除搜索。
|
||||||
|
// 用 prefixIcon 而非 prefix:后者仅在聚焦/有文字时才显示,搜索后输入框为空会被隐藏。
|
||||||
|
prefixIconConstraints:
|
||||||
|
const BoxConstraints(minWidth: 0, minHeight: 0),
|
||||||
|
prefixIcon: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8, right: 6),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.search, size: 16),
|
||||||
|
if (hasKw) ...[
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
SearchChip(label: _appliedKw, onDeleted: _clearSearch),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: const Icon(Icons.search, size: 16),
|
icon: const Icon(Icons.search, size: 16),
|
||||||
tooltip: '搜索',
|
tooltip: '搜索',
|
||||||
@@ -495,7 +530,7 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
|||||||
onPrint: () async {
|
onPrint: () async {
|
||||||
final order = await ref.read(stockInRepositoryProvider).get(o.id);
|
final order = await ref.read(stockInRepositoryProvider).get(o.id);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
await safePrint(context, () => printStockInOrder(order));
|
await showStockInOrderPrint(context, order);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
afterPrint: [
|
afterPrint: [
|
||||||
@@ -573,6 +608,8 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
|
|||||||
Future<void> _showDetail(BuildContext context, int orderId) async {
|
Future<void> _showDetail(BuildContext context, int orderId) async {
|
||||||
showAppDialog(
|
showAppDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
// 用分支 Navigator 承载,全屏弹窗只覆盖内容区,不盖住左侧栏/顶栏/状态栏
|
||||||
|
useRootNavigator: false,
|
||||||
builder: (ctx) => _StockInDetailDialog(
|
builder: (ctx) => _StockInDetailDialog(
|
||||||
orderId: orderId,
|
orderId: orderId,
|
||||||
repository: ref.read(stockInRepositoryProvider),
|
repository: ref.read(stockInRepositoryProvider),
|
||||||
@@ -1010,40 +1047,36 @@ class _StockInDetailDialogState extends ConsumerState<_StockInDetailDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Dialog(
|
return Dialog.fullscreen(
|
||||||
child: Container(
|
child: SafeArea(
|
||||||
width: context.dialogWidth(720),
|
|
||||||
constraints: const BoxConstraints(maxHeight: 600),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: AppTheme.primary,
|
color: AppTheme.brand50,
|
||||||
borderRadius: BorderRadius.only(
|
border: Border(bottom: BorderSide(color: AppTheme.border)),
|
||||||
topLeft: Radius.circular(12),
|
|
||||||
topRight: Radius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back, color: AppTheme.primaryDark),
|
||||||
|
tooltip: '返回',
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
),
|
||||||
const Text('入库单详情',
|
const Text('入库单详情',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: Colors.white)),
|
color: AppTheme.primaryDark)),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
if (_loadedOrder != null)
|
if (_loadedOrder != null)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.print_outlined, color: Colors.white),
|
icon: const Icon(Icons.print_outlined, color: AppTheme.primaryDark),
|
||||||
tooltip: '打印',
|
tooltip: '打印',
|
||||||
onPressed: () => safePrint(context, () => printStockInOrder(_loadedOrder!)),
|
onPressed: () => showStockInOrderPrint(context, _loadedOrder!),
|
||||||
),
|
),
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.close, color: Colors.white),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import 'package:go_router/go_router.dart';
|
|||||||
import '../../core/responsive/responsive.dart';
|
import '../../core/responsive/responsive.dart';
|
||||||
import '../../core/theme/app_theme.dart';
|
import '../../core/theme/app_theme.dart';
|
||||||
import '../../core/auth/auth_state.dart';
|
import '../../core/auth/auth_state.dart';
|
||||||
import '../../core/utils/print_util.dart';
|
|
||||||
import '../../core/utils/date_util.dart';
|
import '../../core/utils/date_util.dart';
|
||||||
|
import '../../widgets/order_print_preview_dialog.dart';
|
||||||
import '../../models/inventory.dart';
|
import '../../models/inventory.dart';
|
||||||
import '../../models/stock_out.dart';
|
import '../../models/stock_out.dart';
|
||||||
import '../../widgets/date_picker_field.dart';
|
import '../../widgets/date_picker_field.dart';
|
||||||
@@ -258,7 +258,7 @@ class _StockOutFormScreenState extends ConsumerState<StockOutFormScreen> {
|
|||||||
|
|
||||||
Future<void> _printOrder() async {
|
Future<void> _printOrder() async {
|
||||||
if (_loadedOrder == null) return;
|
if (_loadedOrder == null) return;
|
||||||
await safePrint(context, () => printStockOutOrder(_loadedOrder!));
|
await showStockOutOrderPrint(context, _loadedOrder!);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _submit(bool asDraft) async {
|
Future<void> _submit(bool asDraft) async {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import '../../core/utils/dialog_util.dart';
|
import '../../core/utils/dialog_util.dart';
|
||||||
import '../../core/errors/error_reporter.dart';
|
import '../../core/errors/error_reporter.dart';
|
||||||
import '../../core/utils/print_util.dart' show safePrint, printStockOutOrder;
|
import '../../widgets/order_print_preview_dialog.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -15,8 +15,8 @@ import '../../widgets/multi_select_dropdown.dart' show ColDef, ColumnToggleButto
|
|||||||
import '../../core/storage/column_prefs.dart';
|
import '../../core/storage/column_prefs.dart';
|
||||||
import '../../widgets/page_scaffold.dart';
|
import '../../widgets/page_scaffold.dart';
|
||||||
import '../../widgets/status_badge.dart';
|
import '../../widgets/status_badge.dart';
|
||||||
|
import '../../widgets/search_chip.dart';
|
||||||
import '../../core/utils/export_util.dart';
|
import '../../core/utils/export_util.dart';
|
||||||
import '../../core/utils/print_util.dart';
|
|
||||||
import '../../providers/inventory_provider.dart';
|
import '../../providers/inventory_provider.dart';
|
||||||
import '../../providers/tab_state_provider.dart';
|
import '../../providers/tab_state_provider.dart';
|
||||||
import '../../providers/product_provider.dart';
|
import '../../providers/product_provider.dart';
|
||||||
@@ -43,6 +43,7 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
|
|||||||
Set<String>? _hiddenCols; // null = 尚未载入本地存档(回退到 minWidth 首次默认)
|
Set<String>? _hiddenCols; // null = 尚未载入本地存档(回退到 minWidth 首次默认)
|
||||||
final _searchCtrl = TextEditingController();
|
final _searchCtrl = TextEditingController();
|
||||||
final _codeSearchCtrl = TextEditingController();
|
final _codeSearchCtrl = TextEditingController();
|
||||||
|
String _appliedKw = ''; // 已生效的搜索词(框内 chip 标签展示)
|
||||||
|
|
||||||
static const _screenId = 'stock_out_list';
|
static const _screenId = 'stock_out_list';
|
||||||
|
|
||||||
@@ -59,6 +60,10 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
|
|||||||
final want = tab == 1 ? 'pending,draft' : _statusFilter;
|
final want = tab == 1 ? 'pending,draft' : _statusFilter;
|
||||||
final notifier = ref.read(stockOutListProvider.notifier);
|
final notifier = ref.read(stockOutListProvider.notifier);
|
||||||
if (notifier.currentStatus != want) notifier.setStatus(want);
|
if (notifier.currentStatus != want) notifier.setStatus(want);
|
||||||
|
// 同步已生效的搜索词到框内 chip(provider 持久化,切走再回来不丢)
|
||||||
|
if (notifier.currentKeyword != _appliedKw) {
|
||||||
|
setState(() => _appliedKw = notifier.currentKeyword);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +87,19 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _triggerSearch() => ref
|
void _triggerSearch() {
|
||||||
.read(stockOutListProvider.notifier)
|
final kw = _searchCtrl.text.trim();
|
||||||
.setKeyword(_searchCtrl.text.trim());
|
ref.read(stockOutListProvider.notifier).setKeyword(kw);
|
||||||
|
// 仅支持单个搜索词:生效后输入框清空,搜索词转为框内 chip 标签
|
||||||
|
setState(() => _appliedKw = kw);
|
||||||
|
if (kw.isNotEmpty) _searchCtrl.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _clearSearch() {
|
||||||
|
_searchCtrl.clear();
|
||||||
|
setState(() => _appliedKw = '');
|
||||||
|
ref.read(stockOutListProvider.notifier).setKeyword('');
|
||||||
|
}
|
||||||
|
|
||||||
void _triggerCodeSearch() => ref
|
void _triggerCodeSearch() => ref
|
||||||
.read(stockOutListProvider.notifier)
|
.read(stockOutListProvider.notifier)
|
||||||
@@ -375,12 +390,29 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
|
|||||||
)
|
)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
final hasKw = _appliedKw.isNotEmpty;
|
||||||
final searchField = TextField(
|
final searchField = TextField(
|
||||||
controller: _searchCtrl,
|
controller: _searchCtrl,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: '单号/往来单位/酒名,回车搜索',
|
hintText: hasKw ? '继续输入新关键词…' : '单号/往来单位/酒名,回车搜索',
|
||||||
prefixIcon: const Icon(Icons.search, size: 16),
|
|
||||||
hintStyle: const TextStyle(fontSize: 12),
|
hintStyle: const TextStyle(fontSize: 12),
|
||||||
|
// 搜索图标 +(已生效时)框内 chip 标签,仅一个词;✕ 删除即清除搜索。
|
||||||
|
// 用 prefixIcon 而非 prefix:后者仅在聚焦/有文字时才显示,搜索后输入框为空会被隐藏。
|
||||||
|
prefixIconConstraints:
|
||||||
|
const BoxConstraints(minWidth: 0, minHeight: 0),
|
||||||
|
prefixIcon: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 8, right: 6),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Icon(Icons.search, size: 16),
|
||||||
|
if (hasKw) ...[
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
SearchChip(label: _appliedKw, onDeleted: _clearSearch),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: const Icon(Icons.search, size: 16),
|
icon: const Icon(Icons.search, size: 16),
|
||||||
tooltip: '搜索',
|
tooltip: '搜索',
|
||||||
@@ -526,7 +558,7 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
|
|||||||
onPrint: () async {
|
onPrint: () async {
|
||||||
final order = await ref.read(stockOutRepositoryProvider).get(o.id);
|
final order = await ref.read(stockOutRepositoryProvider).get(o.id);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
await safePrint(context, () => printStockOutOrder(order));
|
await showStockOutOrderPrint(context, order);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onSettle: () => _confirmSettle(context, o.id, 'stock_out'),
|
onSettle: () => _confirmSettle(context, o.id, 'stock_out'),
|
||||||
@@ -574,6 +606,8 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
|
|||||||
Future<void> _showDetail(BuildContext context, int orderId) async {
|
Future<void> _showDetail(BuildContext context, int orderId) async {
|
||||||
showAppDialog(
|
showAppDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
// 用分支 Navigator 承载,全屏弹窗只覆盖内容区,不盖住左侧栏/顶栏/状态栏
|
||||||
|
useRootNavigator: false,
|
||||||
builder: (ctx) => _StockOutDetailDialog(
|
builder: (ctx) => _StockOutDetailDialog(
|
||||||
orderId: orderId,
|
orderId: orderId,
|
||||||
repository: ref.read(stockOutRepositoryProvider),
|
repository: ref.read(stockOutRepositoryProvider),
|
||||||
@@ -924,40 +958,36 @@ class _StockOutDetailDialogState extends ConsumerState<_StockOutDetailDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Dialog(
|
return Dialog.fullscreen(
|
||||||
child: Container(
|
child: SafeArea(
|
||||||
width: context.dialogWidth(720),
|
|
||||||
constraints: const BoxConstraints(maxHeight: 600),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
color: AppTheme.primary,
|
color: AppTheme.brand50,
|
||||||
borderRadius: BorderRadius.only(
|
border: Border(bottom: BorderSide(color: AppTheme.border)),
|
||||||
topLeft: Radius.circular(12),
|
|
||||||
topRight: Radius.circular(12),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back, color: AppTheme.primaryDark),
|
||||||
|
tooltip: '返回',
|
||||||
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
|
),
|
||||||
const Text('出库单详情',
|
const Text('出库单详情',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: Colors.white)),
|
color: AppTheme.primaryDark)),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
if (_loadedOrder != null)
|
if (_loadedOrder != null)
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.print_outlined, color: Colors.white),
|
icon: const Icon(Icons.print_outlined, color: AppTheme.primaryDark),
|
||||||
tooltip: '打印',
|
tooltip: '打印',
|
||||||
onPressed: () => safePrint(context, () => printStockOutOrder(_loadedOrder!)),
|
onPressed: () => showStockOutOrderPrint(context, _loadedOrder!),
|
||||||
),
|
),
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.close, color: Colors.white),
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -1040,7 +1070,7 @@ class _StockOutDetailDialogState extends ConsumerState<_StockOutDetailDialog> {
|
|||||||
children: [
|
children: [
|
||||||
TableRow(
|
TableRow(
|
||||||
decoration: const BoxDecoration(color: Color(0xFFF0F4FF)),
|
decoration: const BoxDecoration(color: Color(0xFFF0F4FF)),
|
||||||
children: ['序号', '商品编码', '名称', '系列', '规格', '生产日期', '批次号', '数量', '单价', '金额']
|
children: ['序号', '商品编码', '名称', '系列', '规格', '生产日期', '批次号', '成本价', '售价', '利润']
|
||||||
.map((h) => Padding(
|
.map((h) => Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
|
||||||
child: Text(h,
|
child: Text(h,
|
||||||
@@ -1069,9 +1099,9 @@ class _StockOutDetailDialogState extends ConsumerState<_StockOutDetailDialog> {
|
|||||||
: (item.productionDate ?? '-')),
|
: (item.productionDate ?? '-')),
|
||||||
_TableCell(
|
_TableCell(
|
||||||
(item.batchNo?.isNotEmpty ?? false) ? item.batchNo! : '-'),
|
(item.batchNo?.isNotEmpty ?? false) ? item.batchNo! : '-'),
|
||||||
_TableCell(item.quantity.toStringAsFixed(3)),
|
|
||||||
_TableCell('¥${item.unitPrice.toStringAsFixed(2)}'),
|
_TableCell('¥${item.unitPrice.toStringAsFixed(2)}'),
|
||||||
_TableCell('¥${item.totalPrice.toStringAsFixed(2)}'),
|
_TableCell('¥${item.salePrice.toStringAsFixed(2)}'),
|
||||||
|
_TableCell('¥${(item.salePrice - item.unitPrice).toStringAsFixed(2)}'),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -0,0 +1,258 @@
|
|||||||
|
import 'dart:typed_data';
|
||||||
|
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:printing/printing.dart';
|
||||||
|
import '../core/errors/error_reporter.dart';
|
||||||
|
import '../core/theme/app_theme.dart';
|
||||||
|
import '../core/responsive/responsive.dart';
|
||||||
|
import '../core/utils/print_util.dart';
|
||||||
|
import '../models/stock_in.dart';
|
||||||
|
import '../models/stock_out.dart';
|
||||||
|
|
||||||
|
/// 单据打印预览弹窗:把待打印的 A4 PDF 光栅化成图片(所见即所得)逐页展示,
|
||||||
|
/// 页内点「打印」再调系统打印。解决部分 Windows 系统打印对话框无预览的问题。
|
||||||
|
///
|
||||||
|
/// 仅桌面端使用;Web 端走浏览器自带的打印预览(见 [showStockInOrderPrint])。
|
||||||
|
class OrderPrintPreviewDialog extends StatefulWidget {
|
||||||
|
/// 标题,如「入库单打印预览」。
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// 系统打印任务名(也作另存默认文件名前缀)。
|
||||||
|
final String printName;
|
||||||
|
|
||||||
|
/// 惰性生成 PDF 字节。
|
||||||
|
final Future<Uint8List> Function() pdfBuilder;
|
||||||
|
|
||||||
|
const OrderPrintPreviewDialog({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.printName,
|
||||||
|
required this.pdfBuilder,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<OrderPrintPreviewDialog> createState() =>
|
||||||
|
_OrderPrintPreviewDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _OrderPrintPreviewDialogState extends State<OrderPrintPreviewDialog> {
|
||||||
|
Uint8List? _pdfBytes;
|
||||||
|
final List<Uint8List> _pages = [];
|
||||||
|
bool _rendering = true;
|
||||||
|
bool _printing = false;
|
||||||
|
String _error = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_render();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _render() async {
|
||||||
|
try {
|
||||||
|
final bytes = await widget.pdfBuilder();
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _pdfBytes = bytes);
|
||||||
|
// 逐页光栅化(progressive),DPI 取 110 兼顾清晰与速度。
|
||||||
|
await for (final raster in Printing.raster(bytes, dpi: 110)) {
|
||||||
|
final png = await raster.toPng();
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _pages.add(png));
|
||||||
|
}
|
||||||
|
} catch (e, st) {
|
||||||
|
reportError(e, st);
|
||||||
|
if (mounted) setState(() => _error = '预览生成失败:$e');
|
||||||
|
} finally {
|
||||||
|
if (mounted) setState(() => _rendering = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _doPrint() async {
|
||||||
|
final bytes = _pdfBytes;
|
||||||
|
if (bytes == null || _printing) return;
|
||||||
|
setState(() => _printing = true);
|
||||||
|
try {
|
||||||
|
await Printing.layoutPdf(
|
||||||
|
name: '${widget.printName}_${_ts()}',
|
||||||
|
dynamicLayout: false,
|
||||||
|
onLayout: (_) async => bytes,
|
||||||
|
);
|
||||||
|
if (mounted) Navigator.of(context).pop();
|
||||||
|
} catch (e, st) {
|
||||||
|
reportError(e, st);
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_printing = false;
|
||||||
|
_error = '打印失败,请检查打印机连接和驱动是否正常。\n详情:$e';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _ts() {
|
||||||
|
final n = DateTime.now();
|
||||||
|
String p(int v) => v.toString().padLeft(2, '0');
|
||||||
|
return '${n.year}${p(n.month)}${p(n.day)}_${p(n.hour)}${p(n.minute)}${p(n.second)}';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Dialog(
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
child: Container(
|
||||||
|
width: context.dialogWidth(720),
|
||||||
|
constraints: const BoxConstraints(maxHeight: 720),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
// ── 顶栏 ──────────────────────────────────────────────────────────
|
||||||
|
Container(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 20, vertical: 14),
|
||||||
|
decoration: const BoxDecoration(
|
||||||
|
color: AppTheme.primary,
|
||||||
|
borderRadius: BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(12),
|
||||||
|
topRight: Radius.circular(12),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(widget.title,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.white)),
|
||||||
|
const Spacer(),
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.close, color: Colors.white),
|
||||||
|
onPressed:
|
||||||
|
_printing ? null : () => Navigator.of(context).pop(),
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
constraints: const BoxConstraints(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// ── 预览区 ─────────────────────────────────────────────────────────
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
width: double.infinity,
|
||||||
|
color: const Color(0xFFE9ECF1),
|
||||||
|
child: _buildBody(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// ── 底栏 ──────────────────────────────────────────────────────────
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 10, 16, 14),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
_error.isNotEmpty
|
||||||
|
? _error
|
||||||
|
: (_rendering
|
||||||
|
? '正在生成预览…'
|
||||||
|
: '共 ${_pages.length} 页'),
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: _error.isNotEmpty
|
||||||
|
? Colors.red
|
||||||
|
: AppTheme.textSecondary),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed:
|
||||||
|
_printing ? null : () => Navigator.of(context).pop(),
|
||||||
|
child: const Text('取消'),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
FilledButton.icon(
|
||||||
|
icon: const Icon(Icons.print, size: 18),
|
||||||
|
onPressed: (_pdfBytes == null || _printing)
|
||||||
|
? null
|
||||||
|
: _doPrint,
|
||||||
|
label: Text(_printing ? '打印中…' : '打印'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildBody() {
|
||||||
|
if (_pages.isEmpty) {
|
||||||
|
if (_error.isNotEmpty) {
|
||||||
|
return Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Text(_error,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(color: Colors.red, fontSize: 13)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
return ListView.separated(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||||
|
itemCount: _pages.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(height: 16),
|
||||||
|
itemBuilder: (_, i) => Center(
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.white,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withOpacity(0.18),
|
||||||
|
blurRadius: 8,
|
||||||
|
offset: const Offset(0, 2),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Image.memory(_pages[i], fit: BoxFit.contain),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 打印入库单:桌面端先弹应用内预览,Web 端走浏览器自带打印预览。
|
||||||
|
Future<void> showStockInOrderPrint(
|
||||||
|
BuildContext context, StockInOrder order) async {
|
||||||
|
if (kIsWeb) {
|
||||||
|
await safePrint(context, () => printStockInOrder(order));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (_) => OrderPrintPreviewDialog(
|
||||||
|
title: '入库单打印预览',
|
||||||
|
printName: '入库单',
|
||||||
|
pdfBuilder: () => buildStockInOrderPdf(order),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 打印出库单:桌面端先弹应用内预览,Web 端走浏览器自带打印预览。
|
||||||
|
Future<void> showStockOutOrderPrint(
|
||||||
|
BuildContext context, StockOutOrder order) async {
|
||||||
|
if (kIsWeb) {
|
||||||
|
await safePrint(context, () => printStockOutOrder(order));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await showDialog<void>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (_) => OrderPrintPreviewDialog(
|
||||||
|
title: '出库单打印预览',
|
||||||
|
printName: '出库单',
|
||||||
|
pdfBuilder: () => buildStockOutOrderPdf(order),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// 搜索框内嵌的「已生效搜索词」标签:紧凑圆角 chip + ✕ 删除按钮。
|
||||||
|
///
|
||||||
|
/// 用于列表屏搜索框 [InputDecoration.prefix],仅展示单个搜索词;
|
||||||
|
/// 点 ✕ 触发 [onDeleted] 清除搜索。
|
||||||
|
class SearchChip extends StatelessWidget {
|
||||||
|
const SearchChip({super.key, required this.label, required this.onDeleted});
|
||||||
|
|
||||||
|
final String label;
|
||||||
|
final VoidCallback onDeleted;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final bg = theme.colorScheme.primary.withValues(alpha: 0.12);
|
||||||
|
final fg = theme.colorScheme.primary;
|
||||||
|
return Container(
|
||||||
|
padding: const EdgeInsets.only(left: 8, right: 2, top: 2, bottom: 2),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: bg,
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 120),
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 12,
|
||||||
|
color: fg,
|
||||||
|
fontWeight: FontWeight.w500,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
InkResponse(
|
||||||
|
onTap: onDeleted,
|
||||||
|
radius: 14,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(2),
|
||||||
|
child: Icon(Icons.close, size: 14, color: fg),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user