- 照护提醒页:status 过滤(服务端白名单视图)、due_at ASC、逾期红标 双通道标识,四态齐备;创建表单(四类)+ 完成(completedAt 必带、 支持补记)/ 忽略(禁带 completedAt)流转,42202/40902 兜底重拉 - 档案页:「健康提醒」卡改真实待办数据驱动(取代 demo 硬编码文案, 最近到期一条 + 逾期警示形态),照护提醒导航入口带待办数副行 - 疫苗列表(25 号报告遗留①②):scheduled 行「标记完成/取消登记」 PATCH 流转;完成对话框补录厂商/批号(契约可选字段); 42201/40902/40402 兜底 - 埋点:create 三事件 + viewed(recordType=reminder)挂通; edit_succeeded/failed 挂 vaccine 流转(failureReason 含 conflict); 提醒完成/忽略按 06 §7 缺口 3 既定取舍不埋 - 测试 250 → 272 全绿(+22,较基线 +48);analyze 0 问题;format 无 diff Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,12 +3,14 @@ import 'package:patbond_flutter/analytics/analytics_page_name.dart';
|
||||
import 'package:patbond_flutter/core/navigation/fade_route.dart';
|
||||
import 'package:patbond_flutter/core/network/api_exception.dart';
|
||||
import 'package:patbond_flutter/core/theme/app_theme.dart';
|
||||
import 'package:patbond_flutter/core/widgets/app_text_field.dart';
|
||||
import 'package:patbond_flutter/core/widgets/empty_state_illustration.dart';
|
||||
import 'package:patbond_flutter/core/widgets/inline_error_banner.dart';
|
||||
import 'package:patbond_flutter/core/widgets/record_type_dot.dart';
|
||||
import 'package:patbond_flutter/features/pets/health_record_analytics.dart';
|
||||
import 'package:patbond_flutter/features/pets/health_record_display.dart';
|
||||
import 'package:patbond_flutter/features/pets/pet_display.dart';
|
||||
import 'package:patbond_flutter/features/pets/pet_exceptions.dart';
|
||||
import 'package:patbond_flutter/features/pets/pet_models.dart';
|
||||
import 'package:patbond_flutter/features/pets/pets_repository.dart';
|
||||
import 'package:patbond_flutter/features/pets/vaccination_form_page.dart';
|
||||
@@ -21,6 +23,10 @@ enum _ListPhase { loading, ready, error }
|
||||
/// 含 cancelled 行原样展示(取消后同剂次可重新登记的事实留痕)。
|
||||
/// 四态齐备;登记经 [VaccinationFormPage]。
|
||||
///
|
||||
/// T2-14 收尾(25 号报告 §7 遗留①②):scheduled 行支持「标记完成 /
|
||||
/// 取消登记」PATCH 流转;完成时可补录厂商/批号(契约可选字段);
|
||||
/// 挂 `health_record_edit_succeeded/failed`(recordType=vaccine)。
|
||||
///
|
||||
/// 曝光埋点:每次进入首个成功加载上报一次
|
||||
/// `health_record_viewed(recordType=vaccine, source=pet_detail)`。
|
||||
class VaccinationRecordsPage extends StatefulWidget {
|
||||
@@ -53,6 +59,7 @@ class _VaccinationRecordsPageState extends State<VaccinationRecordsPage> {
|
||||
List<Vaccination> _records = const [];
|
||||
ApiException? _error;
|
||||
bool _viewedFired = false;
|
||||
bool _mutating = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -109,6 +116,124 @@ class _VaccinationRecordsPageState extends State<VaccinationRecordsPage> {
|
||||
}
|
||||
}
|
||||
|
||||
void _trackEditFailed(HealthRecordFailureReason reason, [int? errorCode]) {
|
||||
widget.analytics?.editFailed(
|
||||
recordType: HealthRecordType.vaccine,
|
||||
reason: reason,
|
||||
errorCode: errorCode,
|
||||
);
|
||||
}
|
||||
|
||||
/// 标记完成(25 号报告遗留①②):接种日期必填、下次接种/厂商/批号可选
|
||||
/// (厂商/批号为契约可选字段的补录入口)。
|
||||
Future<void> _markCompleted(Vaccination record) async {
|
||||
final result = await showDialog<_CompleteVaccinationResult>(
|
||||
context: context,
|
||||
builder: (context) => _CompleteVaccinationDialog(record: record),
|
||||
);
|
||||
if (result == null || !mounted) return;
|
||||
await _mutate(
|
||||
record,
|
||||
UpdateVaccinationRequest(
|
||||
version: record.version,
|
||||
status: VaccinationStatus.completed,
|
||||
administeredOn: result.administeredOn,
|
||||
nextDueOn: result.nextDueOn,
|
||||
manufacturer: result.manufacturer,
|
||||
batchNo: result.batchNo,
|
||||
),
|
||||
successText: '已标记完成',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _cancelRegistration(Vaccination record) async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('取消这条登记?'),
|
||||
content: Text(
|
||||
'「${vaccinationDoseLabel(record)}」将标记为已取消;'
|
||||
'取消后同系列同剂次可重新登记。',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('返回'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('取消登记'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (confirmed != true || !mounted) return;
|
||||
await _mutate(
|
||||
record,
|
||||
UpdateVaccinationRequest(
|
||||
version: record.version,
|
||||
status: VaccinationStatus.cancelled,
|
||||
),
|
||||
successText: '已取消登记',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _mutate(
|
||||
Vaccination record,
|
||||
UpdateVaccinationRequest request, {
|
||||
required String successText,
|
||||
}) async {
|
||||
if (_mutating) return;
|
||||
setState(() => _mutating = true);
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
await widget.repository.updateVaccination(record.id, request);
|
||||
widget.analytics?.editSucceeded(
|
||||
recordType: HealthRecordType.vaccine,
|
||||
fieldCount: request.toJson().length - 1,
|
||||
);
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(SnackBar(content: Text(successText)));
|
||||
await _load();
|
||||
} on PetVersionConflictException {
|
||||
if (!mounted) return;
|
||||
// 40902:并发修改抢先——刷新取新 version 后由用户重试动作。
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('记录已在其他设备被修改,已刷新,请重试')),
|
||||
);
|
||||
_trackEditFailed(HealthRecordFailureReason.conflict, 40902);
|
||||
await _load();
|
||||
} on VaccinationRuleException {
|
||||
if (!mounted) return;
|
||||
// 42201:状态机/状态-日期规则兜底(前端已按规则拦截主路径)。
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('接种状态与日期不符合规则,请核对后重试')),
|
||||
);
|
||||
_trackEditFailed(HealthRecordFailureReason.validationError, 42201);
|
||||
} on PetRecordNotFoundException {
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(const SnackBar(content: Text('记录不存在或已被删除,已刷新')));
|
||||
_trackEditFailed(HealthRecordFailureReason.notFound, 40402);
|
||||
await _load();
|
||||
} on PetAccessDeniedException {
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(const SnackBar(content: Text('你没有权限操作该记录')));
|
||||
_trackEditFailed(HealthRecordFailureReason.permissionDenied, 40300);
|
||||
} on ApiBusinessException catch (error) {
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(const SnackBar(content: Text('操作失败,请稍后重试')));
|
||||
_trackEditFailed(HealthRecordFailureReason.serverError, error.code);
|
||||
} on ApiNetworkException {
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(const SnackBar(content: Text('网络异常,请检查网络后重试')));
|
||||
_trackEditFailed(HealthRecordFailureReason.networkError);
|
||||
} on SessionExpiredException {
|
||||
// 会话失效:认证状态机自动回登录页。
|
||||
} finally {
|
||||
if (mounted) setState(() => _mutating = false);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -187,7 +312,24 @@ class _VaccinationRecordsPageState extends State<VaccinationRecordsPage> {
|
||||
);
|
||||
}
|
||||
children
|
||||
..add(_VaccinationTile(record: record))
|
||||
..add(
|
||||
_VaccinationTile(
|
||||
record: record,
|
||||
// 流转动作仅 scheduled 行可用(终态由服务端状态机守卫)。
|
||||
onComplete:
|
||||
widget.canWrite &&
|
||||
record.status == VaccinationStatus.scheduled &&
|
||||
!_mutating
|
||||
? () => _markCompleted(record)
|
||||
: null,
|
||||
onCancel:
|
||||
widget.canWrite &&
|
||||
record.status == VaccinationStatus.scheduled &&
|
||||
!_mutating
|
||||
? () => _cancelRegistration(record)
|
||||
: null,
|
||||
),
|
||||
)
|
||||
..add(const SizedBox(height: 10));
|
||||
}
|
||||
return RefreshIndicator(
|
||||
@@ -201,53 +343,252 @@ class _VaccinationRecordsPageState extends State<VaccinationRecordsPage> {
|
||||
}
|
||||
|
||||
/// 疫苗条目:RecordTypeDot(疫苗) + 剂次标题 + 日期副行 + 状态 TagPill
|
||||
/// (图标+文字双通道,不单靠颜色区分)。
|
||||
/// (图标+文字双通道,不单靠颜色区分);scheduled 行附
|
||||
/// 「标记完成 / 取消登记」流转动作。
|
||||
class _VaccinationTile extends StatelessWidget {
|
||||
const _VaccinationTile({required this.record});
|
||||
const _VaccinationTile({
|
||||
required this.record,
|
||||
this.onComplete,
|
||||
this.onCancel,
|
||||
});
|
||||
|
||||
final Vaccination record;
|
||||
final VoidCallback? onComplete;
|
||||
final VoidCallback? onCancel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Row(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const RecordTypeDot(
|
||||
type: RecordType.vaccine,
|
||||
size: RecordTypeDotSize.md,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
vaccinationDoseLabel(record),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
Row(
|
||||
children: [
|
||||
const RecordTypeDot(
|
||||
type: RecordType.vaccine,
|
||||
size: RecordTypeDotSize.md,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
vaccinationDoseLabel(record),
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
vaccinationDateLine(record),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.inkSoft,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
vaccinationDateLine(record),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
color: AppColors.inkSoft,
|
||||
fontSize: 12,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TagPill(
|
||||
vaccinationStatusLabel(record.status),
|
||||
color: vaccinationStatusColor(record.status),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (onComplete != null || onCancel != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton.icon(
|
||||
onPressed: onCancel,
|
||||
icon: const Icon(Icons.close, size: 16),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.inkSoft,
|
||||
),
|
||||
label: const Text('取消登记'),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
TextButton.icon(
|
||||
onPressed: onComplete,
|
||||
icon: const Icon(Icons.check_circle_outline, size: 16),
|
||||
label: const Text('标记完成'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
TagPill(
|
||||
vaccinationStatusLabel(record.status),
|
||||
color: vaccinationStatusColor(record.status),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 标记完成对话框返回值。
|
||||
class _CompleteVaccinationResult {
|
||||
const _CompleteVaccinationResult({
|
||||
required this.administeredOn,
|
||||
this.nextDueOn,
|
||||
this.manufacturer,
|
||||
this.batchNo,
|
||||
});
|
||||
|
||||
final DateTime administeredOn;
|
||||
final DateTime? nextDueOn;
|
||||
final String? manufacturer;
|
||||
final String? batchNo;
|
||||
}
|
||||
|
||||
/// 标记完成对话框:接种日期必填(默认今天)、下次接种可选;
|
||||
/// 厂商/批号补录(契约可选字段,25 号报告遗留②的落地入口)。
|
||||
/// 日期规则复用 [vaccinationDateRuleError](42201 前置拦截)。
|
||||
class _CompleteVaccinationDialog extends StatefulWidget {
|
||||
const _CompleteVaccinationDialog({required this.record});
|
||||
|
||||
final Vaccination record;
|
||||
|
||||
@override
|
||||
State<_CompleteVaccinationDialog> createState() =>
|
||||
_CompleteVaccinationDialogState();
|
||||
}
|
||||
|
||||
class _CompleteVaccinationDialogState
|
||||
extends State<_CompleteVaccinationDialog> {
|
||||
final _manufacturerCtrl = TextEditingController();
|
||||
final _batchNoCtrl = TextEditingController();
|
||||
DateTime _administeredOn = DateTime.now();
|
||||
DateTime? _nextDueOn;
|
||||
String? _dateError;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_manufacturerCtrl.text = widget.record.manufacturer ?? '';
|
||||
_batchNoCtrl.text = widget.record.batchNo ?? '';
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_manufacturerCtrl.dispose();
|
||||
_batchNoCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _confirm() {
|
||||
final error = vaccinationDateRuleError(
|
||||
status: VaccinationStatus.completed,
|
||||
administeredOn: _administeredOn,
|
||||
nextDueOn: _nextDueOn,
|
||||
);
|
||||
if (error != null) {
|
||||
setState(() => _dateError = error);
|
||||
return;
|
||||
}
|
||||
final manufacturer = _manufacturerCtrl.text.trim();
|
||||
final batchNo = _batchNoCtrl.text.trim();
|
||||
Navigator.of(context).pop(
|
||||
_CompleteVaccinationResult(
|
||||
administeredOn: _administeredOn,
|
||||
nextDueOn: _nextDueOn,
|
||||
manufacturer: manufacturer.isEmpty ? null : manufacturer,
|
||||
batchNo: batchNo.isEmpty ? null : batchNo,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _dateTile({
|
||||
required String label,
|
||||
required DateTime? value,
|
||||
required bool allowFuture,
|
||||
required ValueChanged<DateTime> onPicked,
|
||||
}) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: const Icon(Icons.event_outlined, color: AppColors.muted),
|
||||
title: Text(label, style: const TextStyle(fontSize: 14)),
|
||||
subtitle: Text(
|
||||
value == null ? '未选择' : dateToJson(value),
|
||||
style: const TextStyle(color: AppColors.inkSoft, fontSize: 12),
|
||||
),
|
||||
onTap: () async {
|
||||
final now = DateTime.now();
|
||||
final picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: value ?? now,
|
||||
firstDate: DateTime(1990),
|
||||
lastDate: allowFuture ? DateTime(now.year + 5) : now,
|
||||
);
|
||||
if (picked != null && mounted) {
|
||||
setState(() {
|
||||
onPicked(picked);
|
||||
_dateError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('标记完成'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'「${vaccinationDoseLabel(widget.record)}」',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_dateTile(
|
||||
label: '接种日期',
|
||||
value: _administeredOn,
|
||||
allowFuture: false,
|
||||
onPicked: (value) => _administeredOn = value,
|
||||
),
|
||||
_dateTile(
|
||||
label: '下次接种日期(可选)',
|
||||
value: _nextDueOn,
|
||||
allowFuture: true,
|
||||
onPicked: (value) => _nextDueOn = value,
|
||||
),
|
||||
if (_dateError != null) ...[
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
_dateError!,
|
||||
style: const TextStyle(color: AppColors.error, fontSize: 12),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 12),
|
||||
AppTextField(
|
||||
label: '厂商(可选)',
|
||||
controller: _manufacturerCtrl,
|
||||
textInputAction: TextInputAction.next,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
AppTextField(
|
||||
label: '批号(可选)',
|
||||
controller: _batchNoCtrl,
|
||||
textInputAction: TextInputAction.done,
|
||||
onSubmitted: (_) => _confirm(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
FilledButton(onPressed: _confirm, child: const Text('确认完成')),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user