355ac0ebc3
接后端新能力:listInventory 加 productId 透传;详情异步拉本商品库存+流水(失败 静默不阻塞主数据),渲染原型富数据三件套: - 3 KPI 卡(当前库存 / 库存货值=库存×进价 / 近30天出库=出库流水30天聚合) - 各仓库库存分布(按仓库分组 数量+货值) - 近期流水(StatusPill 入/出 + 增减量,最近 8 条) 价格历史待后端第二步。整屏 golden ×三主题入回归闸。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TSKEiHsvauyxYUW2itzUXX
93 lines
2.8 KiB
Dart
93 lines
2.8 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<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,
|
|
);
|
|
}
|
|
}
|
|
}
|