vehicle_model.dart 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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: (json['estimatedMileage'] as num?)?.toDouble() ?? 0.0,
  83. estimatedCost: (json['estimatedCost'] as num?)?.toDouble() ?? 0.0,
  84. reason: json['reason'] as String? ?? '',
  85. status: json['status'] as String? ?? 'draft',
  86. currentApproverId: json['currentApproverId'] as String? ?? '',
  87. approvalChain:
  88. (json['approvalChain'] as List<dynamic>?)
  89. ?.map((e) => e as String)
  90. .toList() ??
  91. [],
  92. createTime: DateTime.parse(json['createTime'] as String),
  93. updateTime: DateTime.parse(json['updateTime'] as String),
  94. actualMileage: (json['actualMileage'] as num?)?.toDouble() ?? 0.0,
  95. actualCost: (json['actualCost'] as num?)?.toDouble() ?? 0.0,
  96. startOdometer: (json['startOdometer'] as num?)?.toDouble() ?? 0.0,
  97. endOdometer: (json['endOdometer'] as num?)?.toDouble() ?? 0.0,
  98. returnTime: json['returnTime'] != null
  99. ? DateTime.parse(json['returnTime'] as String)
  100. : null,
  101. passengers:
  102. (json['passengers'] as List<dynamic>?)
  103. ?.map((e) => e as String)
  104. .toList() ??
  105. [],
  106. approvalRecords:
  107. (json['approvalRecords'] as List<dynamic>?)
  108. ?.map((e) => ApprovalRecord.fromJson(e as Map<String, dynamic>))
  109. .toList() ??
  110. [],
  111. );
  112. }
  113. Map<String, dynamic> toJson() => {
  114. 'id': id,
  115. 'applicationNo': applicationNo,
  116. 'applicantId': applicantId,
  117. 'applicantName': applicantName,
  118. 'deptId': deptId,
  119. 'deptName': deptName,
  120. 'vehicleType': vehicleType,
  121. 'purpose': purpose,
  122. 'startTime': startTime.toIso8601String(),
  123. 'endTime': endTime.toIso8601String(),
  124. 'origin': origin,
  125. 'destination': destination,
  126. 'passengerCount': passengerCount,
  127. 'driver': driver,
  128. 'licensePlate': licensePlate,
  129. 'estimatedMileage': estimatedMileage,
  130. 'estimatedCost': estimatedCost,
  131. 'reason': reason,
  132. 'status': status,
  133. 'currentApproverId': currentApproverId,
  134. 'approvalChain': approvalChain,
  135. 'createTime': createTime.toIso8601String(),
  136. 'updateTime': updateTime.toIso8601String(),
  137. 'actualMileage': actualMileage,
  138. 'actualCost': actualCost,
  139. 'startOdometer': startOdometer,
  140. 'endOdometer': endOdometer,
  141. 'returnTime': returnTime?.toIso8601String(),
  142. 'passengers': passengers,
  143. 'approvalRecords': approvalRecords.map((r) => r.toJson()).toList(),
  144. };
  145. VehicleModel copyWith({
  146. String? id,
  147. String? applicationNo,
  148. String? applicantId,
  149. String? applicantName,
  150. String? deptId,
  151. String? deptName,
  152. String? vehicleType,
  153. String? purpose,
  154. DateTime? startTime,
  155. DateTime? endTime,
  156. String? origin,
  157. String? destination,
  158. int? passengerCount,
  159. String? driver,
  160. String? licensePlate,
  161. double? estimatedMileage,
  162. double? estimatedCost,
  163. String? reason,
  164. String? status,
  165. String? currentApproverId,
  166. List<String>? approvalChain,
  167. DateTime? createTime,
  168. DateTime? updateTime,
  169. double? actualMileage,
  170. double? actualCost,
  171. double? startOdometer,
  172. double? endOdometer,
  173. DateTime? returnTime,
  174. List<String>? passengers,
  175. List<ApprovalRecord>? approvalRecords,
  176. }) {
  177. return VehicleModel(
  178. id: id ?? this.id,
  179. applicationNo: applicationNo ?? this.applicationNo,
  180. applicantId: applicantId ?? this.applicantId,
  181. applicantName: applicantName ?? this.applicantName,
  182. deptId: deptId ?? this.deptId,
  183. deptName: deptName ?? this.deptName,
  184. vehicleType: vehicleType ?? this.vehicleType,
  185. purpose: purpose ?? this.purpose,
  186. startTime: startTime ?? this.startTime,
  187. endTime: endTime ?? this.endTime,
  188. origin: origin ?? this.origin,
  189. destination: destination ?? this.destination,
  190. passengerCount: passengerCount ?? this.passengerCount,
  191. driver: driver ?? this.driver,
  192. licensePlate: licensePlate ?? this.licensePlate,
  193. estimatedMileage: estimatedMileage ?? this.estimatedMileage,
  194. estimatedCost: estimatedCost ?? this.estimatedCost,
  195. reason: reason ?? this.reason,
  196. status: status ?? this.status,
  197. currentApproverId: currentApproverId ?? this.currentApproverId,
  198. approvalChain: approvalChain ?? this.approvalChain,
  199. createTime: createTime ?? this.createTime,
  200. updateTime: updateTime ?? this.updateTime,
  201. actualMileage: actualMileage ?? this.actualMileage,
  202. actualCost: actualCost ?? this.actualCost,
  203. startOdometer: startOdometer ?? this.startOdometer,
  204. endOdometer: endOdometer ?? this.endOdometer,
  205. returnTime: returnTime ?? this.returnTime,
  206. passengers: passengers ?? this.passengers,
  207. approvalRecords: approvalRecords ?? this.approvalRecords,
  208. );
  209. }
  210. }