vehicle_model.dart 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 double actualMileage;
  27. final double actualCost;
  28. final double startOdometer;
  29. final double endOdometer;
  30. final DateTime? returnTime;
  31. final List<String> passengers;
  32. final List<ApprovalRecord> approvalRecords;
  33. const VehicleModel({
  34. required this.id,
  35. required this.applicationNo,
  36. required this.applicantId,
  37. required this.applicantName,
  38. required this.deptId,
  39. required this.deptName,
  40. this.vehicleType = '轿车',
  41. required this.purpose,
  42. required this.startTime,
  43. required this.endTime,
  44. required this.origin,
  45. required this.destination,
  46. this.passengerCount = 1,
  47. this.driver = '',
  48. this.licensePlate = '',
  49. this.estimatedMileage = 0.0,
  50. this.estimatedCost = 0.0,
  51. required this.reason,
  52. this.status = 'draft',
  53. this.currentApproverId = '',
  54. this.approvalChain = const [],
  55. required this.createTime,
  56. required this.updateTime,
  57. this.actualMileage = 0.0,
  58. this.actualCost = 0.0,
  59. this.startOdometer = 0.0,
  60. this.endOdometer = 0.0,
  61. this.returnTime,
  62. this.passengers = const [],
  63. this.approvalRecords = const [],
  64. });
  65. factory VehicleModel.fromJson(Map<String, dynamic> json) {
  66. return VehicleModel(
  67. id: json['id'] as String,
  68. applicationNo: json['applicationNo'] as String? ?? '',
  69. applicantId: json['applicantId'] as String? ?? '',
  70. applicantName: json['applicantName'] as String? ?? '',
  71. deptId: json['deptId'] as String? ?? '',
  72. deptName: json['deptName'] as String? ?? '',
  73. vehicleType: json['vehicleType'] as String? ?? '轿车',
  74. purpose: json['purpose'] as String? ?? '',
  75. startTime: DateTime.parse(json['startTime'] as String),
  76. endTime: DateTime.parse(json['endTime'] as String),
  77. origin: json['origin'] as String? ?? '',
  78. destination: json['destination'] as String? ?? '',
  79. passengerCount: json['passengerCount'] as int? ?? 1,
  80. driver: json['driver'] as String? ?? '',
  81. licensePlate: json['licensePlate'] as String? ?? '',
  82. estimatedMileage:
  83. (json['estimatedMileage'] as num?)?.toDouble() ?? 0.0,
  84. estimatedCost: (json['estimatedCost'] as num?)?.toDouble() ?? 0.0,
  85. reason: json['reason'] as String? ?? '',
  86. status: json['status'] as String? ?? 'draft',
  87. currentApproverId: json['currentApproverId'] as String? ?? '',
  88. approvalChain:
  89. (json['approvalChain'] as List<dynamic>?)
  90. ?.map((e) => e as String)
  91. .toList() ??
  92. [],
  93. createTime: DateTime.parse(json['createTime'] as String),
  94. updateTime: DateTime.parse(json['updateTime'] as String),
  95. actualMileage: (json['actualMileage'] as num?)?.toDouble() ?? 0.0,
  96. actualCost: (json['actualCost'] as num?)?.toDouble() ?? 0.0,
  97. startOdometer: (json['startOdometer'] as num?)?.toDouble() ?? 0.0,
  98. endOdometer: (json['endOdometer'] as num?)?.toDouble() ?? 0.0,
  99. returnTime: json['returnTime'] != null
  100. ? DateTime.parse(json['returnTime'] as String) : null,
  101. passengers: (json['passengers'] as List<dynamic>?)
  102. ?.map((e) => e as String).toList() ?? [],
  103. approvalRecords:
  104. (json['approvalRecords'] as List<dynamic>?)
  105. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  106. .toList() ??
  107. [],
  108. );
  109. }
  110. Map<String, dynamic> toJson() => {
  111. 'id': id,
  112. 'applicationNo': applicationNo,
  113. 'applicantId': applicantId,
  114. 'applicantName': applicantName,
  115. 'deptId': deptId,
  116. 'deptName': deptName,
  117. 'vehicleType': vehicleType,
  118. 'purpose': purpose,
  119. 'startTime': startTime.toIso8601String(),
  120. 'endTime': endTime.toIso8601String(),
  121. 'origin': origin,
  122. 'destination': destination,
  123. 'passengerCount': passengerCount,
  124. 'driver': driver,
  125. 'licensePlate': licensePlate,
  126. 'estimatedMileage': estimatedMileage,
  127. 'estimatedCost': estimatedCost,
  128. 'reason': reason,
  129. 'status': status,
  130. 'currentApproverId': currentApproverId,
  131. 'approvalChain': approvalChain,
  132. 'createTime': createTime.toIso8601String(),
  133. 'updateTime': updateTime.toIso8601String(),
  134. 'actualMileage': actualMileage,
  135. 'actualCost': actualCost,
  136. 'startOdometer': startOdometer,
  137. 'endOdometer': endOdometer,
  138. 'returnTime': returnTime?.toIso8601String(),
  139. 'passengers': passengers,
  140. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  141. };
  142. VehicleModel copyWith({
  143. String? id,
  144. String? applicationNo,
  145. String? applicantId,
  146. String? applicantName,
  147. String? deptId,
  148. String? deptName,
  149. String? vehicleType,
  150. String? purpose,
  151. DateTime? startTime,
  152. DateTime? endTime,
  153. String? origin,
  154. String? destination,
  155. int? passengerCount,
  156. String? driver,
  157. String? licensePlate,
  158. double? estimatedMileage,
  159. double? estimatedCost,
  160. String? reason,
  161. String? status,
  162. String? currentApproverId,
  163. List<String>? approvalChain,
  164. DateTime? createTime,
  165. DateTime? updateTime,
  166. double? actualMileage,
  167. double? actualCost,
  168. double? startOdometer,
  169. double? endOdometer,
  170. DateTime? returnTime,
  171. List<String>? passengers,
  172. List<ApprovalRecord>? approvalRecords,
  173. }) {
  174. return VehicleModel(
  175. id: id ?? this.id,
  176. applicationNo: applicationNo ?? this.applicationNo,
  177. applicantId: applicantId ?? this.applicantId,
  178. applicantName: applicantName ?? this.applicantName,
  179. deptId: deptId ?? this.deptId,
  180. deptName: deptName ?? this.deptName,
  181. vehicleType: vehicleType ?? this.vehicleType,
  182. purpose: purpose ?? this.purpose,
  183. startTime: startTime ?? this.startTime,
  184. endTime: endTime ?? this.endTime,
  185. origin: origin ?? this.origin,
  186. destination: destination ?? this.destination,
  187. passengerCount: passengerCount ?? this.passengerCount,
  188. driver: driver ?? this.driver,
  189. licensePlate: licensePlate ?? this.licensePlate,
  190. estimatedMileage: estimatedMileage ?? this.estimatedMileage,
  191. estimatedCost: estimatedCost ?? this.estimatedCost,
  192. reason: reason ?? this.reason,
  193. status: status ?? this.status,
  194. currentApproverId: currentApproverId ?? this.currentApproverId,
  195. approvalChain: approvalChain ?? this.approvalChain,
  196. createTime: createTime ?? this.createTime,
  197. updateTime: updateTime ?? this.updateTime,
  198. actualMileage: actualMileage ?? this.actualMileage,
  199. actualCost: actualCost ?? this.actualCost,
  200. startOdometer: startOdometer ?? this.startOdometer,
  201. endOdometer: endOdometer ?? this.endOdometer,
  202. returnTime: returnTime ?? this.returnTime,
  203. passengers: passengers ?? this.passengers,
  204. approvalRecords: approvalRecords ?? this.approvalRecords,
  205. );
  206. }
  207. }