feat: 财务结清、酒行信息、库存备注编辑、标签溯源、入库必填校验

后端
- 新增 shop handler:GET/PUT /shop/info(管理员权限)
- 新增 finance CloseByRef:按单据 ref_type+ref_id 结清账款
- 新增 inventory UpdateRemark:PUT /inventory/:id/remark
- 入库/出库审批自动生成财务应付/应收记录(去除金额>0限制)
- 种子数据 S001-S003 补充真实门店信息

前端
- 设置页新增「酒行信息」Tab,管理员可编辑门店名称/地址/电话/负责人
- 入库单列表新增结清按钮(含确认弹窗),出库单同步
- 入库表单:规格、系列、生产日期、供应商、商品名称改为提交必填
- 入库/出库列表新增入库时间、出库时间、创建时间列
- 商品标签标题改为读取 shop 表门店名,扫码文案改为「扫码溯源 · TRACE」
- 标签页脚显示门店地址和电话(从 API 读取,不再依赖编译时 dart-define)
- 库存备注支持点击编辑,超4字截断显示+Hover展示全文
- ApiClient 新增 patch() 方法(已改用 PUT 规避 CORS)

文档
- 新增 docs/user-manual.md 完整用户操作手册(12章)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-05-23 14:05:41 +08:00
parent c77e1c1490
commit c1ed81dfab
60 changed files with 4664 additions and 1572 deletions
+328 -37
View File
@@ -1,3 +1,4 @@
import '../../core/utils/dialog_util.dart';
import 'package:dio/dio.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/foundation.dart';
@@ -18,6 +19,8 @@ import '../../providers/number_rule_provider.dart';
import '../../providers/update_provider.dart';
import '../../providers/user_provider.dart';
import '../../providers/warehouse_provider.dart';
import '../../providers/shop_provider.dart';
import '../../models/shop.dart';
class SettingsScreen extends ConsumerStatefulWidget {
const SettingsScreen({super.key});
@@ -39,7 +42,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 6,
length: 7,
child: Column(
children: [
Container(
@@ -53,6 +56,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
labelStyle:
TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
tabs: [
Tab(text: '酒行信息'),
Tab(text: '用户管理'),
Tab(text: '仓库管理'),
Tab(text: '编号规则'),
@@ -66,6 +70,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
Expanded(
child: TabBarView(
children: [
_buildShopInfoTab(),
_buildUsersTab(),
_buildWarehousesTab(),
_buildNumberRulesTab(),
@@ -80,6 +85,95 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
);
}
Widget _buildShopInfoTab() {
final asyncShop = ref.watch(shopInfoProvider);
final currentUser = ref.watch(authStateProvider).user;
final isAdmin =
currentUser?.role == 'admin' || currentUser?.role == 'superadmin';
return asyncShop.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.cloud_off, size: 40, color: AppTheme.textSecondary),
const SizedBox(height: 12),
const Text('暂无数据,网络不可用',
style: TextStyle(color: AppTheme.textSecondary)),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () => ref.invalidate(shopInfoProvider),
child: const Text('重试'),
),
],
),
),
data: (shop) => SingleChildScrollView(
padding: const EdgeInsets.all(24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('酒行信息',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
const SizedBox(height: 4),
const Text('门店的基本信息,仅管理员可编辑',
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary)),
const SizedBox(height: 16),
Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_ShopInfoRow(
label: '门店编号',
value: shop.code.isNotEmpty ? shop.code : ''),
const Divider(height: 16),
_ShopInfoRow(
label: '门店名称',
value: shop.name.isNotEmpty ? shop.name : ''),
const Divider(height: 16),
_ShopInfoRow(
label: '门店地址',
value: shop.address.isNotEmpty ? shop.address : ''),
const Divider(height: 16),
_ShopInfoRow(
label: '联系电话',
value: shop.phone.isNotEmpty ? shop.phone : ''),
const Divider(height: 16),
_ShopInfoRow(
label: '负责人',
value:
shop.managerName.isNotEmpty ? shop.managerName : ''),
],
),
),
),
if (isAdmin) ...[
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: () => _showEditShopDialog(context, shop),
icon: const Icon(Icons.edit_outlined, size: 16),
label: const Text('编辑信息'),
),
],
],
),
),
);
}
void _showEditShopDialog(BuildContext context, ShopInfo shop) {
showAppDialog(
context: context,
builder: (ctx) => _ShopEditDialog(
shop: shop,
onSaved: () => ref.invalidate(shopInfoProvider),
),
);
}
Widget _buildUsersTab() {
final asyncUsers = ref.watch(userListProvider);
return Column(
@@ -330,7 +424,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
}
void _showWarehouseDialog(BuildContext context, {Warehouse? warehouse}) {
showDialog(
showAppDialog(
context: context,
builder: (ctx) => _WarehouseFormDialog(
warehouse: warehouse,
@@ -432,7 +526,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
final prefixCtrl = TextEditingController(text: rule.prefix);
final currentNoCtrl =
TextEditingController(text: '${rule.currentNo}');
showDialog(
showAppDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text('编辑编号规则 — ${rule.typeLabel}'),
@@ -778,7 +872,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
}
void _showRenewDialog() {
showDialog(
showAppDialog(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('续费 / 升级授权'),
@@ -820,7 +914,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
void _showFeedbackDialog({required bool isBug}) {
final ctrl = TextEditingController();
showDialog(
showAppDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(isBug ? '反馈 Bug' : '功能建议'),
@@ -861,7 +955,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
void _showEditParamDialog(
String label, String current, ValueChanged<String> onSave) {
final ctrl = TextEditingController(text: current);
showDialog(
showAppDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text('修改$label'),
@@ -891,7 +985,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
}
void _showAddUserDialog(BuildContext context) {
showDialog(
showAppDialog(
context: context,
builder: (ctx) => _UserFormDialog(
onSaved: () => ref.read(userListProvider.notifier).reload(),
@@ -900,7 +994,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
}
void _showEditUserDialog(BuildContext context, AppUser user) {
showDialog(
showAppDialog(
context: context,
builder: (ctx) => _UserFormDialog(
user: user,
@@ -910,7 +1004,7 @@ class _SettingsScreenState extends ConsumerState<SettingsScreen> {
}
void _showResetPasswordDialog(BuildContext context, AppUser user) {
showDialog(
showAppDialog(
context: context,
builder: (ctx) => _ResetPasswordDialog(user: user),
);
@@ -1447,6 +1541,7 @@ class _BatchImportWidget extends ConsumerStatefulWidget {
class _BatchImportWidgetState extends ConsumerState<_BatchImportWidget> {
bool _loading = false;
String? _lastDir;
OverlayEntry? _importBarrier;
static const _prefKey = 'import_last_dir';
@@ -1459,6 +1554,8 @@ class _BatchImportWidgetState extends ConsumerState<_BatchImportWidget> {
'格式:选项编号 | 选项名称 | 备注'),
_ImportSlot('商品规格', '/import/product-specs',
'格式:选项编号 | 选项名称 | 单品数量 | 备注'),
_ImportSlot('商品编码', '/import/product-codes',
'格式:商品编码:xxxx'),
_ImportSlot('库存', '/import/inventory',
'格式:商品编号|商品名称|系列|规格|单位|库存数量|单价|金额|生产日期|批次|分类|所在仓库|入库日期|供应商|上次盘点|备注'),
];
@@ -1519,10 +1616,44 @@ class _BatchImportWidgetState extends ConsumerState<_BatchImportWidget> {
}
}
void _showBarrier() {
_importBarrier = OverlayEntry(
builder: (_) => Stack(children: [
const ModalBarrier(dismissible: false, color: Colors.transparent),
Positioned(
bottom: 24, left: 0, right: 0,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(8),
),
child: const Row(mainAxisSize: MainAxisSize.min, children: [
SizedBox(width: 14, height: 14,
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white)),
SizedBox(width: 10),
Text('导入中,请勿切换页面…',
style: TextStyle(color: Colors.white, fontSize: 13)),
]),
),
),
),
]),
);
Overlay.of(context, rootOverlay: true).insert(_importBarrier!);
}
void _removeBarrier() {
_importBarrier?.remove();
_importBarrier = null;
}
Future<void> _runImport() async {
final token = ref.read(authStateProvider).user?.accessToken ?? '';
if (!_slots.any((s) => s.file != null)) return;
_showBarrier();
setState(() {
_loading = true;
for (final s in _slots) {
@@ -1570,7 +1701,10 @@ class _BatchImportWidgetState extends ConsumerState<_BatchImportWidget> {
}
}
if (mounted) setState(() => _loading = false);
if (mounted) {
_removeBarrier();
setState(() => _loading = false);
}
}
@override
@@ -1920,39 +2054,196 @@ class _BatchImportWidgetState extends ConsumerState<_BatchImportWidget> {
}
return Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Row(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 68,
child: Text(slot.title,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
),
const SizedBox(width: 12),
OutlinedButton(
onPressed: _loading ? null : () => _pickFile(index),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
minimumSize: Size.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: const Text('选择文件', style: TextStyle(fontSize: 13)),
),
const SizedBox(width: 12),
Expanded(
child: Text(
slot.file?.name ?? '未选择',
style: TextStyle(
fontSize: 13,
color: slot.file != null ? AppTheme.textPrimary : AppTheme.textSecondary,
Row(
children: [
SizedBox(
width: 68,
child: Text(slot.title,
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
),
overflow: TextOverflow.ellipsis,
const SizedBox(width: 12),
OutlinedButton(
onPressed: _loading ? null : () => _pickFile(index),
style: OutlinedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
minimumSize: Size.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
child: const Text('选择文件', style: TextStyle(fontSize: 13)),
),
const SizedBox(width: 12),
Expanded(
child: Text(
slot.file?.name ?? '未选择',
style: TextStyle(
fontSize: 13,
color: slot.file != null ? AppTheme.textPrimary : AppTheme.textSecondary,
),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 12),
if (statusWidget != null) statusWidget,
],
),
const SizedBox(height: 3),
Padding(
padding: const EdgeInsets.only(left: 80),
child: Text(
slot.hint,
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary),
),
),
const SizedBox(width: 12),
if (statusWidget != null) statusWidget,
],
),
);
}
}
// ── 酒行信息行 ────────────────────────────────────────────
class _ShopInfoRow extends StatelessWidget {
final String label;
final String value;
const _ShopInfoRow({required this.label, required this.value});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
children: [
SizedBox(
width: 88,
child: Text(label,
style: const TextStyle(
fontSize: 14, color: AppTheme.textSecondary)),
),
Expanded(
child: Text(value,
style: const TextStyle(
fontSize: 14, fontWeight: FontWeight.w500)),
),
],
),
);
}
}
// ── 编辑酒行信息弹窗 ─────────────────────────────────────
class _ShopEditDialog extends ConsumerStatefulWidget {
final ShopInfo shop;
final VoidCallback onSaved;
const _ShopEditDialog({required this.shop, required this.onSaved});
@override
ConsumerState<_ShopEditDialog> createState() => _ShopEditDialogState();
}
class _ShopEditDialogState extends ConsumerState<_ShopEditDialog> {
late final TextEditingController _nameCtrl;
late final TextEditingController _addressCtrl;
late final TextEditingController _phoneCtrl;
late final TextEditingController _managerCtrl;
bool _saving = false;
@override
void initState() {
super.initState();
_nameCtrl = TextEditingController(text: widget.shop.name);
_addressCtrl = TextEditingController(text: widget.shop.address);
_phoneCtrl = TextEditingController(text: widget.shop.phone);
_managerCtrl = TextEditingController(text: widget.shop.managerName);
}
@override
void dispose() {
_nameCtrl.dispose();
_addressCtrl.dispose();
_phoneCtrl.dispose();
_managerCtrl.dispose();
super.dispose();
}
Future<void> _save() async {
setState(() => _saving = true);
try {
await ref.read(shopRepositoryProvider).updateInfo({
'name': _nameCtrl.text.trim(),
'address': _addressCtrl.text.trim(),
'phone': _phoneCtrl.text.trim(),
'manager_name': _managerCtrl.text.trim(),
});
if (mounted) {
Navigator.of(context).pop();
widget.onSaved();
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('信息已更新'),
backgroundColor: AppTheme.success,
));
}
} catch (e) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('保存失败:$e'),
backgroundColor: AppTheme.danger,
));
}
} finally {
if (mounted) setState(() => _saving = false);
}
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('编辑酒行信息'),
content: SizedBox(
width: 400,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _nameCtrl,
decoration: const InputDecoration(labelText: '门店名称'),
),
const SizedBox(height: 12),
TextField(
controller: _addressCtrl,
decoration: const InputDecoration(labelText: '门店地址'),
),
const SizedBox(height: 12),
TextField(
controller: _phoneCtrl,
decoration: const InputDecoration(labelText: '联系电话'),
),
const SizedBox(height: 12),
TextField(
controller: _managerCtrl,
decoration: const InputDecoration(labelText: '负责人'),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('取消'),
),
ElevatedButton(
onPressed: _saving ? null : _save,
child: _saving
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2, color: Colors.white))
: const Text('保存'),
),
],
);
}
}