a20645671b
Deploy Client / build-client-web (push) Successful in 41s
Deploy Client / build-macos (push) Successful in 5m37s
Deploy Client / build-android (push) Successful in 1m15s
Deploy Client / build-ios (push) Successful in 4m3s
Deploy Client / build-windows (push) Has been cancelled
Deploy Client / release-deploy-client (push) Has been cancelled
出库列表加商品编码精确搜索框 + 移除数据导入入口 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YZ4DskSRKsSiheQonFtQvx
147 lines
3.7 KiB
Dart
147 lines
3.7 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../core/api/api_client.dart';
|
|
import '../core/auth/auth_state.dart';
|
|
import '../core/config/app_constants.dart';
|
|
import '../core/models/page_result.dart';
|
|
import '../models/stock_out.dart';
|
|
import '../repositories/stock_out_repository.dart';
|
|
import 'connectivity_provider.dart';
|
|
import 'inventory_provider.dart';
|
|
|
|
final stockOutRepositoryProvider = Provider<StockOutRepository>((ref) {
|
|
return StockOutRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final stockOutListProvider =
|
|
AsyncNotifierProvider<StockOutListNotifier, PageResult<StockOutOrder>>(
|
|
StockOutListNotifier.new,
|
|
);
|
|
|
|
class StockOutListNotifier extends AsyncNotifier<PageResult<StockOutOrder>> {
|
|
int _page = 1;
|
|
int _pageSize = AppConstants.defaultPageSize;
|
|
String _status = '';
|
|
String? _startDate;
|
|
String? _endDate;
|
|
String _keyword = '';
|
|
String _productCode = '';
|
|
PageResult<StockOutOrder>? _cache;
|
|
|
|
@override
|
|
Future<PageResult<StockOutOrder>> build() async {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
ref.watch(networkRecoveryCountProvider);
|
|
try {
|
|
final result = await _fetch();
|
|
_cache = result;
|
|
return result;
|
|
} catch (_) {
|
|
if (_cache != null) return _cache!;
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
Future<PageResult<StockOutOrder>> _fetch() {
|
|
return ref.read(stockOutRepositoryProvider).list(
|
|
status: _status.isEmpty ? null : _status,
|
|
startDate: _startDate,
|
|
endDate: _endDate,
|
|
keyword: _keyword.isEmpty ? null : _keyword,
|
|
productCode: _productCode.isEmpty ? null : _productCode,
|
|
page: _page,
|
|
pageSize: _pageSize,
|
|
);
|
|
}
|
|
|
|
void setPage(int page) {
|
|
_page = page;
|
|
reload();
|
|
}
|
|
|
|
void setPageSize(int pageSize) {
|
|
_pageSize = pageSize;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
|
|
String get currentStatus => _status;
|
|
|
|
void setStatus(String status) {
|
|
_status = status;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setDateRange(String? startDate, String? endDate) {
|
|
_startDate = startDate;
|
|
_endDate = endDate;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setKeyword(String keyword) {
|
|
_keyword = keyword;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
/// 按商品编码精确反查(独立于 keyword)
|
|
void setProductCode(String code) {
|
|
_productCode = code;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void reload() {
|
|
state = const AsyncValue.loading();
|
|
_fetch().then((result) {
|
|
_cache = result;
|
|
state = AsyncValue.data(result);
|
|
}, onError: (e, st) {
|
|
if (_cache != null) {
|
|
state = AsyncValue.data(_cache!);
|
|
} else {
|
|
state = AsyncValue.error(e, st);
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> createOrder(Map<String, dynamic> data) async {
|
|
await ref.read(stockOutRepositoryProvider).create(data);
|
|
reload();
|
|
}
|
|
|
|
Future<void> deleteOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).delete(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> submitOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).submit(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> approveOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).approve(id);
|
|
reload();
|
|
ref.invalidate(inventoryListProvider);
|
|
}
|
|
|
|
Future<void> rejectOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).reject(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> withdrawOrder(int id) async {
|
|
await ref.read(stockOutRepositoryProvider).withdraw(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> returnItems(int id, List<int> itemIds) async {
|
|
await ref.read(stockOutRepositoryProvider).returnItems(id, itemIds);
|
|
reload();
|
|
ref.invalidate(inventoryListProvider);
|
|
}
|
|
}
|