overtime_detail_page.dart 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import '../../core/theme/app_colors.dart';
  4. import '../../core/utils/date_utils.dart' as du;
  5. import '../../core/utils/responsive.dart';
  6. import '../../shared/widgets/form_section.dart';
  7. import '../../shared/widgets/form_field_row.dart';
  8. import '../../shared/widgets/status_tag.dart';
  9. import 'overtime_api.dart';
  10. import 'overtime_model.dart';
  11. final overtimeDetailProvider = FutureProvider.autoDispose.family<OvertimeModel, String>((ref, id) async {
  12. return ref.read(overtimeApiProvider).fetchDetail(id);
  13. });
  14. class OvertimeDetailPage extends ConsumerWidget {
  15. final String id;
  16. const OvertimeDetailPage({super.key, required this.id});
  17. @override
  18. Widget build(BuildContext context, WidgetRef ref) {
  19. final detailAsync = ref.watch(overtimeDetailProvider(id));
  20. final r = ResponsiveHelper.of(context);
  21. return Scaffold(
  22. appBar: AppBar(title: const Text('加班详情')),
  23. body: detailAsync.when(
  24. loading: () => const Center(child: CircularProgressIndicator()),
  25. error: (_, __) => const Center(child: Text('加载失败')),
  26. data: (o) => Center(
  27. child: ConstrainedBox(
  28. constraints: BoxConstraints(maxWidth: r.detailTwoColumns ? 700 : double.infinity),
  29. child: SingleChildScrollView(
  30. padding: const EdgeInsets.symmetric(vertical: 8),
  31. child: FormSection(
  32. title: '加班信息',
  33. children: [
  34. FormFieldRow(label: '申请单号', value: o.applicationNo, showArrow: false),
  35. FormFieldRow(label: '加班类型', value: o.otType, showArrow: false),
  36. FormFieldRow(label: '补偿方式', value: o.compensationType, showArrow: false),
  37. FormFieldRow(label: '开始时间', value: du.DateUtils.formatDateTime(o.startTime), showArrow: false),
  38. FormFieldRow(label: '结束时间', value: du.DateUtils.formatDateTime(o.endTime), showArrow: false),
  39. FormFieldRow(label: '预估工时', value: '${o.otHours.toStringAsFixed(1)}h', showArrow: false),
  40. FormFieldRow(label: '部门', value: o.deptName, showArrow: false),
  41. FormFieldRow(label: '申请人', value: o.applicantName, showArrow: false),
  42. FormFieldRow(label: '创建时间', value: du.DateUtils.formatDateTime(o.createTime), showArrow: false),
  43. Padding(
  44. padding: const EdgeInsets.fromLTRB(14, 0, 14, 12),
  45. child: Row(
  46. children: [
  47. const SizedBox(width: 72, child: Text('状态', style: TextStyle(color: AppColors.textSecondary, fontSize: 13))),
  48. StatusTag(status: o.status),
  49. ],
  50. ),
  51. ),
  52. FormFieldRow(label: '加班事由', value: o.reason.isEmpty ? '-' : o.reason, showArrow: false),
  53. ],
  54. ),
  55. ),
  56. ),
  57. ),
  58. ),
  59. );
  60. }
  61. }