智慧水务管理系统 - 精河县供水工程综合管理平台

bill_model.dart 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /// 账单模型
  2. class BillModel {
  3. final String id;
  4. final String billNo;
  5. final String userName;
  6. final String userAddress;
  7. final String meterNo;
  8. final double previousReading;
  9. final double currentReading;
  10. final double usage;
  11. final double amount;
  12. final String status; // unpaid, paid, overdue
  13. final String period;
  14. final DateTime dueDate;
  15. BillModel({
  16. required this.id,
  17. required this.billNo,
  18. required this.userName,
  19. required this.userAddress,
  20. required this.meterNo,
  21. required this.previousReading,
  22. required this.currentReading,
  23. required this.usage,
  24. required this.amount,
  25. required this.status,
  26. required this.period,
  27. required this.dueDate,
  28. });
  29. factory BillModel.fromJson(Map<String, dynamic> json) {
  30. return BillModel(
  31. id: json['id']?.toString() ?? '',
  32. billNo: json['billNo'] ?? '',
  33. userName: json['userName'] ?? '',
  34. userAddress: json['userAddress'] ?? '',
  35. meterNo: json['meterNo'] ?? '',
  36. previousReading: (json['previousReading'] ?? 0).toDouble(),
  37. currentReading: (json['currentReading'] ?? 0).toDouble(),
  38. usage: (json['usage'] ?? 0).toDouble(),
  39. amount: (json['amount'] ?? 0).toDouble(),
  40. status: json['status'] ?? 'unpaid',
  41. period: json['period'] ?? '',
  42. dueDate: DateTime.tryParse(json['dueDate'] ?? '') ?? DateTime.now(),
  43. );
  44. }
  45. Map<String, dynamic> toJson() {
  46. return {
  47. 'id': id,
  48. 'billNo': billNo,
  49. 'userName': userName,
  50. 'userAddress': userAddress,
  51. 'meterNo': meterNo,
  52. 'previousReading': previousReading,
  53. 'currentReading': currentReading,
  54. 'usage': usage,
  55. 'amount': amount,
  56. 'status': status,
  57. 'period': period,
  58. 'dueDate': dueDate.toIso8601String(),
  59. };
  60. }
  61. }