| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- import 'package:flutter/material.dart';
-
- /// 巡检管理 Tab
- class InspectionTab extends StatelessWidget {
- const InspectionTab({super.key});
-
- @override
- Widget build(BuildContext context) {
- final theme = Theme.of(context);
-
- return DefaultTabController(
- length: 3,
- child: Column(
- children: [
- // ---------- 子 Tab ----------
- Material(
- color: theme.colorScheme.surface,
- child: TabBar(
- labelColor: theme.colorScheme.primary,
- unselectedLabelColor: Colors.grey,
- indicatorColor: theme.colorScheme.primary,
- tabs: const [
- Tab(text: '待执行', icon: Icon(Icons.pending_actions, size: 18)),
- Tab(text: '进行中', icon: Icon(Icons.play_circle, size: 18)),
- Tab(text: '已完成', icon: Icon(Icons.check_circle, size: 18)),
- ],
- ),
- ),
-
- // ---------- 内容 ----------
- Expanded(
- child: TabBarView(
- children: [
- _InspectionList(status: 'pending'),
- _InspectionList(status: 'ongoing'),
- _InspectionList(status: 'done'),
- ],
- ),
- ),
- ],
- ),
- );
- }
- }
-
- class _InspectionList extends StatelessWidget {
- final String status;
- const _InspectionList({required this.status});
-
- List<Map<String, dynamic>> get _mockData {
- switch (status) {
- case 'pending':
- return [
- {'id': 'XJ-2024-001', 'route': '城东片区巡检路线', 'date': '2024-06-14', 'points': 8, 'priority': '高'},
- {'id': 'XJ-2024-002', 'route': '城北加压站巡检', 'date': '2024-06-14', 'points': 4, 'priority': '中'},
- {'id': 'XJ-2024-003', 'route': '水厂设备日检', 'date': '2024-06-15', 'points': 12, 'priority': '高'},
- ];
- case 'ongoing':
- return [
- {'id': 'XJ-2024-004', 'route': '城西管网巡检', 'date': '2024-06-14', 'points': 6, 'progress': '3/6'},
- ];
- default:
- return [
- {'id': 'XJ-2024-005', 'route': '城南片区周检', 'date': '2024-06-13', 'points': 10, 'result': '正常'},
- {'id': 'XJ-2024-006', 'route': '水厂设备周检', 'date': '2024-06-13', 'points': 12, 'result': '发现1处隐患'},
- ];
- }
- }
-
- @override
- Widget build(BuildContext context) {
- final data = _mockData;
- if (data.isEmpty) {
- return const Center(child: Text('暂无数据', style: TextStyle(color: Colors.grey)));
- }
-
- return ListView.builder(
- padding: const EdgeInsets.all(12),
- itemCount: data.length,
- itemBuilder: (ctx, i) => _InspectionCard(item: data[i], status: status),
- );
- }
- }
-
- class _InspectionCard extends StatelessWidget {
- final Map<String, dynamic> item;
- final String status;
-
- const _InspectionCard({required this.item, required this.status});
-
- @override
- Widget build(BuildContext context) {
- return Card(
- margin: const EdgeInsets.only(bottom: 12),
- shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- children: [
- Expanded(
- child: Text(
- item['route'] as String,
- style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 15),
- ),
- ),
- if (status == 'pending' && item.containsKey('priority'))
- Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
- decoration: BoxDecoration(
- color: item['priority'] == '高' ? Colors.red.shade100 : Colors.orange.shade100,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Text(
- '${item['priority']}优先',
- style: TextStyle(
- fontSize: 11,
- color: item['priority'] == '高' ? Colors.red.shade800 : Colors.orange.shade800,
- ),
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- Row(
- children: [
- _InfoChip(icon: Icons.tag, text: item['id'] as String),
- const SizedBox(width: 8),
- _InfoChip(icon: Icons.calendar_today, text: item['date'] as String, size: 12),
- const SizedBox(width: 8),
- _InfoChip(icon: Icons.location_on, text: '${item['points']}个巡检点'),
- ],
- ),
- if (status == 'ongoing') ...[
- const SizedBox(height: 8),
- LinearProgressIndicator(
- value: 0.5,
- backgroundColor: Colors.grey.shade200,
- ),
- const SizedBox(height: 4),
- Text('进度: ${item['progress']}', style: const TextStyle(fontSize: 12, color: Colors.grey)),
- ],
- if (status == 'done') ...[
- const SizedBox(height: 8),
- Text('巡检结果: ${item['result']}', style: const TextStyle(fontSize: 13, color: Colors.green)),
- ],
- const SizedBox(height: 12),
- Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- if (status == 'pending')
- FilledButton.icon(
- onPressed: () {},
- icon: const Icon(Icons.play_arrow, size: 18),
- label: const Text('开始巡检'),
- ),
- if (status == 'ongoing')
- FilledButton.icon(
- onPressed: () {},
- icon: const Icon(Icons.continue, size: 18),
- label: const Text('继续'),
- ),
- if (status == 'done')
- OutlinedButton.icon(
- onPressed: () {},
- icon: const Icon(Icons.visibility, size: 18),
- label: const Text('查看详情'),
- ),
- ],
- ),
- ],
- ),
- ),
- );
- }
- }
-
- class _InfoChip extends StatelessWidget {
- final IconData icon;
- final String text;
- final double size;
-
- const _InfoChip({required this.icon, required this.text, this.size = 14});
-
- @override
- Widget build(BuildContext context) {
- return Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(icon, size: size, color: Colors.grey),
- const SizedBox(width: 2),
- Text(text, style: TextStyle(fontSize: 12, color: Colors.grey.shade700)),
- ],
- );
- }
- }
|