Compare commits

..

2 Commits

Author SHA1 Message Date
wangjia a678c3806e chore: release client-v1.0.79
Deploy Client / build-client-web (push) Successful in 44s
Deploy Client / build-macos (push) Successful in 2m29s
Deploy Client / build-android (push) Successful in 1m23s
Deploy Client / build-ios (push) Successful in 2m59s
Deploy Client / build-windows (push) Successful in 1m52s
Deploy Client / release-deploy-client (push) Successful in 2m40s
入库/出库单搜索框升级:搜索后关键词转为框内 chip 标签 + 一键清除(✕),仅保留单个搜索词;新增 SearchChip 组件 + provider currentKeyword getter 进屏同步。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
2026-06-24 12:08:55 +08:00
wangjia 5ff41cc505 chore: release server-v1.0.81
Deploy Server / release-deploy-server (push) Successful in 1m54s
修复入库单/出库单按商品名搜不到历史导入单:搜索酒名条件由 COALESCE(被占位名劫持) 改为 p.name OR it.product_name 任一命中,并加回归测试。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
2026-06-24 11:56:21 +08:00
11 changed files with 236 additions and 16 deletions
+5
View File
@@ -5,6 +5,11 @@ 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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.79] - 2026-06-24
### 改进
- 入库单 / 出库单搜索框升级:搜索后关键词以标签形式显示在搜索框内,带一键清除(✕)按钮,输入框自动清空便于继续输入;当前仅支持单个搜索词。
## [1.0.78] - 2026-06-24
### 改进
+5
View File
@@ -5,6 +5,11 @@
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).
## [1.0.81] - 2026-06-24
### 修复
- 入库单 / 出库单按商品名搜索:历史导入的单据现在也能按商品名搜到(此前明细统一挂占位商品,搜索被占位名顶替,只能搜到新建单据)。
## [1.0.80] - 2026-06-24
### 改进
+5 -3
View File
@@ -53,16 +53,18 @@ func (h *StockInHandler) List(c *gin.Context) {
if kw := strings.TrimSpace(c.Query("keyword")); kw != "" {
like := "%" + kw + "%"
// keyword 同时命中:单号 / 往来单位 / 酒名(含全拼+首字母,反查含该酒明细的单据)。
// 酒名优先取 product 主数据、回退快照列;拼音只在 products 上(快照无拼音列)。
// 酒名product 主数据名 OR 明细快照名」任一命中——不能用 COALESCE 二选一:历史导入单的
// 明细 product_id 统一指向占位商品「历史导入占位」(p.name 非空),COALESCE 会被占位名劫持,
// 永远取不到真实快照 product_name,导致导入单按真实酒名搜不到。拼音只在 products 上(快照无拼音列)。
query = query.Where(
"order_no 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"+
" 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"+
" 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 ?))",
like, shopID, like, shopID, like, like, like,
like, shopID, like, shopID, like, like, like, like,
)
}
+44 -1
View File
@@ -263,7 +263,7 @@ func TestStockInHandler_TotalAmount(t *testing.T) {
"warehouse_id": warehouse.ID,
"order_date": time.Now().Format(time.RFC3339),
"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
},
})
@@ -487,6 +487,49 @@ func TestStockInHandler_List_FilterByProductName(t *testing.T) {
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) {
db := testutil.SetupTestDB()
shop := testutil.CreateTestShop(db, "SI013")
+5 -3
View File
@@ -46,16 +46,18 @@ func (h *StockOutHandler) List(c *gin.Context) {
if kw := strings.TrimSpace(c.Query("keyword")); kw != "" {
like := "%" + kw + "%"
// keyword 同时命中:单号 / 往来单位 / 酒名(含全拼+首字母,反查含该酒明细的单据)。
// 酒名优先取 product 主数据、回退快照列;拼音只在 products 上(快照无拼音列)。
// 酒名product 主数据名 OR 明细快照名」任一命中——不能用 COALESCE 二选一:历史导入单的
// 明细 product_id 统一指向占位商品「历史导入占位」(p.name 非空),COALESCE 会被占位名劫持,
// 永远取不到真实快照 product_name,导致导入单按真实酒名搜不到。拼音只在 products 上(快照无拼音列)。
query = query.Where(
"order_no 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"+
" 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"+
" 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 ?))",
like, shopID, like, shopID, like, like, like,
like, shopID, like, shopID, like, like, like, like,
)
}
// 按商品编码反查单据:精确匹配,走 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))
}
// 回归:历史导入出库单的明细 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) {
db := testutil.SetupTestDB()
shop := testutil.CreateTestShop(db, "SO004")
@@ -69,6 +69,8 @@ class StockInListNotifier extends AsyncNotifier<PageResult<StockInOrder>> {
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
String get currentStatus => _status;
String get currentKeyword => _keyword;
void setStatus(String status) {
_status = status;
_page = 1;
@@ -71,6 +71,8 @@ class StockOutListNotifier extends AsyncNotifier<PageResult<StockOutOrder>> {
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
String get currentStatus => _status;
String get currentKeyword => _keyword;
void setStatus(String status) {
_status = status;
_page = 1;
@@ -17,6 +17,7 @@ import '../../widgets/multi_select_dropdown.dart' show ColDef, ColumnToggleButto
import '../../core/storage/column_prefs.dart';
import '../../widgets/page_scaffold.dart';
import '../../widgets/status_badge.dart';
import '../../widgets/search_chip.dart';
import '../../core/utils/export_util.dart';
import '../../providers/inventory_provider.dart';
import '../../providers/tab_state_provider.dart';
@@ -44,6 +45,7 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
Set<String> _filterSupplier = {};
Set<String>? _hiddenCols; // null = 尚未载入本地存档(回退到 minWidth 首次默认)
final _searchCtrl = TextEditingController();
String _appliedKw = ''; // 已生效的搜索词(框内 chip 标签展示)
static const _screenId = 'stock_in_list';
@@ -72,6 +74,10 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
final want = tab == 1 ? 'pending,draft' : _statusFilter;
final notifier = ref.read(stockInListProvider.notifier);
if (notifier.currentStatus != want) notifier.setStatus(want);
// 同步已生效的搜索词到框内 chip(provider 持久化,切走再回来不丢)
if (notifier.currentKeyword != _appliedKw) {
setState(() => _appliedKw = notifier.currentKeyword);
}
});
}
@@ -81,8 +87,19 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
super.dispose();
}
void _triggerSearch() =>
ref.read(stockInListProvider.notifier).setKeyword(_searchCtrl.text.trim());
void _triggerSearch() {
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
? '${_dateRange!.start.year}-${_dateRange!.start.month.toString().padLeft(2, '0')}-${_dateRange!.start.day.toString().padLeft(2, '0')}'
@@ -363,12 +380,29 @@ class _StockInListScreenState extends ConsumerState<StockInListScreen> {
)
: null;
final hasKw = _appliedKw.isNotEmpty;
final searchField = TextField(
controller: _searchCtrl,
decoration: InputDecoration(
hintText: '单号/往来单位/酒名,回车搜索',
prefixIcon: const Icon(Icons.search, size: 16),
hintText: hasKw ? '继续输入新关键词…' : '单号/往来单位/酒名,回车搜索',
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(
icon: const Icon(Icons.search, size: 16),
tooltip: '搜索',
@@ -15,6 +15,7 @@ import '../../widgets/multi_select_dropdown.dart' show ColDef, ColumnToggleButto
import '../../core/storage/column_prefs.dart';
import '../../widgets/page_scaffold.dart';
import '../../widgets/status_badge.dart';
import '../../widgets/search_chip.dart';
import '../../core/utils/export_util.dart';
import '../../core/utils/print_util.dart';
import '../../providers/inventory_provider.dart';
@@ -43,6 +44,7 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
Set<String>? _hiddenCols; // null = 尚未载入本地存档(回退到 minWidth 首次默认)
final _searchCtrl = TextEditingController();
final _codeSearchCtrl = TextEditingController();
String _appliedKw = ''; // 已生效的搜索词(框内 chip 标签展示)
static const _screenId = 'stock_out_list';
@@ -59,6 +61,10 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
final want = tab == 1 ? 'pending,draft' : _statusFilter;
final notifier = ref.read(stockOutListProvider.notifier);
if (notifier.currentStatus != want) notifier.setStatus(want);
// 同步已生效的搜索词到框内 chip(provider 持久化,切走再回来不丢)
if (notifier.currentKeyword != _appliedKw) {
setState(() => _appliedKw = notifier.currentKeyword);
}
});
}
@@ -82,9 +88,19 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
super.dispose();
}
void _triggerSearch() => ref
.read(stockOutListProvider.notifier)
.setKeyword(_searchCtrl.text.trim());
void _triggerSearch() {
final kw = _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
.read(stockOutListProvider.notifier)
@@ -375,12 +391,29 @@ class _StockOutListScreenState extends ConsumerState<StockOutListScreen> {
)
: null;
final hasKw = _appliedKw.isNotEmpty;
final searchField = TextField(
controller: _searchCtrl,
decoration: InputDecoration(
hintText: '单号/往来单位/酒名,回车搜索',
prefixIcon: const Icon(Icons.search, size: 16),
hintText: hasKw ? '继续输入新关键词…' : '单号/往来单位/酒名,回车搜索',
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(
icon: const Icon(Icons.search, size: 16),
tooltip: '搜索',
+52
View File
@@ -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),
),
),
],
),
);
}
}