智慧水务管理系统 - 精河县供水工程综合管理平台

meter_reading_page.dart 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import 'package:flutter/material.dart';
  2. import '../models/meter_reading_model.dart';
  3. import 'bill_list_page.dart';
  4. /// 抄表页面(营收 Tab 入口,包含抄表列表和账单入口)
  5. class MeterReadingPage extends StatefulWidget {
  6. const MeterReadingPage({super.key});
  7. @override
  8. State<MeterReadingPage> createState() => _MeterReadingPageState();
  9. }
  10. class _MeterReadingPageState extends State<MeterReadingPage>
  11. with AutomaticKeepAliveClientMixin {
  12. List<MeterReadingModel> _readings = [];
  13. bool _isLoading = true;
  14. @override
  15. bool get wantKeepAlive => true;
  16. @override
  17. void initState() {
  18. super.initState();
  19. _loadData();
  20. }
  21. void _loadData() {
  22. Future.delayed(const Duration(milliseconds: 500), () {
  23. setState(() {
  24. _readings = _generateMockData();
  25. _isLoading = false;
  26. });
  27. });
  28. }
  29. List<MeterReadingModel> _generateMockData() {
  30. return [
  31. MeterReadingModel(
  32. id: '1', meterNo: 'WM-2024-001', userName: '张三',
  33. address: '城东街道12号', previousReading: 1250.5,
  34. status: 'pending', readingDate: DateTime.now(),
  35. ),
  36. MeterReadingModel(
  37. id: '2', meterNo: 'WM-2024-002', userName: '李四',
  38. address: '城西大道88号', previousReading: 3420.0,
  39. currentReading: 3456.0, status: 'completed',
  40. readingDate: DateTime.now().subtract(const Duration(days: 1)),
  41. reader: '王工',
  42. ),
  43. MeterReadingModel(
  44. id: '3', meterNo: 'WM-2024-003', userName: '王五',
  45. address: '南区花园5栋', previousReading: 890.0,
  46. status: 'pending', readingDate: DateTime.now(),
  47. ),
  48. MeterReadingModel(
  49. id: '4', meterNo: 'WM-2024-004', userName: '赵六',
  50. address: '北区商铺16号', previousReading: 5600.0,
  51. currentReading: 5780.0, status: 'completed',
  52. readingDate: DateTime.now().subtract(const Duration(days: 2)),
  53. reader: '李工',
  54. ),
  55. MeterReadingModel(
  56. id: '5', meterNo: 'WM-2024-005', userName: '孙七',
  57. address: '中心路28号', previousReading: 2100.0,
  58. status: 'abnormal', readingDate: DateTime.now(),
  59. remark: '水表损坏',
  60. ),
  61. ];
  62. }
  63. Color _getStatusColor(String status) {
  64. switch (status) {
  65. case 'pending': return Colors.orange;
  66. case 'completed': return Colors.green;
  67. case 'abnormal': return Colors.red;
  68. default: return Colors.grey;
  69. }
  70. }
  71. String _getStatusText(String status) {
  72. switch (status) {
  73. case 'pending': return '待抄表';
  74. case 'completed': return '已完成';
  75. case 'abnormal': return '异常';
  76. default: return status;
  77. }
  78. }
  79. void _showReadingDialog(MeterReadingModel reading) {
  80. final controller = TextEditingController();
  81. showDialog(
  82. context: context,
  83. builder: (ctx) => AlertDialog(
  84. title: Text('抄表 - ${reading.userName}'),
  85. content: Column(
  86. mainAxisSize: MainAxisSize.min,
  87. crossAxisAlignment: CrossAxisAlignment.start,
  88. children: [
  89. Text('表号: ${reading.meterNo}'),
  90. Text('上次读数: ${reading.previousReading}'),
  91. const SizedBox(height: 12),
  92. TextField(
  93. controller: controller,
  94. keyboardType: const TextInputType.numberWithOptions(decimal: true),
  95. decoration: const InputDecoration(
  96. labelText: '当前读数',
  97. hintText: '请输入当前水表读数',
  98. ),
  99. ),
  100. ],
  101. ),
  102. actions: [
  103. TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('取消')),
  104. ElevatedButton(
  105. onPressed: () {
  106. // TODO: 提交抄表数据
  107. Navigator.pop(ctx);
  108. ScaffoldMessenger.of(context).showSnackBar(
  109. const SnackBar(content: Text('抄表数据已提交')),
  110. );
  111. },
  112. child: const Text('提交'),
  113. ),
  114. ],
  115. ),
  116. );
  117. }
  118. @override
  119. Widget build(BuildContext context) {
  120. super.build(context);
  121. return Scaffold(
  122. appBar: AppBar(
  123. title: const Text('营收管理'),
  124. actions: [
  125. IconButton(
  126. icon: const Icon(Icons.receipt_long),
  127. tooltip: '账单列表',
  128. onPressed: () {
  129. Navigator.of(context).push(
  130. MaterialPageRoute(builder: (_) => const BillListPage()),
  131. );
  132. },
  133. ),
  134. ],
  135. ),
  136. body: _isLoading
  137. ? const Center(child: CircularProgressIndicator())
  138. : Column(
  139. crossAxisAlignment: CrossAxisAlignment.start,
  140. children: [
  141. // 统计卡片
  142. Padding(
  143. padding: const EdgeInsets.all(12),
  144. child: Row(
  145. children: [
  146. _buildStatCard('待抄表', '${_readings.where((r) => r.status == 'pending').length}', Colors.orange),
  147. const SizedBox(width: 8),
  148. _buildStatCard('已完成', '${_readings.where((r) => r.status == 'completed').length}', Colors.green),
  149. const SizedBox(width: 8),
  150. _buildStatCard('异常', '${_readings.where((r) => r.status == 'abnormal').length}', Colors.red),
  151. ],
  152. ),
  153. ),
  154. const Padding(
  155. padding: EdgeInsets.symmetric(horizontal: 12),
  156. child: Text('抄表任务', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
  157. ),
  158. // 抄表列表
  159. Expanded(
  160. child: ListView.builder(
  161. padding: const EdgeInsets.all(12),
  162. itemCount: _readings.length,
  163. itemBuilder: (context, index) {
  164. final reading = _readings[index];
  165. return Card(
  166. margin: const EdgeInsets.only(bottom: 8),
  167. child: ListTile(
  168. leading: CircleAvatar(
  169. backgroundColor: _getStatusColor(reading.status).withOpacity(0.1),
  170. child: Icon(
  171. Icons.speed,
  172. color: _getStatusColor(reading.status),
  173. ),
  174. ),
  175. title: Text(reading.userName),
  176. subtitle: Text('${reading.meterNo} · ${reading.address}'),
  177. trailing: Column(
  178. mainAxisAlignment: MainAxisAlignment.center,
  179. crossAxisAlignment: CrossAxisAlignment.end,
  180. children: [
  181. Text(
  182. _getStatusText(reading.status),
  183. style: TextStyle(
  184. fontSize: 12,
  185. color: _getStatusColor(reading.status),
  186. fontWeight: FontWeight.bold,
  187. ),
  188. ),
  189. if (reading.status == 'pending')
  190. TextButton(
  191. onPressed: () => _showReadingDialog(reading),
  192. style: TextButton.styleFrom(
  193. padding: EdgeInsets.zero,
  194. minimumSize: const Size(0, 0),
  195. tapTargetSize: MaterialTapTargetSize.shrinkWrap,
  196. ),
  197. child: const Text('抄表', style: TextStyle(fontSize: 12)),
  198. ),
  199. ],
  200. ),
  201. ),
  202. );
  203. },
  204. ),
  205. ),
  206. ],
  207. ),
  208. );
  209. }
  210. Widget _buildStatCard(String label, String count, Color color) {
  211. return Expanded(
  212. child: Card(
  213. child: Padding(
  214. padding: const EdgeInsets.all(12),
  215. child: Column(
  216. children: [
  217. Text(count, style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold, color: color)),
  218. const SizedBox(height: 4),
  219. Text(label, style: TextStyle(fontSize: 12, color: Colors.grey[600])),
  220. ],
  221. ),
  222. ),
  223. ),
  224. );
  225. }
  226. }