272 lines
9.7 KiB
Dart
272 lines
9.7 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:siro_admin/constant/theme.dart';
|
|
import 'package:siro_admin/controller/admin/food_merchants_controller.dart';
|
|
|
|
/// إدارة المطاعم — قائمة، تصفية بالحالة، واعتماد/رفض الطلبات المعلّقة.
|
|
/// تتبع لغة تصميم شاشة الرحلات: أسطح محايدة واللون للمعنى وحده.
|
|
class FoodMerchantsPage extends StatelessWidget {
|
|
const FoodMerchantsPage({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
body: GetBuilder<FoodMerchantsController>(
|
|
init: Get.isRegistered<FoodMerchantsController>()
|
|
? Get.find<FoodMerchantsController>()
|
|
: FoodMerchantsController(),
|
|
builder: (ctrl) => Column(
|
|
children: [
|
|
_buildHeader(ctrl, cs),
|
|
_buildFilterBar(ctrl, cs),
|
|
Expanded(
|
|
child: ctrl.isLoading
|
|
? Center(child: CircularProgressIndicator(color: cs.primary))
|
|
: _buildList(ctrl, cs),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(FoodMerchantsController ctrl, ColorScheme cs) {
|
|
return Container(
|
|
padding: const EdgeInsets.fromLTRB(16, 50, 16, 16),
|
|
decoration: BoxDecoration(
|
|
color: cs.surface,
|
|
border: Border(bottom: BorderSide(color: cs.outline)),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
GestureDetector(
|
|
onTap: () => Get.back(),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(color: cs.outline),
|
|
),
|
|
child: Icon(Icons.arrow_back_ios_new_rounded,
|
|
color: cs.onSurfaceVariant, size: 16),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Text('إدارة المطاعم',
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w700)),
|
|
const Spacer(),
|
|
Text('${ctrl.merchants.length}',
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 12)),
|
|
IconButton(
|
|
icon: Icon(Icons.refresh_rounded, color: cs.onSurfaceVariant),
|
|
onPressed: () => ctrl.fetchMerchants(),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFilterBar(FoodMerchantsController ctrl, ColorScheme cs) {
|
|
return SizedBox(
|
|
height: 52,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
children: FoodMerchantsController.statuses.entries.map((e) {
|
|
final selected = ctrl.filter == e.key;
|
|
return Padding(
|
|
padding: const EdgeInsets.only(left: 8),
|
|
child: GestureDetector(
|
|
onTap: () => ctrl.changeFilter(e.key),
|
|
child: Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: selected
|
|
? cs.primary.withValues(alpha: 0.12)
|
|
: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(10),
|
|
border:
|
|
Border.all(color: selected ? cs.primary : cs.outline),
|
|
),
|
|
child: Text(e.value,
|
|
style: TextStyle(
|
|
color: selected ? cs.primary : cs.onSurfaceVariant,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
)),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildList(FoodMerchantsController ctrl, ColorScheme cs) {
|
|
if (ctrl.merchants.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.storefront_outlined,
|
|
color: cs.onSurfaceVariant, size: 40),
|
|
const SizedBox(height: 10),
|
|
Text('لا توجد مطاعم في هذه الحالة',
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 13)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.fromLTRB(12, 4, 12, 24),
|
|
itemCount: ctrl.merchants.length,
|
|
itemBuilder: (_, i) => _buildCard(ctrl, ctrl.merchants[i], cs),
|
|
);
|
|
}
|
|
|
|
Widget _buildCard(FoodMerchantsController ctrl, dynamic m, ColorScheme cs) {
|
|
final status = '${m['status'] ?? ''}';
|
|
final color = switch (status) {
|
|
'active' => cs.success,
|
|
'pending_approval' => cs.warning,
|
|
'rejected' || 'suspended' => cs.danger,
|
|
_ => cs.onSurfaceVariant,
|
|
};
|
|
final id = int.tryParse('${m['id']}') ?? 0;
|
|
final busy = ctrl.busyId == id;
|
|
final ratingCount = int.tryParse('${m['rating_count'] ?? 0}') ?? 0;
|
|
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 10),
|
|
padding: const EdgeInsets.all(14),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: cs.outline),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Icon(Icons.storefront_rounded, color: color, size: 18),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text('${m['name_ar'] ?? m['name_en'] ?? 'بلا اسم'}',
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w700)),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
'${m['city'] ?? ''}${m['category'] != null ? ' · ${m['category']}' : ''}',
|
|
style: TextStyle(
|
|
color: cs.onSurfaceVariant, fontSize: 11),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
padding:
|
|
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: color.withValues(alpha: 0.3)),
|
|
),
|
|
child: Text(
|
|
FoodMerchantsController.statuses[status] ?? status,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w700)),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 10),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.percent_rounded,
|
|
size: 13, color: cs.onSurfaceVariant),
|
|
const SizedBox(width: 4),
|
|
Text('عمولة ${m['commission_percent'] ?? 0}%',
|
|
style:
|
|
TextStyle(color: cs.onSurfaceVariant, fontSize: 11)),
|
|
const SizedBox(width: 14),
|
|
Icon(Icons.star_rounded, size: 13, color: cs.warning),
|
|
const SizedBox(width: 4),
|
|
// بلا تقييمات نعرض شرطة بدل 0.0 حتى لا يُقرأ كتقييم سيئ
|
|
Text(
|
|
ratingCount == 0
|
|
? 'لا تقييمات'
|
|
: '${m['rating_avg'] ?? 0} ($ratingCount)',
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 11),
|
|
),
|
|
],
|
|
),
|
|
if (status == 'pending_approval') ...[
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
_action(ctrl, id, 'approve', 'اعتماد', cs.success, busy),
|
|
const SizedBox(width: 8),
|
|
_action(ctrl, id, 'reject', 'رفض', cs.danger, busy),
|
|
],
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _action(FoodMerchantsController ctrl, int id, String action,
|
|
String label, Color color, bool busy) {
|
|
return Expanded(
|
|
child: GestureDetector(
|
|
onTap: busy ? null : () => ctrl.decide(id, action),
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(vertical: 9),
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: color.withValues(alpha: busy ? 0.05 : 0.12),
|
|
borderRadius: BorderRadius.circular(10),
|
|
border: Border.all(
|
|
color: color.withValues(alpha: busy ? 0.15 : 0.35)),
|
|
),
|
|
child: busy
|
|
? SizedBox(
|
|
width: 14,
|
|
height: 14,
|
|
child:
|
|
CircularProgressIndicator(strokeWidth: 2, color: color),
|
|
)
|
|
: Text(label,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|