vehicle_model.dart 6.4 KB

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