Files
flutter-learn/lib/leave/leave_model.dart
T

72 lines
2.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class Leave {
final String billNo; // billno (Primary Key)
final DateTime? billDate; // billdate
final String personId; // personid
final String agentId; // agentid (代理人)
final String leaveType; // leavetype (假別:事假、病假等)
final DateTime? startTime; // starttime
final DateTime? endTime; // endtime
final double days; // days
final double hours; // hours
final String? leaveNote; // leave_note
final String? flowStatus; // flow_status (0:草稿, 1:審核中, 2:已核准, X:駁回)
Leave({
required this.billNo,
this.billDate,
required this.personId,
required this.agentId,
required this.leaveType,
this.startTime,
this.endTime,
this.days = 0,
this.hours = 0,
this.leaveNote,
this.flowStatus,
});
factory Leave.fromJson(Map<String, dynamic> json) {
return Leave(
billNo: json['billno'] as String? ?? '',
billDate: json['billdate'] != null ? DateTime.tryParse(json['billdate']) : null,
personId: json['personid'] as String? ?? '',
agentId: json['agentid'] as String? ?? '',
leaveType: json['leavetype'] as String? ?? '',
startTime: json['starttime'] != null ? DateTime.tryParse(json['starttime']) : null,
endTime: json['endtime'] != null ? DateTime.tryParse(json['endtime']) : null,
days: double.tryParse(json['days']?.toString() ?? '0') ?? 0,
hours: double.tryParse(json['hours']?.toString() ?? '0') ?? 0,
leaveNote: json['leave_note'] as String?,
flowStatus: json['flow_status'] as String?,
);
}
// 格式化顯示
String get formattedRange {
if (startTime == null || endTime == null) return '時間未定';
final df = DateFormat('yyyy/MM/dd HH:mm');
return '${df.format(startTime!)} ~ ${df.format(endTime!)}';
}
// 狀態顏色映射
Color get statusColor {
switch (flowStatus) {
case '1': return Colors.orange; // 審核中
case '2': return Colors.green; // 已核准
case 'X': return Colors.red; // 駁回
default: return Colors.grey; // 草稿
}
}
String get statusText {
switch (flowStatus) {
case '1': return '審核中';
case '2': return '已核准';
case 'X': return '已駁回';
default: return '草稿';
}
}
}