| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /// 巡检任务模型
- class PatrolTaskModel {
- final String id;
- final String taskName;
- final String taskCode;
- final String routeName;
- final String assignee;
- final String status; // pending, in_progress, completed, overdue
- final DateTime planDate;
- final int checkpointTotal;
- final int checkpointCompleted;
- final String? remark;
-
- PatrolTaskModel({
- required this.id,
- required this.taskName,
- required this.taskCode,
- required this.routeName,
- required this.assignee,
- required this.status,
- required this.planDate,
- required this.checkpointTotal,
- required this.checkpointCompleted,
- this.remark,
- });
-
- double get progress =>
- checkpointTotal > 0 ? checkpointCompleted / checkpointTotal : 0;
-
- factory PatrolTaskModel.fromJson(Map<String, dynamic> json) {
- return PatrolTaskModel(
- id: json['id']?.toString() ?? '',
- taskName: json['taskName'] ?? '',
- taskCode: json['taskCode'] ?? '',
- routeName: json['routeName'] ?? '',
- assignee: json['assignee'] ?? '',
- status: json['status'] ?? 'pending',
- planDate: DateTime.tryParse(json['planDate'] ?? '') ?? DateTime.now(),
- checkpointTotal: json['checkpointTotal'] ?? 0,
- checkpointCompleted: json['checkpointCompleted'] ?? 0,
- remark: json['remark'],
- );
- }
-
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'taskName': taskName,
- 'taskCode': taskCode,
- 'routeName': routeName,
- 'assignee': assignee,
- 'status': status,
- 'planDate': planDate.toIso8601String(),
- 'checkpointTotal': checkpointTotal,
- 'checkpointCompleted': checkpointCompleted,
- 'remark': remark,
- };
- }
- }
|