list orders
This commit is contained in:
@@ -3,20 +3,18 @@
|
||||
/// Displays order information in a card format.
|
||||
library;
|
||||
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:worker/core/database/models/enums.dart';
|
||||
import 'package:worker/core/enums/status_color.dart';
|
||||
import 'package:worker/core/theme/colors.dart';
|
||||
import 'package:worker/features/orders/data/models/order_model.dart';
|
||||
import 'package:worker/features/orders/domain/entities/order.dart';
|
||||
|
||||
/// Order Card Widget
|
||||
///
|
||||
/// Displays order details in a card with status indicator.
|
||||
class OrderCard extends StatelessWidget {
|
||||
/// Order to display
|
||||
final OrderModel order;
|
||||
final Order order;
|
||||
|
||||
/// Tap callback
|
||||
final VoidCallback? onTap;
|
||||
@@ -50,7 +48,7 @@ class OrderCard extends StatelessWidget {
|
||||
children: [
|
||||
// Order number
|
||||
Text(
|
||||
'#${order.orderNumber}',
|
||||
'#${order.name}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -60,7 +58,7 @@ class OrderCard extends StatelessWidget {
|
||||
|
||||
// Amount
|
||||
Text(
|
||||
currencyFormatter.format(order.finalAmount),
|
||||
currencyFormatter.format(order.grandTotal),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w700,
|
||||
@@ -73,18 +71,13 @@ class OrderCard extends StatelessWidget {
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Order details
|
||||
_buildDetailRow('Ngày đặt:', _formatDate(order.createdAt)),
|
||||
_buildDetailRow('Ngày đặt:', _formatDate(order.transactionDate)),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
_buildDetailRow(
|
||||
'Ngày giao:',
|
||||
order.expectedDeliveryDate != null
|
||||
? _formatDate(order.expectedDeliveryDate!)
|
||||
: 'Chưa xác định',
|
||||
),
|
||||
_buildDetailRow('Ngày giao:', _formatDate(order.deliveryDate)),
|
||||
const SizedBox(height: 6),
|
||||
|
||||
_buildDetailRow('Địa chỉ:', _getShortAddress()),
|
||||
_buildDetailRow('Địa chỉ:', order.address),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Status badge
|
||||
@@ -118,100 +111,50 @@ class OrderCard extends StatelessWidget {
|
||||
|
||||
/// Build status badge
|
||||
Widget _buildStatusBadge() {
|
||||
final statusColor = _getStatusColor();
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: _getStatusColor(order.status).withValues(alpha: 0.1),
|
||||
color: statusColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: _getStatusColor(order.status).withValues(alpha: 0.3),
|
||||
color: statusColor.withValues(alpha: 0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
_getStatusText(order.status),
|
||||
order.status,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: _getStatusColor(order.status),
|
||||
color: statusColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Get status color
|
||||
Color _getStatusColor(OrderStatus status) {
|
||||
switch (status) {
|
||||
case OrderStatus.draft:
|
||||
return AppColors.grey500;
|
||||
case OrderStatus.pending:
|
||||
return const Color(0xFFF59E0B); // warning/pending color
|
||||
case OrderStatus.confirmed:
|
||||
return const Color(0xFFF59E0B); // warning/pending color
|
||||
case OrderStatus.processing:
|
||||
return AppColors.info;
|
||||
case OrderStatus.shipped:
|
||||
return const Color(0xFF3B82F6); // blue
|
||||
case OrderStatus.delivered:
|
||||
return const Color(0xFF10B981); // green
|
||||
case OrderStatus.completed:
|
||||
return AppColors.success;
|
||||
case OrderStatus.cancelled:
|
||||
return AppColors.danger;
|
||||
case OrderStatus.refunded:
|
||||
return const Color(0xFFF97316); // orange
|
||||
}
|
||||
}
|
||||
|
||||
/// Get status text in Vietnamese
|
||||
String _getStatusText(OrderStatus status) {
|
||||
switch (status) {
|
||||
case OrderStatus.draft:
|
||||
return 'Nháp';
|
||||
case OrderStatus.pending:
|
||||
return 'Chờ xác nhận';
|
||||
case OrderStatus.confirmed:
|
||||
return 'Đã xác nhận';
|
||||
case OrderStatus.processing:
|
||||
return 'Đang xử lý';
|
||||
case OrderStatus.shipped:
|
||||
return 'Đang giao';
|
||||
case OrderStatus.delivered:
|
||||
return 'Đã giao';
|
||||
case OrderStatus.completed:
|
||||
return 'Hoàn thành';
|
||||
case OrderStatus.cancelled:
|
||||
return 'Đã hủy';
|
||||
case OrderStatus.refunded:
|
||||
return 'Đã hoàn tiền';
|
||||
}
|
||||
/// Get status color from API status_color field
|
||||
Color _getStatusColor() {
|
||||
// Parse statusColor from API (Warning, Success, Danger, Info, Secondary)
|
||||
final statusColorEnum = StatusColor.values.firstWhere(
|
||||
(e) => e.name.toLowerCase() == order.statusColor.toLowerCase(),
|
||||
orElse: () => StatusColor.secondary,
|
||||
);
|
||||
return statusColorEnum.color;
|
||||
}
|
||||
|
||||
/// Format date to dd/MM/yyyy
|
||||
String _formatDate(DateTime date) {
|
||||
return DateFormat('dd/MM/yyyy').format(date);
|
||||
}
|
||||
|
||||
/// Get short address (city or district, city)
|
||||
String _getShortAddress() {
|
||||
if (order.shippingAddress == null) {
|
||||
return 'Chưa có địa chỉ';
|
||||
String _formatDate(String? dateString) {
|
||||
if (dateString == null || dateString.isEmpty) {
|
||||
return 'Chưa xác định';
|
||||
}
|
||||
|
||||
try {
|
||||
final addressJson = jsonDecode(order.shippingAddress!);
|
||||
final city = addressJson['city'] as String?;
|
||||
final district = addressJson['district'] as String?;
|
||||
|
||||
if (district != null && city != null) {
|
||||
return '$district, $city';
|
||||
} else if (city != null) {
|
||||
return city;
|
||||
} else {
|
||||
return 'Chưa có địa chỉ';
|
||||
}
|
||||
final date = DateTime.parse(dateString);
|
||||
return DateFormat('dd/MM/yyyy').format(date);
|
||||
} catch (e) {
|
||||
return 'Chưa có địa chỉ';
|
||||
return dateString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user