Files

50 lines
2.0 KiB
Dart
Raw Permalink Normal View History

// 功能描述:工单展示适配,状态动作只取服务端许可,不猜测派单和处理时间。
// 版本1.0.0。
import 'client_models.dart';
class ServiceTicket {
const ServiceTicket(this.record);
final ClientRecord record;
String get identity => record.identity;
String get number => text('ticket_no', record.title);
String get state => text('status_name', '状态待核实');
String get description => text('description', '暂无描述');
String get result => text('result');
String get address => text('address', '未填写地址');
List<Map<String, Object?>> get photos => (record.raw['photos'] as List? ?? [])
.whereType<Map<Object?, Object?>>()
.map((value) => Map<String, Object?>.from(value))
.where((value) => value['identity'] is String)
.toList();
String get fault =>
const {'valve': '阀门故障', 'alarm': '报警器故障', 'leak': '燃气泄漏', 'other': '其他问题'}[text(
'fault_type',
)] ??
category;
String get category =>
const {
'repair': '维修',
'installation': '安装',
'inspection': '安检',
'reinspection': '复检',
'customer_service': '客户服务',
}[text('category')] ??
'其他服务';
List<String> get actions =>
(record.raw['allowed_actions'] as List?)?.whereType<String>().toList() ?? [];
/// 返回可展示文字,空值采用调用方指定的占位。
String text(String key, [String fallback = '']) {
final value = record.raw[key];
return value is String && value.trim().isNotEmpty ? value : fallback;
}
/// 使用接口的真实时间转换到本地,缺失时不生成推测进度。
String time(String key) {
final value = DateTime.tryParse(text(key))?.toLocal();
if (value == null) return '未记录';
String pad(int n) => n.toString().padLeft(2, '0');
return '${value.year}-${pad(value.month)}-${pad(value.day)} ${pad(value.hour)}:${pad(value.minute)}';
}
}