| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- import 'package:flutter/material.dart';
- import '../../core/theme/app_colors.dart';
- import '../models/user_model.dart';
- class ApprovalActions extends StatefulWidget {
- final String status;
- final UserRole userRole;
- final VoidCallback onApprove;
- final VoidCallback onReject;
- final VoidCallback? onEdit;
- final VoidCallback? onWithdraw;
- final bool isSubmitting;
- const ApprovalActions({
- super.key,
- required this.status,
- required this.userRole,
- required this.onApprove,
- required this.onReject,
- this.onEdit,
- this.onWithdraw,
- this.isSubmitting = false,
- });
- @override
- State<ApprovalActions> createState() => _ApprovalActionsState();
- }
- class _ApprovalActionsState extends State<ApprovalActions> {
- final _opinionCtrl = TextEditingController();
- Future<void> _showOpinionDialog(String action) async {
- final result = await showDialog<bool>(
- context: context,
- builder: (ctx) => AlertDialog(
- title: Text(action == 'approve' ? '确认通过' : '确认拒绝'),
- content: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text('确定要${action == 'approve' ? '通过' : '拒绝'}该申请吗?'),
- const SizedBox(height: 12),
- TextField(
- controller: _opinionCtrl,
- maxLines: 3,
- decoration: InputDecoration(
- hintText: '审批意见(选填)',
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8)),
- ),
- ),
- ],
- ),
- actions: [
- TextButton(
- onPressed: () => Navigator.pop(ctx, false),
- child: const Text('取消'),
- ),
- TextButton(
- onPressed: () => Navigator.pop(ctx, true),
- child: Text('确定',
- style: TextStyle(
- color: action == 'approve'
- ? AppColors.primary
- : AppColors.error)),
- ),
- ],
- ),
- );
- if (result == true) {
- if (action == 'approve') {
- widget.onApprove();
- } else {
- widget.onReject();
- }
- }
- }
- @override
- Widget build(BuildContext context) {
- final isPending = widget.status == 'pending';
- final isDraft = widget.status == 'draft';
- final canApprove = isPending &&
- (widget.userRole == UserRole.approver ||
- widget.userRole == UserRole.finance ||
- widget.userRole == UserRole.admin);
- return Container(
- padding: const EdgeInsets.all(12),
- decoration: BoxDecoration(
- color: Colors.white,
- boxShadow: [
- BoxShadow(
- color: Colors.black.withValues(alpha: 0.05),
- blurRadius: 4, offset: const Offset(0, -1)),
- ],
- ),
- child: canApprove
- ? Row(children: [
- Expanded(
- child: OutlinedButton(
- onPressed: widget.isSubmitting
- ? null
- : () => _showOpinionDialog('reject'),
- style: OutlinedButton.styleFrom(
- foregroundColor: AppColors.error,
- side: const BorderSide(color: AppColors.error),
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(8)),
- minimumSize: const Size(double.infinity, 48),
- ),
- child: const Text('拒绝'),
- ),
- ),
- const SizedBox(width: 12),
- Expanded(
- flex: 2,
- child: ElevatedButton(
- onPressed: widget.isSubmitting
- ? null
- : () => _showOpinionDialog('approve'),
- style: ElevatedButton.styleFrom(
- backgroundColor: AppColors.primary,
- foregroundColor: Colors.white,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(8)),
- minimumSize: const Size(double.infinity, 48),
- ),
- child: widget.isSubmitting
- ? const SizedBox(
- width: 20, height: 20,
- child: CircularProgressIndicator(
- strokeWidth: 2, color: Colors.white))
- : const Text('通过'),
- ),
- ),
- ])
- : Row(children: [
- if (isDraft && widget.onEdit != null) ...[
- Expanded(
- child: OutlinedButton(
- onPressed: widget.onEdit,
- child: const Text('编辑'),
- ),
- ),
- const SizedBox(width: 12),
- ],
- if (isPending && widget.onWithdraw != null)
- Expanded(
- child: OutlinedButton(
- onPressed: widget.onWithdraw,
- style: OutlinedButton.styleFrom(
- foregroundColor: AppColors.warning,
- side: const BorderSide(color: AppColors.warning),
- ),
- child: const Text('撤回'),
- ),
- ),
- ]),
- );
- }
- @override
- void dispose() {
- _opinionCtrl.dispose();
- super.dispose();
- }
- }
|