Files
jiu/client/lib/widgets/searchable_option_field.dart
T
wangjia c1ed81dfab 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>
2026-05-23 14:05:41 +08:00

192 lines
6.0 KiB
Dart

import '../core/utils/dialog_util.dart';
import 'package:flutter/material.dart';
import 'package:lpinyin/lpinyin.dart';
import '../core/theme/app_theme.dart';
class OptionItem {
final int id;
final String name;
final String? code;
// 拼音索引,构造时预计算
late final String _fullPinyin;
late final String _initials;
OptionItem({required this.id, required this.name, this.code}) {
_fullPinyin = PinyinHelper.getPinyinE(name, separator: '', defPinyin: '').toLowerCase();
_initials = PinyinHelper.getShortPinyin(name).toLowerCase();
}
bool matches(String kw) {
final k = kw.toLowerCase();
return name.toLowerCase().contains(k) ||
(_fullPinyin.isNotEmpty && _fullPinyin.contains(k)) ||
(_initials.isNotEmpty && _initials.contains(k)) ||
(code?.toLowerCase().contains(k) ?? false);
}
}
/// 点击后弹出搜索对话框的下拉选择框
class SearchableOptionField extends StatelessWidget {
final List<OptionItem> options;
final int? selectedId;
final String hint;
final String dialogTitle;
final ValueChanged<int?> onChanged;
final bool isRequired;
final bool isDense;
const SearchableOptionField({
super.key,
required this.options,
required this.selectedId,
required this.hint,
required this.dialogTitle,
required this.onChanged,
this.isRequired = false,
this.isDense = true,
});
String get _displayText {
if (selectedId == null) return '';
return options.where((o) => o.id == selectedId).firstOrNull?.name ?? '';
}
Future<void> _openDialog(BuildContext context) async {
final result = await showDialog<int?>(
context: context,
builder: (_) => _SearchDialog(
title: dialogTitle,
options: options,
selectedId: selectedId,
),
);
// result == -1 means "clear selection"
if (result == -1) {
onChanged(null);
} else if (result != null) {
onChanged(result);
}
}
@override
Widget build(BuildContext context) {
final selected = selectedId != null;
return FormField<int>(
initialValue: selectedId,
validator: isRequired ? (v) => (selectedId == null ? '请选择' : null) : null,
builder: (state) {
return InkWell(
onTap: () => _openDialog(context),
borderRadius: BorderRadius.circular(4),
child: InputDecorator(
decoration: InputDecoration(
isDense: isDense,
errorText: state.errorText,
suffixIcon: selected
? GestureDetector(
onTap: () => onChanged(null),
child: const Icon(Icons.close, size: 14, color: AppTheme.textSecondary),
)
: const Icon(Icons.arrow_drop_down, size: 16, color: AppTheme.textSecondary),
),
isEmpty: !selected,
child: Text(
selected ? _displayText : hint,
style: TextStyle(
fontSize: 12,
color: selected ? Colors.black87 : AppTheme.textSecondary,
),
overflow: TextOverflow.ellipsis,
),
),
);
},
);
}
}
class _SearchDialog extends StatefulWidget {
final String title;
final List<OptionItem> options;
final int? selectedId;
const _SearchDialog({required this.title, required this.options, this.selectedId});
@override
State<_SearchDialog> createState() => _SearchDialogState();
}
class _SearchDialogState extends State<_SearchDialog> {
final _ctrl = TextEditingController();
String _keyword = '';
@override
void dispose() {
_ctrl.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final filtered = _keyword.isEmpty
? widget.options
: widget.options.where((o) => o.matches(_keyword)).toList();
return AlertDialog(
title: Text(widget.title, style: const TextStyle(fontSize: 16)),
contentPadding: const EdgeInsets.fromLTRB(16, 12, 16, 0),
content: SizedBox(
width: 300,
height: 400,
child: Column(
children: [
TextField(
controller: _ctrl,
autofocus: true,
decoration: const InputDecoration(
hintText: '搜索...',
prefixIcon: Icon(Icons.search, size: 18),
isDense: true,
),
onChanged: (v) => setState(() => _keyword = v),
),
const SizedBox(height: 8),
Expanded(
child: filtered.isEmpty
? const Center(
child: Text('无匹配结果', style: TextStyle(color: AppTheme.textSecondary)))
: ListView.builder(
itemCount: filtered.length,
itemBuilder: (_, i) {
final opt = filtered[i];
final isSelected = opt.id == widget.selectedId;
return ListTile(
dense: true,
title: Text(opt.name, style: const TextStyle(fontSize: 13)),
subtitle: opt.code != null && opt.code!.isNotEmpty
? Text(opt.code!, style: const TextStyle(fontSize: 11))
: null,
selected: isSelected,
selectedTileColor: AppTheme.primary.withValues(alpha: 0.08),
onTap: () => Navigator.of(context).pop(opt.id),
);
},
),
),
],
),
),
actions: [
if (widget.selectedId != null)
TextButton(
onPressed: () => Navigator.of(context).pop(-1),
child: const Text('清除选择', style: TextStyle(color: AppTheme.textSecondary)),
),
TextButton(
onPressed: () => Navigator.of(context).pop(null),
child: const Text('取消'),
),
],
);
}
}