319 lines
11 KiB
Dart
319 lines
11 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/withdrawal_controller.dart';
|
|
|
|
/// شاشة طلبات سحب أرصدة السائقين.
|
|
/// تتبع لغة تصميم شاشة الرحلات: أسطح محايدة، واللون للمعنى وحده.
|
|
class WithdrawalRequestsPage extends StatelessWidget {
|
|
const WithdrawalRequestsPage({super.key});
|
|
|
|
static const _filters = <String, String>{
|
|
'pending': 'معلّقة',
|
|
'approved': 'معتمدة',
|
|
'paid': 'مدفوعة',
|
|
'rejected': 'مرفوضة',
|
|
'all': 'الكل',
|
|
};
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cs = Theme.of(context).colorScheme;
|
|
|
|
return Scaffold(
|
|
backgroundColor: cs.surface,
|
|
body: GetBuilder<WithdrawalController>(
|
|
init: Get.isRegistered<WithdrawalController>()
|
|
? Get.find<WithdrawalController>()
|
|
: WithdrawalController(),
|
|
builder: (ctrl) {
|
|
return Column(
|
|
children: [
|
|
_buildHeader(context, ctrl, cs),
|
|
_buildTotals(ctrl, cs),
|
|
_buildFilterBar(ctrl, cs),
|
|
Expanded(
|
|
child: ctrl.isLoading
|
|
? Center(child: CircularProgressIndicator(color: cs.primary))
|
|
: _buildList(ctrl, cs),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(
|
|
BuildContext context, WithdrawalController 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(),
|
|
IconButton(
|
|
icon: Icon(Icons.refresh_rounded, color: cs.onSurfaceVariant),
|
|
onPressed: () => ctrl.fetchRequests(),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildTotals(WithdrawalController ctrl, ColorScheme cs) {
|
|
if (ctrl.totals.isEmpty) return const SizedBox.shrink();
|
|
|
|
Widget tile(String label, String key, Color color) {
|
|
final t = ctrl.totals[key] as Map? ?? {};
|
|
return Expanded(
|
|
child: Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 4),
|
|
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
|
decoration: BoxDecoration(
|
|
color: cs.surfaceContainerHighest,
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(color: color.withValues(alpha: 0.22)),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
Text('${t['count'] ?? 0}',
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.w800)),
|
|
const SizedBox(height: 2),
|
|
Text(label,
|
|
style:
|
|
TextStyle(color: cs.onSurfaceVariant, fontSize: 11)),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.fromLTRB(12, 12, 12, 4),
|
|
child: Row(
|
|
children: [
|
|
tile('معلّقة', 'pending', cs.warning),
|
|
tile('معتمدة', 'approved', cs.info),
|
|
tile('مدفوعة', 'paid', cs.success),
|
|
tile('مرفوضة', 'rejected', cs.danger),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildFilterBar(WithdrawalController ctrl, ColorScheme cs) {
|
|
return SizedBox(
|
|
height: 52,
|
|
child: ListView(
|
|
scrollDirection: Axis.horizontal,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
children: _filters.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(WithdrawalController ctrl, ColorScheme cs) {
|
|
if (ctrl.requests.isEmpty) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Icon(Icons.inbox_rounded, 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.requests.length,
|
|
itemBuilder: (_, i) => _buildCard(ctrl, ctrl.requests[i], cs),
|
|
);
|
|
}
|
|
|
|
Widget _buildCard(WithdrawalController ctrl, dynamic r, ColorScheme cs) {
|
|
final status = '${r['status'] ?? 'pending'}';
|
|
final color = switch (status) {
|
|
'approved' => cs.info,
|
|
'paid' => cs.success,
|
|
'rejected' => cs.danger,
|
|
_ => cs.warning,
|
|
};
|
|
final id = int.tryParse('${r['id']}') ?? 0;
|
|
final busy = ctrl.busyId == id;
|
|
|
|
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: [
|
|
Expanded(
|
|
child: Text('${r['driver_name'] ?? 'سائق غير معروف'}',
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w700)),
|
|
),
|
|
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(_filters[status] ?? status,
|
|
style: TextStyle(
|
|
color: color,
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w700)),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(
|
|
children: [
|
|
Icon(Icons.payments_rounded, size: 14, color: color),
|
|
const SizedBox(width: 6),
|
|
Text('${r['amount'] ?? 0}',
|
|
style: TextStyle(
|
|
color: cs.onSurface,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w800)),
|
|
const SizedBox(width: 12),
|
|
Icon(Icons.account_balance_wallet_outlined,
|
|
size: 14, color: cs.onSurfaceVariant),
|
|
const SizedBox(width: 6),
|
|
Expanded(
|
|
child: Text(
|
|
'${r['wallet_type'] ?? ''} — ${r['wallet_number'] ?? ''}',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style:
|
|
TextStyle(color: cs.onSurfaceVariant, fontSize: 12),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text('#$id · ${r['created_at'] ?? ''}',
|
|
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 11)),
|
|
|
|
// الإجراءات تظهر بحسب ما يقبله الخادم: من pending إلى أي حالة،
|
|
// ومن approved إلى paid فقط. أي انتقال آخر يرفضه الخادم بـ 409.
|
|
if (status == 'pending' || status == 'approved') ...[
|
|
const SizedBox(height: 12),
|
|
Row(
|
|
children: [
|
|
if (status == 'pending') ...[
|
|
_action(ctrl, id, 'approved', 'اعتماد', cs.info, cs, busy),
|
|
const SizedBox(width: 8),
|
|
_action(ctrl, id, 'rejected', 'رفض', cs.danger, cs, busy),
|
|
const SizedBox(width: 8),
|
|
],
|
|
_action(ctrl, id, 'paid', 'تم الدفع', cs.success, cs, busy),
|
|
],
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _action(WithdrawalController ctrl, int id, String status, String label,
|
|
Color color, ColorScheme cs, bool busy) {
|
|
return Expanded(
|
|
child: GestureDetector(
|
|
onTap: busy ? null : () => ctrl.updateStatus(id, status),
|
|
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)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|