| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /// 账单模型
- class BillModel {
- final String id;
- final String billNo;
- final String userName;
- final String userAddress;
- final String meterNo;
- final double previousReading;
- final double currentReading;
- final double usage;
- final double amount;
- final String status; // unpaid, paid, overdue
- final String period;
- final DateTime dueDate;
-
- BillModel({
- required this.id,
- required this.billNo,
- required this.userName,
- required this.userAddress,
- required this.meterNo,
- required this.previousReading,
- required this.currentReading,
- required this.usage,
- required this.amount,
- required this.status,
- required this.period,
- required this.dueDate,
- });
-
- factory BillModel.fromJson(Map<String, dynamic> json) {
- return BillModel(
- id: json['id']?.toString() ?? '',
- billNo: json['billNo'] ?? '',
- userName: json['userName'] ?? '',
- userAddress: json['userAddress'] ?? '',
- meterNo: json['meterNo'] ?? '',
- previousReading: (json['previousReading'] ?? 0).toDouble(),
- currentReading: (json['currentReading'] ?? 0).toDouble(),
- usage: (json['usage'] ?? 0).toDouble(),
- amount: (json['amount'] ?? 0).toDouble(),
- status: json['status'] ?? 'unpaid',
- period: json['period'] ?? '',
- dueDate: DateTime.tryParse(json['dueDate'] ?? '') ?? DateTime.now(),
- );
- }
-
- Map<String, dynamic> toJson() {
- return {
- 'id': id,
- 'billNo': billNo,
- 'userName': userName,
- 'userAddress': userAddress,
- 'meterNo': meterNo,
- 'previousReading': previousReading,
- 'currentReading': currentReading,
- 'usage': usage,
- 'amount': amount,
- 'status': status,
- 'period': period,
- 'dueDate': dueDate.toIso8601String(),
- };
- }
- }
|