feat(ui): 强化药品删除下架功能,在卡片菜单、编辑弹窗及过期警告条提供全景删除入口

This commit is contained in:
shen
2026-10-28 00:32:04 -07:00
parent 5025e67ef1
commit 77d53a01f9
2 changed files with 72 additions and 9 deletions
+35 -5
View File
@@ -109,7 +109,10 @@ class _MedicineCabinetScreenState extends State<MedicineCabinetScreen> {
Future<void> _editMedicine(MedicineItem item) async {
final updatedItem = await showDialog<MedicineItem>(
context: context,
builder: (_) => MedicineEditDialog(initialItem: item),
builder: (_) => MedicineEditDialog(
initialItem: item,
onDelete: () => _deleteMedicine(item),
),
);
if (updatedItem != null) {
@@ -544,15 +547,31 @@ class _MedicineCabinetScreenState extends State<MedicineCabinetScreen> {
),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert, size: 20, color: Colors.grey),
tooltip: '更多操作',
onSelected: (val) {
if (val == 'edit') _editMedicine(item);
if (val == 'delete') _deleteMedicine(item);
},
itemBuilder: (ctx) => [
const PopupMenuItem(value: 'edit', child: Text('编辑药品')),
const PopupMenuItem(
value: 'edit',
child: Row(
children: [
Icon(Icons.edit_outlined, size: 18, color: Colors.black87),
SizedBox(width: 8),
Text('编辑药品'),
],
),
),
const PopupMenuItem(
value: 'delete',
child: Text('移出药箱', style: TextStyle(color: Colors.red)),
child: Row(
children: [
Icon(Icons.delete_outline, size: 18, color: Colors.red),
SizedBox(width: 8),
Text('删除药品', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)),
],
),
),
],
),
@@ -685,7 +704,7 @@ class _MedicineCabinetScreenState extends State<MedicineCabinetScreen> {
),
],
// 危险警告提醒条 (超期或过期)
// 危险警告提醒条 (超期或过期,带一键下架/清理按钮)
if (isDanger) ...[
const SizedBox(height: 8),
Container(
@@ -702,11 +721,22 @@ class _MedicineCabinetScreenState extends State<MedicineCabinetScreen> {
Expanded(
child: Text(
item.healthStatus == MedicineHealthStatus.overdueInUse
? '已超出开封后推荐使用期限,易滋生细菌/失效,建议丢弃更换。'
? '已超出开封推荐使用期限,易滋生细菌/失效。'
: '已超出出厂有效期,严禁继续使用!',
style: const TextStyle(color: Colors.red, fontSize: 11, fontWeight: FontWeight.w600),
),
),
TextButton.icon(
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
minimumSize: Size.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
foregroundColor: Colors.red,
),
onPressed: () => _deleteMedicine(item),
icon: const Icon(Icons.delete_outline, size: 14),
label: const Text('清理下架', style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold)),
),
],
),
),
+37 -4
View File
@@ -7,11 +7,13 @@ import '../services/medicine_parser_service.dart';
class MedicineEditDialog extends StatefulWidget {
final MedicineItem? initialItem;
final ScannedMedicineInfo? scannedInfo;
final VoidCallback? onDelete;
const MedicineEditDialog({
super.key,
this.initialItem,
this.scannedInfo,
this.onDelete,
});
@override
@@ -568,10 +570,41 @@ class _MedicineEditDialogState extends State<MedicineEditDialog> {
),
child: Row(
children: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消', style: TextStyle(color: Colors.grey)),
),
if (isEditing && widget.onDelete != null)
TextButton.icon(
style: TextButton.styleFrom(foregroundColor: Colors.red),
onPressed: () async {
final confirm = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('确认删除该药品?'),
content: Text('确定将【${widget.initialItem!.name}】移出药箱吗?该操作将多端同步生效。'),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: const Text('取消'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () => Navigator.pop(ctx, true),
child: const Text('确认删除', style: TextStyle(color: Colors.white)),
),
],
),
);
if (confirm == true && context.mounted) {
Navigator.pop(context);
widget.onDelete!();
}
},
icon: const Icon(Icons.delete_outline, size: 18),
label: const Text('删除药品'),
)
else
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('取消', style: TextStyle(color: Colors.grey)),
),
const Spacer(),
ElevatedButton.icon(
style: ElevatedButton.styleFrom(