vehicle_model.dart 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. import '../../shared/models/approval_status.dart';
  2. class VehicleModel {
  3. final String id;
  4. final String applicationNo;
  5. final String applicantId;
  6. final String applicantName;
  7. final String deptId;
  8. final String deptName;
  9. final String vehicleType;
  10. final String purpose;
  11. final DateTime startTime;
  12. final DateTime endTime;
  13. final String origin;
  14. final String destination;
  15. final int passengerCount;
  16. final String driver;
  17. final String licensePlate;
  18. final double estimatedMileage;
  19. final double estimatedCost;
  20. final String reason;
  21. final String status;
  22. final String currentApproverId;
  23. final List<String> approvalChain;
  24. final DateTime createTime;
  25. final DateTime updateTime;
  26. final List<ApprovalRecord> approvalRecords;
  27. const VehicleModel({
  28. required this.id,
  29. required this.applicationNo,
  30. required this.applicantId,
  31. required this.applicantName,
  32. required this.deptId,
  33. required this.deptName,
  34. this.vehicleType = '轿车',
  35. required this.purpose,
  36. required this.startTime,
  37. required this.endTime,
  38. required this.origin,
  39. required this.destination,
  40. this.passengerCount = 1,
  41. this.driver = '',
  42. this.licensePlate = '',
  43. this.estimatedMileage = 0.0,
  44. this.estimatedCost = 0.0,
  45. required this.reason,
  46. this.status = 'draft',
  47. this.currentApproverId = '',
  48. this.approvalChain = const [],
  49. required this.createTime,
  50. required this.updateTime,
  51. this.approvalRecords = const [],
  52. });
  53. factory VehicleModel.fromJson(Map<String, dynamic> json) {
  54. return VehicleModel(
  55. id: json['id'] as String,
  56. applicationNo: json['applicationNo'] as String? ?? '',
  57. applicantId: json['applicantId'] as String? ?? '',
  58. applicantName: json['applicantName'] as String? ?? '',
  59. deptId: json['deptId'] as String? ?? '',
  60. deptName: json['deptName'] as String? ?? '',
  61. vehicleType: json['vehicleType'] as String? ?? '轿车',
  62. purpose: json['purpose'] as String? ?? '',
  63. startTime: DateTime.parse(json['startTime'] as String),
  64. endTime: DateTime.parse(json['endTime'] as String),
  65. origin: json['origin'] as String? ?? '',
  66. destination: json['destination'] as String? ?? '',
  67. passengerCount: json['passengerCount'] as int? ?? 1,
  68. driver: json['driver'] as String? ?? '',
  69. licensePlate: json['licensePlate'] as String? ?? '',
  70. estimatedMileage:
  71. (json['estimatedMileage'] as num?)?.toDouble() ?? 0.0,
  72. estimatedCost: (json['estimatedCost'] as num?)?.toDouble() ?? 0.0,
  73. reason: json['reason'] as String? ?? '',
  74. status: json['status'] as String? ?? 'draft',
  75. currentApproverId: json['currentApproverId'] as String? ?? '',
  76. approvalChain:
  77. (json['approvalChain'] as List<dynamic>?)
  78. ?.map((e) => e as String)
  79. .toList() ??
  80. [],
  81. createTime: DateTime.parse(json['createTime'] as String),
  82. updateTime: DateTime.parse(json['updateTime'] as String),
  83. approvalRecords:
  84. (json['approvalRecords'] as List<dynamic>?)
  85. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  86. .toList() ??
  87. [],
  88. );
  89. }
  90. Map<String, dynamic> toJson() => {
  91. 'id': id,
  92. 'applicationNo': applicationNo,
  93. 'applicantId': applicantId,
  94. 'applicantName': applicantName,
  95. 'deptId': deptId,
  96. 'deptName': deptName,
  97. 'vehicleType': vehicleType,
  98. 'purpose': purpose,
  99. 'startTime': startTime.toIso8601String(),
  100. 'endTime': endTime.toIso8601String(),
  101. 'origin': origin,
  102. 'destination': destination,
  103. 'passengerCount': passengerCount,
  104. 'driver': driver,
  105. 'licensePlate': licensePlate,
  106. 'estimatedMileage': estimatedMileage,
  107. 'estimatedCost': estimatedCost,
  108. 'reason': reason,
  109. 'status': status,
  110. 'currentApproverId': currentApproverId,
  111. 'approvalChain': approvalChain,
  112. 'createTime': createTime.toIso8601String(),
  113. 'updateTime': updateTime.toIso8601String(),
  114. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  115. };
  116. VehicleModel copyWith({
  117. String? id,
  118. String? applicationNo,
  119. String? applicantId,
  120. String? applicantName,
  121. String? deptId,
  122. String? deptName,
  123. String? vehicleType,
  124. String? purpose,
  125. DateTime? startTime,
  126. DateTime? endTime,
  127. String? origin,
  128. String? destination,
  129. int? passengerCount,
  130. String? driver,
  131. String? licensePlate,
  132. double? estimatedMileage,
  133. double? estimatedCost,
  134. String? reason,
  135. String? status,
  136. String? currentApproverId,
  137. List<String>? approvalChain,
  138. DateTime? createTime,
  139. DateTime? updateTime,
  140. List<ApprovalRecord>? approvalRecords,
  141. }) {
  142. return VehicleModel(
  143. id: id ?? this.id,
  144. applicationNo: applicationNo ?? this.applicationNo,
  145. applicantId: applicantId ?? this.applicantId,
  146. applicantName: applicantName ?? this.applicantName,
  147. deptId: deptId ?? this.deptId,
  148. deptName: deptName ?? this.deptName,
  149. vehicleType: vehicleType ?? this.vehicleType,
  150. purpose: purpose ?? this.purpose,
  151. startTime: startTime ?? this.startTime,
  152. endTime: endTime ?? this.endTime,
  153. origin: origin ?? this.origin,
  154. destination: destination ?? this.destination,
  155. passengerCount: passengerCount ?? this.passengerCount,
  156. driver: driver ?? this.driver,
  157. licensePlate: licensePlate ?? this.licensePlate,
  158. estimatedMileage: estimatedMileage ?? this.estimatedMileage,
  159. estimatedCost: estimatedCost ?? this.estimatedCost,
  160. reason: reason ?? this.reason,
  161. status: status ?? this.status,
  162. currentApproverId: currentApproverId ?? this.currentApproverId,
  163. approvalChain: approvalChain ?? this.approvalChain,
  164. createTime: createTime ?? this.createTime,
  165. updateTime: updateTime ?? this.updateTime,
  166. approvalRecords: approvalRecords ?? this.approvalRecords,
  167. );
  168. }
  169. }