Files
zhinian_manage/lib/models/order.dart
2026-05-15 14:41:37 +08:00

156 lines
4.6 KiB
Dart

import 'package:flutter/material.dart';
enum OrderStatus {
all,
pendingPayment,
pendingVerification,
verified,
pendingRefund,
refunded,
}
class OrderItem {
final String id;
final String orderNo;
final String customerName;
final String customerPhone;
final String productName;
final double amount;
final OrderStatus status;
final DateTime createdAt;
final DateTime? paidAt;
final DateTime? verifiedAt;
final DateTime? refundedAt;
final String? verifyCode;
final int quantity;
final String? remark;
final String? scenicSpot;
const OrderItem({
required this.id,
required this.orderNo,
required this.customerName,
required this.customerPhone,
required this.productName,
required this.amount,
required this.status,
required this.createdAt,
this.paidAt,
this.verifiedAt,
this.refundedAt,
this.verifyCode,
required this.quantity,
this.remark,
this.scenicSpot,
});
String get statusText {
switch (status) {
case OrderStatus.pendingPayment:
return '待支付';
case OrderStatus.pendingVerification:
return '待核销';
case OrderStatus.verified:
return '已核销';
case OrderStatus.pendingRefund:
return '待退款';
case OrderStatus.refunded:
return '已退款';
default:
return '全部';
}
}
Color get statusColor {
switch (status) {
case OrderStatus.pendingPayment:
return const Color(0xFFF59E0B);
case OrderStatus.pendingVerification:
return const Color(0xFF3B82F6);
case OrderStatus.verified:
return const Color(0xFF10B981);
case OrderStatus.pendingRefund:
return const Color(0xFFEF4444);
case OrderStatus.refunded:
return const Color(0xFF64748B);
default:
return const Color(0xFF64748B);
}
}
bool get canVerify => status == OrderStatus.pendingVerification;
bool get canRefund => status == OrderStatus.pendingVerification || status == OrderStatus.verified;
OrderItem copyWith({
String? id,
String? orderNo,
String? customerName,
String? customerPhone,
String? productName,
double? amount,
OrderStatus? status,
DateTime? createdAt,
DateTime? paidAt,
DateTime? verifiedAt,
DateTime? refundedAt,
String? verifyCode,
int? quantity,
String? remark,
String? scenicSpot,
}) {
return OrderItem(
id: id ?? this.id,
orderNo: orderNo ?? this.orderNo,
customerName: customerName ?? this.customerName,
customerPhone: customerPhone ?? this.customerPhone,
productName: productName ?? this.productName,
amount: amount ?? this.amount,
status: status ?? this.status,
createdAt: createdAt ?? this.createdAt,
paidAt: paidAt ?? this.paidAt,
verifiedAt: verifiedAt ?? this.verifiedAt,
refundedAt: refundedAt ?? this.refundedAt,
verifyCode: verifyCode ?? this.verifyCode,
quantity: quantity ?? this.quantity,
remark: remark ?? this.remark,
scenicSpot: scenicSpot ?? this.scenicSpot,
);
}
Map<String, dynamic> toJson() => {
'id': id,
'orderNo': orderNo,
'customerName': customerName,
'customerPhone': customerPhone,
'productName': productName,
'amount': amount,
'status': status.name,
'createdAt': createdAt.toIso8601String(),
'paidAt': paidAt?.toIso8601String(),
'verifiedAt': verifiedAt?.toIso8601String(),
'refundedAt': refundedAt?.toIso8601String(),
'verifyCode': verifyCode,
'quantity': quantity,
'remark': remark,
'scenicSpot': scenicSpot,
};
factory OrderItem.fromJson(Map<String, dynamic> json) => OrderItem(
id: json['id'] ?? '',
orderNo: json['orderNo'] ?? '',
customerName: json['customerName'] ?? '',
customerPhone: json['customerPhone'] ?? '',
productName: json['productName'] ?? '',
amount: (json['amount'] ?? 0.0).toDouble(),
status: OrderStatus.values.byName(json['status'] ?? 'pendingPayment'),
createdAt: DateTime.tryParse(json['createdAt'] ?? '') ?? DateTime.now(),
paidAt: json['paidAt'] != null ? DateTime.tryParse(json['paidAt']) : null,
verifiedAt: json['verifiedAt'] != null ? DateTime.tryParse(json['verifiedAt']) : null,
refundedAt: json['refundedAt'] != null ? DateTime.tryParse(json['refundedAt']) : null,
verifyCode: json['verifyCode'],
quantity: json['quantity'] ?? 1,
remark: json['remark'],
scenicSpot: json['scenicSpot'],
);
}