904bfbe67d
照原型 inventory.html 把库存屏从「3 tab」重排为单视图: - 去 3 tab(库存查询/预警/流水)→ 单视图;预警并入 KPI 缺货卡点击筛选;流水移商品详情 - 头部:库存管理 + 共 N 个 SKU·数据实时 + 列设置/导出(盘点/新增入库去掉,走专门菜单) - KPI 4 卡走全店汇总接口:SKU总数/库存货值(Σqty×进价)/在库数量/缺货预警(可点筛选) - 表格 12 列:加 库存(低库存染色)/成本价(进价)/单价(售价);操作列只「查看详情」;状态圆点 - 仓库/备注默认隐藏;工具栏 搜索+状态筛选+重置 - 后端 GET /inventory/summary 全店汇总(守 shop_id);前端 model/repository/provider 配套 - golden_harness:monospace 指向 Noto(消等宽数字黑块,全 golden 受益);库存屏存量 grey 清零 后端编译/库存测试通过;前端 analyze 0 error,flutter test 242 通过;代码端颜色闸 0 违规。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TSKEiHsvauyxYUW2itzUXX
105 lines
3.1 KiB
Dart
105 lines
3.1 KiB
Dart
import 'package:dio/dio.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/exceptions.dart';
|
|
import '../core/models/page_result.dart';
|
|
import '../models/inventory.dart';
|
|
|
|
class InventoryRepository {
|
|
final ApiClient _client;
|
|
|
|
const InventoryRepository(this._client);
|
|
|
|
Future<PageResult<Inventory>> listInventory({
|
|
int? warehouseId,
|
|
int? productId,
|
|
String? keyword,
|
|
List<String>? series,
|
|
List<String>? spec,
|
|
int page = 1,
|
|
int pageSize = 50,
|
|
}) async {
|
|
try {
|
|
final params = <String, dynamic>{
|
|
'page': page,
|
|
'page_size': pageSize,
|
|
if (warehouseId != null) 'warehouse_id': warehouseId,
|
|
if (productId != null) 'product_id': productId,
|
|
if (keyword != null && keyword.isNotEmpty) 'keyword': keyword,
|
|
if (series != null && series.isNotEmpty) 'series': series.join(','),
|
|
if (spec != null && spec.isNotEmpty) 'spec': spec.join(','),
|
|
};
|
|
final resp = await _client.get('/inventory', params: params);
|
|
return PageResult.fromJson(
|
|
resp.data as Map<String, dynamic>,
|
|
Inventory.fromJson,
|
|
);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '获取库存失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<InventorySummary> getSummary() async {
|
|
try {
|
|
final resp = await _client.get('/inventory/summary');
|
|
return InventorySummary.fromJson(resp.data as Map<String, dynamic>);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '获取库存汇总失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<Map<String, dynamic>> createCheck(Map<String, dynamic> data) async {
|
|
try {
|
|
final resp = await _client.post('/inventory/checks', data: data);
|
|
return resp.data as Map<String, dynamic>;
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '提交盘点失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> updateRemark(int id, String remark) async {
|
|
try {
|
|
await _client.put('/inventory/$id/remark', data: {'remark': remark});
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '更新备注失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<PageResult<InventoryLog>> listLogs({
|
|
int? warehouseId,
|
|
int? productId,
|
|
int page = 1,
|
|
int pageSize = 50,
|
|
}) async {
|
|
try {
|
|
final params = <String, dynamic>{
|
|
'page': page,
|
|
'page_size': pageSize,
|
|
if (warehouseId != null) 'warehouse_id': warehouseId,
|
|
if (productId != null) 'product_id': productId,
|
|
};
|
|
final resp = await _client.get('/inventory/logs', params: params);
|
|
return PageResult.fromJson(
|
|
resp.data as Map<String, dynamic>,
|
|
InventoryLog.fromJson,
|
|
);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '获取流水失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
}
|