6238b86dcb
- 登录/注册(login.html/register.html 1:1):两栏卡片+品牌渐变面板+主题小衣服 pill(onSurface 变体)+记住我(记录并预填最近账号)+原型式 toast 校验; 登录 fidelity 1.4–2.1% 三主题全绿;注册暂不入闸(少 门店编号/兑换券 字段, 已记 CONTRACT,screens.mjs 留存根) - ds 原子补齐:DsToast(.toast 单例)/DsCheck(.check/.agree)/DsButton lg 档/ DsSelect 替换全部旧 DropdownButton/DsField label 在上/DsInput 后缀与密码形态 - 全屏统一:对话框按钮全 DsButton、盒式输入主题钉死(visualDensity.standard、 h38、InputDecorationTheme 渗漏修复)、图标全 lucide、JetBrains Mono 三端同源、 BrandMark 真相源 logo、只读模式写操作全量守卫(WriteGuard+DsToast) - 出入库列表:版式对齐原型(卡片对齐+搜索框居中)、KPI 近30天滚动、结清后 失效财务应收应付表;商品编辑抽屉介绍库改搜索下拉、图片双击全屏预览 - 删除旧 UI 死代码:DataTableCard/FormDialog/PageScaffold/SearchChip/ SelectProductDialog/tabStateProvider - golden/fidelity:stock-in/out 补注册(9%)、login 入册(8%)、goldens 全量重打; 修复 pubspec flutter_web_plugins 非法声明(CI pub get 阻断) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JJ1g8XV1YhhmHRzhwWEW7o
180 lines
5.3 KiB
Dart
180 lines
5.3 KiB
Dart
import 'dart:async';
|
|
|
|
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_in.dart';
|
|
import '../models/stock_summary.dart';
|
|
import '../repositories/stock_in_repository.dart';
|
|
import 'connectivity_provider.dart';
|
|
import 'inventory_provider.dart';
|
|
|
|
final stockInRepositoryProvider = Provider<StockInRepository>((ref) {
|
|
return StockInRepository(ref.watch(apiClientProvider));
|
|
});
|
|
|
|
final stockInListProvider =
|
|
AsyncNotifierProvider<StockInListNotifier, PageResult<StockInOrder>>(
|
|
StockInListNotifier.new,
|
|
);
|
|
|
|
/// 入库 KPI 汇总——自然月口径(财务屏「本月采购额」用;换店/网络恢复自动刷新)。
|
|
final stockInSummaryProvider = FutureProvider.autoDispose<StockSummary>((ref) {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
ref.watch(networkRecoveryCountProvider);
|
|
return ref.read(stockInRepositoryProvider).summary();
|
|
});
|
|
|
|
/// 入库 KPI 汇总——近 30 天滚动窗(入库列表卡片用;月初自然月全 0,用户拍板改滚动)。
|
|
final stockInSummary30Provider =
|
|
FutureProvider.autoDispose<StockSummary>((ref) {
|
|
ref.watch(authStateProvider.select((s) => s.user?.shopId));
|
|
ref.watch(networkRecoveryCountProvider);
|
|
return ref.read(stockInRepositoryProvider).summary(window: 'rolling30');
|
|
});
|
|
|
|
class StockInListNotifier extends AsyncNotifier<PageResult<StockInOrder>> {
|
|
int _page = 1;
|
|
int _pageSize = AppConstants.defaultPageSize;
|
|
String _status = '';
|
|
String? _startDate;
|
|
String? _endDate;
|
|
String _keyword = '';
|
|
Map<String, String> _detail = const {};
|
|
PageResult<StockInOrder>? _cache;
|
|
Timer? _searchDebounce;
|
|
|
|
@override
|
|
Future<PageResult<StockInOrder>> build() async {
|
|
ref.onDispose(() => _searchDebounce?.cancel());
|
|
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<StockInOrder>> _fetch() {
|
|
return ref.read(stockInRepositoryProvider).list(
|
|
status: _status.isEmpty ? null : _status,
|
|
startDate: _startDate,
|
|
endDate: _endDate,
|
|
keyword: _keyword.isEmpty ? null : _keyword,
|
|
detail: _detail.isEmpty ? null : _detail,
|
|
page: _page,
|
|
pageSize: _pageSize,
|
|
);
|
|
}
|
|
|
|
Map<String, String> get currentDetail => _detail;
|
|
|
|
/// 详细搜索多字段(order_no/partner_id/series/spec/category_id/... → 后端组合 AND)。
|
|
void setDetail(Map<String, String> detail) {
|
|
_detail = detail;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setPage(int page) {
|
|
_page = page;
|
|
reload();
|
|
}
|
|
|
|
void setPageSize(int pageSize) {
|
|
_pageSize = pageSize;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
/// 当前服务端状态过滤值(供页面进入时对齐标签/下拉,避免重复拉取)
|
|
String get currentStatus => _status;
|
|
|
|
String get currentKeyword => _keyword;
|
|
|
|
void setStatus(String status) {
|
|
_status = status;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
void setDateRange(String? startDate, String? endDate) {
|
|
_startDate = startDate;
|
|
_endDate = endDate;
|
|
_page = 1;
|
|
reload();
|
|
}
|
|
|
|
/// 关键词搜索(含酒名模糊反查,单次约 55ms 的明细扫描)。
|
|
/// 去重 + 防抖限流:同词不重查;连发回车/狂点合并取最后一次,避免昂贵查询被刷。
|
|
void setKeyword(String keyword) {
|
|
final kw = keyword.trim();
|
|
if (kw == _keyword) return;
|
|
_searchDebounce?.cancel();
|
|
_searchDebounce = Timer(const Duration(milliseconds: 350), () {
|
|
_keyword = kw;
|
|
_page = 1;
|
|
reload();
|
|
});
|
|
}
|
|
|
|
void reload() {
|
|
// 保留上一次数据(isReloading)→ 屏幕可继续渲染旧内容 + 叠加半透明进度,不白屏。
|
|
state = const AsyncValue<PageResult<StockInOrder>>.loading()
|
|
.copyWithPrevious(state);
|
|
_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(stockInRepositoryProvider).create(data);
|
|
reload();
|
|
}
|
|
|
|
Future<void> deleteOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).delete(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> submitOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).submit(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> approveOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).approve(id);
|
|
reload();
|
|
ref.invalidate(inventoryListProvider);
|
|
}
|
|
|
|
Future<void> rejectOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).reject(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> withdrawOrder(int id) async {
|
|
await ref.read(stockInRepositoryProvider).withdraw(id);
|
|
reload();
|
|
}
|
|
|
|
Future<void> returnItems(int id, List<int> itemIds) async {
|
|
await ref.read(stockInRepositoryProvider).returnItems(id, itemIds);
|
|
reload();
|
|
ref.invalidate(inventoryListProvider);
|
|
}
|
|
}
|