71ed15b40b
Deploy Client / build-client-web (push) Successful in 42s
Deploy Client / build-windows (push) Successful in 1m53s
Deploy Client / build-macos (push) Successful in 2m10s
Deploy Client / build-android (push) Successful in 1m15s
Deploy Client / build-ios (push) Successful in 2m28s
Deploy Client / release-deploy-client (push) Successful in 1m21s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
123 lines
3.6 KiB
Dart
123 lines
3.6 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/stock_out.dart';
|
|
|
|
class StockOutRepository {
|
|
final ApiClient _client;
|
|
|
|
const StockOutRepository(this._client);
|
|
|
|
Future<PageResult<StockOutOrder>> list({
|
|
String? status,
|
|
String? startDate,
|
|
String? endDate,
|
|
String? keyword,
|
|
int page = 1,
|
|
int pageSize = 20,
|
|
}) async {
|
|
try {
|
|
final params = <String, dynamic>{
|
|
'page': page,
|
|
'page_size': pageSize,
|
|
if (status != null && status.isNotEmpty) 'status': status,
|
|
if (startDate != null) 'start_date': startDate,
|
|
if (endDate != null) 'end_date': endDate,
|
|
if (keyword != null && keyword.isNotEmpty) 'keyword': keyword,
|
|
};
|
|
final resp = await _client.get('/stock-out/orders', params: params);
|
|
return PageResult.fromJson(
|
|
resp.data as Map<String, dynamic>,
|
|
StockOutOrder.fromJson,
|
|
);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '获取出库单列表失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<StockOutOrder> get(int id) async {
|
|
try {
|
|
final resp = await _client.get('/stock-out/orders/$id');
|
|
return StockOutOrder.fromJson(
|
|
(resp.data as Map<String, dynamic>)['data'] as Map<String, dynamic>);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '获取出库单详情失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<StockOutOrder> create(Map<String, dynamic> data) async {
|
|
try {
|
|
final resp = await _client.post('/stock-out/orders', data: data);
|
|
return StockOutOrder.fromJson(
|
|
(resp.data as Map<String, dynamic>)['data'] as Map<String, dynamic>);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '创建出库单失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> update(int id, Map<String, dynamic> data) async {
|
|
try {
|
|
await _client.put('/stock-out/orders/$id', data: data);
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '修改出库单失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> delete(int id) async {
|
|
try {
|
|
await _client.delete('/stock-out/orders/$id');
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '删除出库单失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> submit(int id) async {
|
|
try {
|
|
await _client.put('/stock-out/orders/$id/submit');
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '提交审核失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> approve(int id) async {
|
|
try {
|
|
await _client.put('/stock-out/orders/$id/approve');
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '审核通过失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
|
|
Future<void> reject(int id) async {
|
|
try {
|
|
await _client.put('/stock-out/orders/$id/reject');
|
|
} on DioException catch (e) {
|
|
throw AppException(
|
|
e.response?.data?['error'] as String? ?? '拒绝失败',
|
|
statusCode: e.response?.statusCode,
|
|
);
|
|
}
|
|
}
|
|
}
|