122 lines
3.4 KiB
Dart
122 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
enum WorkOrderStatus { all, pending, processing, completed }
|
|
|
|
class WorkOrder {
|
|
final String id;
|
|
final String title;
|
|
final String description;
|
|
final WorkOrderStatus status;
|
|
final String creatorName;
|
|
final String? assigneeName;
|
|
final DateTime createdAt;
|
|
final DateTime? completedAt;
|
|
final String priority;
|
|
final String category;
|
|
final List<String> images;
|
|
final String? location;
|
|
|
|
const WorkOrder({
|
|
required this.id,
|
|
required this.title,
|
|
required this.description,
|
|
required this.status,
|
|
required this.creatorName,
|
|
this.assigneeName,
|
|
required this.createdAt,
|
|
this.completedAt,
|
|
required this.priority,
|
|
required this.category,
|
|
required this.images,
|
|
this.location,
|
|
});
|
|
|
|
String get statusText {
|
|
switch (status) {
|
|
case WorkOrderStatus.pending:
|
|
return '待接单';
|
|
case WorkOrderStatus.processing:
|
|
return '处理中';
|
|
case WorkOrderStatus.completed:
|
|
return '已完成';
|
|
default:
|
|
return '全部';
|
|
}
|
|
}
|
|
|
|
Color get statusColor {
|
|
switch (status) {
|
|
case WorkOrderStatus.pending:
|
|
return const Color(0xFFF59E0B);
|
|
case WorkOrderStatus.processing:
|
|
return const Color(0xFF3B82F6);
|
|
case WorkOrderStatus.completed:
|
|
return const Color(0xFF10B981);
|
|
default:
|
|
return const Color(0xFF64748B);
|
|
}
|
|
}
|
|
|
|
WorkOrder copyWith({
|
|
String? id,
|
|
String? title,
|
|
String? description,
|
|
WorkOrderStatus? status,
|
|
String? creatorName,
|
|
String? assigneeName,
|
|
DateTime? createdAt,
|
|
DateTime? completedAt,
|
|
String? priority,
|
|
String? category,
|
|
List<String>? images,
|
|
String? location,
|
|
}) {
|
|
return WorkOrder(
|
|
id: id ?? this.id,
|
|
title: title ?? this.title,
|
|
description: description ?? this.description,
|
|
status: status ?? this.status,
|
|
creatorName: creatorName ?? this.creatorName,
|
|
assigneeName: assigneeName ?? this.assigneeName,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
completedAt: completedAt ?? this.completedAt,
|
|
priority: priority ?? this.priority,
|
|
category: category ?? this.category,
|
|
images: images ?? this.images,
|
|
location: location ?? this.location,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'title': title,
|
|
'description': description,
|
|
'status': status.name,
|
|
'creatorName': creatorName,
|
|
'assigneeName': assigneeName,
|
|
'createdAt': createdAt.toIso8601String(),
|
|
'completedAt': completedAt?.toIso8601String(),
|
|
'priority': priority,
|
|
'category': category,
|
|
'images': images,
|
|
'location': location,
|
|
};
|
|
|
|
factory WorkOrder.fromJson(Map<String, dynamic> json) => WorkOrder(
|
|
id: json['id'] ?? '',
|
|
title: json['title'] ?? '',
|
|
description: json['description'] ?? '',
|
|
status: WorkOrderStatus.values.byName(json['status'] ?? 'pending'),
|
|
creatorName: json['creatorName'] ?? '',
|
|
assigneeName: json['assigneeName'],
|
|
createdAt: DateTime.tryParse(json['createdAt'] ?? '') ?? DateTime.now(),
|
|
completedAt: json['completedAt'] != null
|
|
? DateTime.tryParse(json['completedAt'])
|
|
: null,
|
|
priority: json['priority'] ?? 'normal',
|
|
category: json['category'] ?? '',
|
|
images: json['images'] != null ? List<String>.from(json['images']) : [],
|
|
location: json['location'],
|
|
);
|
|
}
|